通过为生成而检索改进检索增强的代码注释生成
Improving Retrieval-Augmented Code Comment Generation by Retrieving for Generation
AI总结:
本文提出JOINTCOM方法,通过让检索器学习生成器的反馈来检索对生成最有利的示例,从而改进检索增强的代码注释生成,并在两个数据集上显著超越现有基线。
摘要:
代码注释生成旨在从源代码中自动生成高质量注释,并已被研究多年。近期研究提出将信息检索技术与神经生成模型相结合来解决这一问题,即检索增强的注释生成(RACG)方法,并取得了最先进的结果。然而,以往工作中的检索器是独立于其生成器构建的。这导致检索到的示例并不一定是对生成注释最有用的示例,从而限制了现有方法的性能。为了解决这一局限性,我们提出了一种新颖的训练策略,使检索器能够从生成器的反馈中学习,并为生成检索示例。具体来说,在训练过程中,我们使用检索器检索前k个示例并计算它们的检索分数,同时使用生成器基于每个示例计算样本的生成损失。通过将检索器检索到的高分示例与生成器观察到的低损失示例对齐,检索器可以学会检索那些最能提高生成注释质量的示例。基于这一策略,我们提出了一种名为JOINTCOM的新型RACG方法,并在两个真实世界数据集JCSD和PCSD上对其进行了评估。实验结果表明,在两个数据集上的五项指标方面,我们的方法比最先进的基线高出7.3%至30.0%。我们还进行了人工评估,将JOINTCOM与表现最佳的基线进行比较。结果表明,JOINTCOM优于基线,生成的注释更自然、信息更丰富且更有用。
英文摘要:
Code comment generation aims to generate high-quality comments from source code automatically and has been studied for years. Recent studies proposed to integrate information retrieval techniques with neural generation models to tackle this problem, i.e., Retrieval-Augmented Comment Generation (RACG) approaches, and achieved state-of-the-art results. However, the retrievers in previous work are built independently of their generators. This results in that the retrieved exemplars are not necessarily the most useful ones for generating comments, limiting the performance of existing approaches. To address this limitation, we propose a novel training strategy to enable the retriever to learn from the feedback of the generator and retrieve exemplars for generation. Specifically, during training, we use the retriever to retrieve the top-k exemplars and calculate their retrieval scores, and use the generator to calculate a generation loss for the sample based on each exemplar. By aligning high-score exemplars retrieved by the retriever with low-loss exemplars observed by the generator, the retriever can learn to retrieve exemplars that can best improve the quality of the generated comments. Based on this strategy, we propose a novel RACG approach named JOINTCOM and evaluate it on two real-world datasets, JCSD and PCSD. The experimental results demonstrate that our approach surpasses the state-of-the-art baselines by 7.3% to 30.0% in terms of five metrics on the two datasets. We also conduct a human evaluation to compare JOINTCOM with the best-performing baselines. The results indicate that JOINTCOM outperforms the baselines, producing comments that are more natural, informative, and useful.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。