arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2308.05646cs.CLcs.LGcs.PLcs.SE
收藏

AST-MHSA:基于多头自注意力的代码摘要生成

AST-MHSA : Code Summarization using Multi-Head Self-Attention

Indian Institute of Technology Madras(印度理工学院马德拉斯分校);Walmart Global Tech(沃尔玛全球技术)

Yeshwanth Nagaraj, Ujjwal Gupta

AI总结:

针对AST过长导致编码效率低和依赖关系难以提取的问题,提出AST-MHSA模型,利用多头自注意力从AST中提取关键语义信息,以更高效地生成代码摘要。

摘要:

代码摘要旨在为源代码生成简洁的自然语言描述。当前主流方法采用基于Transformer的编码器-解码器架构,其中源代码的抽象语法树(AST)被用于编码结构信息。然而,AST比对应的源代码长得多,现有方法忽略了这一长度约束,直接将整个线性化的AST输入编码器。这种简单化的做法使得从过长的输入序列中提取真正有价值的依赖关系变得困难,并且由于对AST中的所有节点应用自注意力而导致显著的计算开销。为了有效且高效地解决这一问题,我们提出了一个模型AST-MHSA,该模型使用多头注意力从AST中提取重要的语义信息。该模型由两个主要组件组成:编码器和解码器。编码器以代码的抽象语法树(AST)作为输入,并生成一系列隐藏状态。然后,解码器以这些隐藏状态作为输入,并生成代码的自然语言摘要。多头注意力机制使模型能够学习输入代码的不同表示,这些表示可以被组合起来生成更全面的摘要。该模型在代码和摘要的数据集上进行训练,并优化模型参数以最小化生成摘要与真实摘要之间的损失。

英文摘要:

Code summarization aims to generate concise natural language descriptions for source code. The prevailing approaches adopt transformer-based encoder-decoder architectures, where the Abstract Syntax Tree (AST) of the source code is utilized for encoding structural information. However, ASTs are much longer than the corresponding source code, and existing methods ignore this size constraint by directly feeding the entire linearized AST into the encoders. This simplistic approach makes it challenging to extract truly valuable dependency relations from the overlong input sequence and leads to significant computational overhead due to self-attention applied to all nodes in the AST. To address this issue effectively and efficiently, we present a model, AST-MHSA that uses multi-head attention to extract the important semantic information from the AST. The model consists of two main components: an encoder and a decoder. The encoder takes as input the abstract syntax tree (AST) of the code and generates a sequence of hidden states. The decoder then takes these hidden states as input and generates a natural language summary of the code. The multi-head attention mechanism allows the model to learn different representations of the input code, which can be combined to generate a more comprehensive summary. The model is trained on a dataset of code and summaries, and the parameters of the model are optimized to minimize the loss between the generated summaries and the ground-truth summaries.

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

↑