一句话:提出融合检索相似代码片段的神经源代码摘要方法,缓解低频词问题并提升生成质量。
源代码摘要旨在用自然语言自动生成简洁描述,帮助开发者理解与维护代码。传统信息检索方法通过选择原始代码词项或复用相似代码片段的摘要来生成摘要;近期神经机器翻译方法采用编码器-解码器网络直接生成摘要,但偏好语料中的高频词,难以处理低频词。该文提出基于检索的神经源代码摘要方法:首先在训练集上训练带注意力的编码器-解码器模型;其次对测试输入,分别从语法和语义角度检索训练集中最相似的两个代码片段;最后编码输入与检索片段,并在解码阶段融合以预测摘要。大量实验表明,该方法优于当前最优方法。
Source code summarization aims to automatically generate concise summaries of source code in natural language texts, in order to help developers better understand and maintain source code. Traditional work generates a source code summary by utilizing information retrieval techniques, which select terms from original source code or adapt summaries of similar code snippets. Recent studies adopt Neural Machine Translation techniques and generate summaries from code snippets using encoder-decoder neural networks. The neural-based approaches prefer the high-frequency words in the corpus and have trouble with the low-frequency ones. In this paper, we propose a retrieval-based neural source code summarization approach where we enhance the neural model with the most similar code snippets retrieved from the training set. Our approach can take advantages of both neural and retrieval-based techniques. Specifically, we first train an attentional encoder-decoder model based on the code snippets and the summaries in the training set; Second, given one input code snippet for testing, we retrieve its two most similar code snippets in the training set from the aspects of syntax and semantics, respectively; Third, we encode the input and two retrieved code snippets, and predict the summary by fusing them during decoding. We conduct extensive experiments to evaluate our approach and the experimental results show that our proposed approach can improve the state-of-the-art methods.
DOI 原文 ·
@inproceedings{paperbot5654,
title = {Retrieval-based neural source code summarization},
author = {Jian Zhang and Xu Wang and Hongyu Zhang and Hailong Sun and Xudong Liu},
booktitle = {ICSE},
year = {2020},
doi = {10.1145/3377811.3380383}
}