论文标题
源代码摘要与结构相对位置指导变压器
Source Code Summarization with Structural Relative Position Guided Transformer
论文作者
论文摘要
源代码摘要旨在为编程语言生成简洁而清晰的自然语言描述。编写良好的代码摘要对程序员参与软件开发和维护过程是有益的。为了了解源代码的语义表示,最近的工作重点是将代码的语法结构纳入变压器等神经网络。这种基于变压器的方法比包括复发性神经网络(RNN)在内的其他神经网络可以更好地捕获远程依赖性,但是,它们中的大多数不考虑令牌之间的结构相对相关性,例如,抽象语法树(ASTS)中的相对位置(ASTS),这对代码语义学学习是有益的。为了建模结构依赖性,我们提出了一个结构相对位置引导的变压器,名为脚本。脚本首先通过解析源代码的AST在代币之间获得结构相对位置,然后将它们传递到两种类型的变压器编码中。一个变压器根据结构相对距离直接调整输入。以及其他变压器在计算自我发项分数过程中编码结构相对位置。最后,我们堆叠这两种类型的变压器编码器,以了解源代码的表示。实验结果表明,相对于BLEU,Rouge-L和基准数据集上的BLEU,提出的脚本的表现分别优于最先进的方法,至少高于1.6%,1.4%和2.8%。我们进一步表明,提出的脚本如何捕获结构相对依赖性。
Source code summarization aims at generating concise and clear natural language descriptions for programming languages. Well-written code summaries are beneficial for programmers to participate in the software development and maintenance process. To learn the semantic representations of source code, recent efforts focus on incorporating the syntax structure of code into neural networks such as Transformer. Such Transformer-based approaches can better capture the long-range dependencies than other neural networks including Recurrent Neural Networks (RNNs), however, most of them do not consider the structural relative correlations between tokens, e.g., relative positions in Abstract Syntax Trees (ASTs), which is beneficial for code semantics learning. To model the structural dependency, we propose a Structural Relative Position guided Transformer, named SCRIPT. SCRIPT first obtains the structural relative positions between tokens via parsing the ASTs of source code, and then passes them into two types of Transformer encoders. One Transformer directly adjusts the input according to the structural relative distance; and the other Transformer encodes the structural relative positions during computing the self-attention scores. Finally, we stack these two types of Transformer encoders to learn representations of source code. Experimental results show that the proposed SCRIPT outperforms the state-of-the-art methods by at least 1.6%, 1.4% and 2.8% with respect to BLEU, ROUGE-L and METEOR on benchmark datasets, respectively. We further show that how the proposed SCRIPT captures the structural relative dependencies.