CoCoSum:基于多关系图神经网络的上下文代码摘要
CoCoSum: Contextual Code Summarization with Multi-Relational Graph Neural Network
摘要:
源代码摘要是对代码片段的简短自然语言描述,可帮助开发人员更好地理解和维护源代码。为了减轻手动编写摘要的负担,自动代码摘要方面的工作激增。然而,大多数当代方法主要利用所概括的方法的边界内的信息(即,本地上下文),并忽略可能有助于代码摘要的更广泛的上下文。本文研究了两种全局上下文,即类内上下文和类间上下文,并提出了CoCoSUM:基于多关系图神经网络的上下文代码摘要模型。CoCoSUM首先将类名作为类内上下文来生成类语义嵌入。然后,相关的统一建模语言(UML)类图提取类间上下文,并编码到类关系嵌入使用一种新的多关系图神经网络(MRGNN)。类语义嵌入和类关系嵌入,以及来自代码令牌编码器和AST编码器的输出,被传递到配备有两级注意力机制的解码器,以生成高质量的、上下文感知的代码摘要。我们进行了大量的实验来评估我们的方法,并将其与其他自动代码摘要模型进行比较。实验结果表明,CoCoSUM是有效的,优于国家的最先进的方法。我们的源代码和实验数据在补充材料中提供,并将公开提供。
英文摘要:
Source code summaries are short natural language descriptions of code snippets that help developers better understand and maintain source code. There has been a surge of work on automatic code summarization to reduce the burden of writing summaries manually. However, most contemporary approaches mainly leverage the information within the boundary of the method being summarized (i.e., local context), and ignore the broader context that could assist with code summarization. This paper explores two global contexts, namely intra-class and inter-class contexts, and proposes the model CoCoSUM: Contextual Code Summarization with Multi-Relational Graph Neural Networks. CoCoSUM first incorporates class names as the intra-class context to generate the class semantic embeddings. Then, relevant Unified Modeling Language (UML) class diagrams are extracted as inter-class context and are encoded into the class relational embeddings using a novel Multi-Relational Graph Neural Network (MRGNN). Class semantic embeddings and class relational embeddings, together with the outputs from code token encoder and AST encoder, are passed to a decoder armed with a two-level attention mechanism to generate high-quality, context-aware code summaries. We conduct extensive experiments to evaluate our approach and compare it with other automatic code summarization models. The experimental results show that CoCoSUM is effective and outperforms state-of-the-art methods. Our source code and experimental data are available in the supplementary materials and will be made publicly available.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。