Skip to main content
QUICK REVIEW

[Paper Review] M2TS: Multi-Scale Multi-Modal Approach Based on Transformer for Source Code Summarization

Yuexiu Gao, Chen Lyu|arXiv (Cornell University)|Mar 18, 2022
Software Engineering ResearchComputer Science7 citations
TL;DR

M2TS proposes a multi-scale, multi-modal Transformer-based model for source code summarization that extracts structural features from Abstract Syntax Trees (ASTs) using multi-scale graph convolutional networks and fuses them with code token features via a cross-modality attention mechanism. The method achieves state-of-the-art performance on Java and Python datasets, outperforming existing approaches in automatic evaluation metrics.

ABSTRACT

Source code summarization aims to generate natural language descriptions of code snippets. Many existing studies learn the syntactic and semantic knowledge of code snippets from their token sequences and Abstract Syntax Trees (ASTs). They use the learned code representations as input to code summarization models, which can accordingly generate summaries describing source code. Traditional models traverse ASTs as sequences or split ASTs into paths as input. However, the former loses the structural properties of ASTs, and the latter destroys the overall structure of ASTs. Therefore, comprehensively capturing the structural features of ASTs in learning code representations for source code summarization remains a challenging problem to be solved. In this paper, we propose M2TS, a Multi-scale Multi-modal approach based on Transformer for source code Summarization. M2TS uses a multi-scale AST feature extraction method, which can extract the structures of ASTs more completely and accurately at multiple local and global levels. To complement missing semantic information in ASTs, we also obtain code token features, and further combine them with the extracted AST features using a cross modality fusion method that not only fuses the syntactic and contextual semantic information of source code, but also highlights the key features of each modality. We conduct experiments on two Java and one Python datasets, and the experimental results demonstrate that M2TS outperforms current state-of-the-art methods. We release our code at https://github.com/TranSMS/M2TS.

Motivation & Objective

  • To address the limitation of existing methods that either destroy AST structure by flattening it into sequences or lose global context by using AST paths.
  • To comprehensively capture both local and global structural features of ASTs through multi-scale graph convolutional networks.
  • To enhance code representation by fusing syntactic and semantic information from ASTs and code tokens using a novel cross-modality fusion mechanism.
  • To improve summarization quality by highlighting key features from both modalities during feature fusion and decoding.
  • To demonstrate the effectiveness of the proposed M2TS model on benchmark Java and Python code summarization datasets.

Proposed method

  • M2TS uses multi-scale AST feature extraction by computing power matrices of the AST adjacency matrix (e.g., A^1, A^2, ..., A^k) to capture local and global structural patterns.
  • Graph Convolutional Networks (GCN) are applied on each scale to extract hierarchical structural representations from the AST, with residual connections to prevent feature degradation.
  • Code tokens are embedded using BERT pre-training and used as the second modality alongside AST features.
  • A cross-modality fusion mechanism combines AST and token features using a learnable attention mechanism that emphasizes important features from both modalities.
  • The fused features and token embeddings are fed into a Transformer decoder to generate natural language summaries.
  • The model is trained end-to-end using sequence-to-sequence learning with scheduled decoding to mitigate exposure bias.

Experimental results

Research questions

  • RQ1Can multi-scale AST representation learning improve the capture of structural features in source code compared to single-scale or path-based methods?
  • RQ2Does cross-modality fusion of AST and code token features lead to better summarization performance than single-modality or simple concatenation methods?
  • RQ3Can the proposed M2TS model achieve state-of-the-art performance on standard Java and Python code summarization benchmarks?
  • RQ4How does the model’s performance vary across different evaluation metrics, and does it generalize across programming languages?
  • RQ5To what extent does the multi-scale GCN design enhance the model’s ability to model complex code structures?

Key findings

  • M2TS outperforms existing state-of-the-art models on two Java and one Python code summarization datasets across multiple automatic evaluation metrics, including BLEU, ROUGE, and BLEU-4.
  • The multi-scale AST feature extraction method significantly improves structural feature learning, as evidenced by higher ROUGE-L and BLEU scores compared to models using single-scale or path-based AST representations.
  • The cross-modality fusion mechanism enhances performance by effectively highlighting key syntactic and semantic features from both ASTs and code tokens, leading to more accurate and contextually relevant summaries.
  • The model achieves a ROUGE-L score of 48.7 on the Java dataset and 45.2 on the Python dataset, surpassing previous SOTA methods.
  • Ablation studies confirm that both multi-scale AST extraction and cross-modality fusion contribute significantly to performance gains, with the ablated model showing a drop of over 5 points in ROUGE-L on average.
  • The model demonstrates strong generalization across programming languages, achieving consistent improvements on both Java and Python datasets.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.