arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2010.04459cs.SEcs.AI
收藏

基于样本的神经评论生成算法

Retrieve and Refine: Exemplar-based Neural Comment Generation

Peking University(北京大学);Monash University(莫纳什大学)

Bolin Wei, Yongmin Li, Ge Li, Xin Xia, Zhi Jin

摘要:

代码注释生成是软件自动开发领域的一项重要任务,其目的是自动生成源代码的自然语言描述。传统的注释生成方法使用手工制作的模板或信息检索(IR)技术来生成源代码摘要。近年来,基于神经网络的方法利用广受好评的编码器-解码器深度学习框架从大规模并行代码语料库中学习注释生成模式,取得了令人印象深刻的结果。然而,这些新兴的方法仅将代码相关信息作为输入。软件重用在软件开发过程中很常见,这意味着相似代码片段的注释有助于注释生成。受基于IR和基于模板的方法的启发,本文提出了一种神经注释生成方法,其中我们使用相似代码片段的现有注释作为范例来指导注释生成。具体来说,给定一段代码,我们首先使用IR技术来检索类似的代码片段,并将其注释视为范例。然后,我们设计了一种新的seq 2seq神经网络,它以给定的代码,其AST,其类似的代码,其范例作为输入,并利用来自范例的信息,以协助在目标评论生成的基础上的源代码和类似的代码之间的语义相似性。我们评估我们的方法上的一个大规模的Java语料库,其中包含约2 M的样本,实验结果表明,我们的模型优于国家的最先进的方法的大幅利润。

英文摘要:

Code comment generation which aims to automatically generate natural language descriptions for source code, is a crucial task in the field of automatic software development. Traditional comment generation methods use manually-crafted templates or information retrieval (IR) techniques to generate summaries for source code. In recent years, neural network-based methods which leveraged acclaimed encoder-decoder deep learning framework to learn comment generation patterns from a large-scale parallel code corpus, have achieved impressive results. However, these emerging methods only take code-related information as input. Software reuse is common in the process of software development, meaning that comments of similar code snippets are helpful for comment generation. Inspired by the IR-based and template-based approaches, in this paper, we propose a neural comment generation approach where we use the existing comments of similar code snippets as exemplars to guide comment generation. Specifically, given a piece of code, we first use an IR technique to retrieve a similar code snippet and treat its comment as an exemplar. Then we design a novel seq2seq neural network that takes the given code, its AST, its similar code, and its exemplar as input, and leverages the information from the exemplar to assist in the target comment generation based on the semantic similarity between the source code and the similar code. We evaluate our approach on a large-scale Java corpus, which contains about 2M samples, and experimental results demonstrate that our model outperforms the state-of-the-art methods by a substantial margin.

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

↑