[论文解读] M2TS: Multi-Scale Multi-Modal Approach Based on Transformer for Source Code Summarization
M2TS 提出了一种基于多尺度、多模态 Transformer 的模型,用于源代码摘要生成。该模型通过多尺度图卷积网络从抽象语法树(AST)中提取结构特征,并利用跨模态注意力机制将这些特征与代码标记特征融合。该方法在 Java 和 Python 数据集上实现了最先进(SOTA)的性能,在自动评估指标上优于现有方法。
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.
研究动机与目标
- 为了解决现有方法的局限性:即通过将 AST 扁平化为序列而破坏其结构,或通过使用 AST 路径而丢失全局上下文。
- 通过多尺度图卷积网络全面捕捉 AST 的局部和全局结构特征。
- 通过新颖的跨模态融合机制,将来自 AST 和代码标记的语法与语义信息融合,以增强代码表示。
- 通过在特征融合和解码过程中突出两种模态的关键特征,提升摘要质量。
- 在标准 Java 和 Python 源代码摘要基准数据集上,证明所提出的 M2TS 模型的有效性。
提出的方法
- M2TS 通过计算 AST 邻接矩阵的幂矩阵(例如,A^1, A^2, ..., A^k)来实现多尺度 AST 特征提取,以捕捉局部和全局结构模式。
- 在每个尺度上应用图卷积网络(GCN)从 AST 中提取分层结构表示,并通过残差连接防止特征退化。
- 使用 BERT 预训练对代码标记进行嵌入,并将其作为与 AST 特征并行的第二模态。
- 通过可学习的注意力机制实现跨模态融合机制,强调来自两种模态的重要特征。
- 将融合后的特征与标记嵌入输入到 Transformer 解码器中,以生成自然语言摘要。
- 采用序列到序列学习方法进行端到端训练,并使用调度解码以减轻暴露偏差。
实验结果
研究问题
- RQ1与单尺度或基于路径的方法相比,多尺度 AST 表征学习是否能更有效地捕捉源代码中的结构特征?
- RQ2与单模态或简单拼接方法相比,AST 与代码标记特征的跨模态融合是否能带来更好的摘要性能?
- RQ3所提出的 M2TS 模型是否能在标准 Java 和 Python 源代码摘要基准上实现最先进性能?
- RQ4模型在不同评估指标上的表现如何变化?其性能是否在不同编程语言间具有泛化能力?
- RQ5多尺度 GCN 设计在多大程度上增强了模型对复杂代码结构的建模能力?
主要发现
- M2TS 在两个 Java 和一个 Python 源代码摘要数据集上,于 BLEU、ROUGE 和 BLEU-4 等多个自动评估指标上均优于现有最先进模型。
- 多尺度 AST 特征提取方法显著提升了结构特征学习效果,表现为相较于使用单尺度或基于路径的 AST 表征模型,ROUGE-L 和 BLEU 分数更高。
- 跨模态融合机制通过有效突出 AST 和代码标记中的关键语法与语义特征,显著提升了性能,生成了更准确且上下文相关的摘要。
- 该模型在 Java 数据集上达到 ROUGE-L 得分为 48.7,在 Python 数据集上达到 45.2,超越了先前的 SOTA 方法。
- 消融研究证实,多尺度 AST 提取与跨模态融合均对性能提升有显著贡献,消融模型在 ROUGE-L 上平均下降超过 5 分。
- 该模型在不同编程语言间表现出强大的泛化能力,在 Java 和 Python 数据集上均实现了稳定的性能提升。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。