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, they are limited by their inability to access external knowledge. To address this limitation, an emerging trend is combining neural models with external knowledge through retrieval methods. Previous methods have relied on the sentence-level retrieval paradigm on the encoder side. However, this paradigm is coarse-grained, noise-filled and cannot directly take advantage of the high-quality retrieved summary tokens on the decoder side. In this paper, we propose a fine-grained Token-level retrieval-augmented mechanism (Tram) on the decoder side rather than the encoder side to enhance the performance of neural models and produce more low-frequency tokens in generating summaries. Furthermore, to overcome the challenge of token-level retrieval in capturing contextual code semantics, we also propose integrating code semantics into individual summary tokens. The results of extensive experiments and human evaluation show that our token-level retrieval-augmented approach significantly improves performance and is more interpretable.
翻译:自动生成描述程序功能的人类可读文本是源代码摘要的目标。尽管神经语言模型在该领域取得了显著性能,但由于无法访问外部知识而受到限制。为解决这一局限,新兴趋势是通过检索方法将神经模型与外部知识结合。以往方法依赖编码器侧的句子级检索范式,但该范式粗粒度、充满噪声,且无法直接利用解码器侧高质量检索到的摘要令牌。本文提出在解码器侧而非编码器侧采用细粒度的令牌级检索增强机制(Tram),以提升神经模型性能,并在生成摘要时产生更多低频令牌。此外,为克服令牌级检索在捕获上下文代码语义方面的挑战,我们还提出将代码语义集成到单个摘要令牌中。大量实验和人工评估结果表明,我们的令牌级检索增强方法显著提升了性能,且具有更高的可解释性。