arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2203.09707cs.SEcs.AI
收藏

M2TS:基于Transformer的多尺度多模态Source Code综合方法

M2TS: Multi-Scale Multi-Modal Approach Based on Transformer for Source Code Summarization

Shandong Normal University(山东师范大学)

Yuexiu Gao, Chen Lyu

摘要:

源代码摘要旨在生成代码片段的自然语言描述。现有的研究多从代码片段的标记序列和抽象树中学习代码片段的语法和语义知识。它们使用学习的代码表示作为代码摘要模型的输入,代码摘要模型可以相应地生成描述源代码的摘要。传统模型将AST作为序列遍历,或者将AST分割为路径作为输入。然而,前者失去了AST的结构特性,后者破坏了AST的整体结构。因此,在学习源代码摘要的代码表示中,全面捕获AST的结构特征仍然是一个有待解决的具有挑战性的问题。本文提出了一种基于Transformer的多尺度多模态源代码摘要方法M2TS。M2TS采用多尺度AST特征提取方法,可以在多个局部和全局级别上更完整、更准确地提取AST的结构。为了补充AST中缺失的语义信息,我们还获得了代码标记特征,并使用跨模态融合方法将它们与提取的AST特征进一步结合,该方法不仅融合了源代码的句法和上下文语义信息,而且突出了每个模态的关键特征。我们在两个Java和一个Python数据集上进行了实验,实验结果表明,M2TS优于当前最先进的方法。我们在www.example.com上发布代码。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑