Code comments are significantly helpful in comprehending software programs and also aid developers to save a great deal of time in software maintenance. Code comment generation aims to automatically predict comments in natural language given a code snippet. Several works investigate the effect of integrating external knowledge on the quality of generated comments. In this study, we propose a solution, namely APIContext2Com, to improve the effectiveness of generated comments by incorporating the pre-defined Application Programming Interface (API) context. The API context includes the definition and description of the pre-defined APIs that are used within the code snippets. As the detailed API information expresses the functionality of a code snippet, it can be helpful in better generating the code summary. We introduce a seq-2-seq encoder-decoder neural network model with different sets of multiple encoders to effectively transform distinct inputs into target comments. A ranking mechanism is also developed to exclude non-informative APIs, so that we can filter out unrelated APIs. We evaluate our approach using the Java dataset from CodeSearchNet. The findings reveal that the proposed model improves the best baseline by 1.88 (8.24 %), 2.16 (17.58 %), 1.38 (18.3 %), 0.73 (14.17 %), 1.58 (14.98 %) and 1.9 (6.92 %) for BLEU1, BLEU2, BLEU3, BLEU4, METEOR, ROUGE-L respectively. Human evaluation and ablation studies confirm the quality of the generated comments and the effect of architecture and ranking APIs.
翻译:代码注释对于理解软件程序具有重要帮助,同时能显著节省开发者在软件维护中的时间。代码注释生成旨在根据给定代码片段自动预测自然语言注释。已有研究探讨了整合外部知识对生成注释质量的影响。本文提出名为APIContext2Com的解决方案,通过融入预定义应用程序编程接口(API)上下文来提高生成注释的有效性。API上下文包含代码片段中使用的预定义API的定义与描述。由于详细的API信息能体现代码片段的功能,因此有助于更好地生成代码摘要。我们引入具有多组编码器的序列到序列(seq-2-seq)编码器-解码器神经网络模型,以有效将不同输入转化为目标注释。同时开发排序机制来排除非信息性API,从而过滤无关API。使用CodeSearchNet中的Java数据集进行评估,结果表明:与最佳基线相比,本模型在BLEU1、BLEU2、BLEU3、BLEU4、METEOR和ROUGE-L指标上分别提升1.88(8.24%)、2.16(17.58%)、1.38(18.3%)、0.73(14.17%)、1.58(14.98%)和1.9(6.92%)。人工评估与消融研究验证了生成注释的质量,以及架构设计与API排序机制的有效性。