Automatically generating human-readable text describing the functionality of a program is the intent of source code summarization. Although Neural Language Models achieve significant performance in this field, an emerging trend is combining neural models with external knowledge. Most previous approaches rely on the sentence-level retrieval and combination paradigm (retrieval of similar code snippets and use of the corresponding code and summary pairs) on the encoder side. However, this paradigm is coarse-grained and cannot directly take advantage of the high-quality retrieved summary tokens on the decoder side. In this paper, we explore a fine-grained token-level retrieval-augmented mechanism on the decoder side to help the vanilla neural model generate a better code summary. Furthermore, to mitigate the limitation of token-level retrieval on capturing contextual code semantics, we propose to integrate code semantics into summary tokens. Extensive experiments and human evaluation reveal that our token-level retrieval-augmented approach significantly improves performance and is more interpretive.
翻译:自动生成描述程序功能的人类可读文本是源码摘要的核心目标。尽管神经语言模型在此领域取得了显著性能,但结合神经网络模型与外部知识正成为新兴趋势。现有方法大多在编码器侧采用句子级检索与组合范式(检索相似代码片段并利用对应代码-摘要对),然而该范式粒度较粗,无法在解码器侧直接利用高质量检索到的摘要令牌。本文探索在解码器侧引入细粒度的令牌级检索增强机制,以辅助原始神经模型生成更优的代码摘要。此外,为缓解令牌级检索在捕获上下文代码语义方面的局限性,我们提出将代码语义融入摘要令牌。大量实验与人工评估表明,我们的令牌级检索增强方法显著提升了性能且具有更强的可解释性。