Code comment generation techniques aim to generate natural language descriptions for source code. There are two orthogonal approaches for this task, i.e., information retrieval (IR) based and neural-based methods. Recent studies have focused on combining their strengths by feeding the input code and its similar code snippets retrieved by the IR-based approach to the neural-based approach, which can enhance the neural-based approach's ability to output low-frequency words and further improve the performance. However, despite the tremendous progress, our pilot study reveals that the current combination is not generalizable and can lead to performance degradation. In this paper, we propose a straightforward but effective approach to tackle the issue of existing combinations of these two comment generation approaches. Instead of binding IR- and neural-based approaches statically, we combine them in a dynamic manner. Specifically, given an input code snippet, we first use an IR-based technique to retrieve a similar code snippet from the corpus. Then we use a Cross-Encoder based classifier to decide the comment generation method to be used dynamically, i.e., if the retrieved similar code snippet is a true positive (i.e., is semantically similar to the input), we directly use the IR-based technique. Otherwise, we pass the input to the neural-based model to generate the comment. We evaluate our approach on a large-scale dataset of Java projects. Experiment results show that our approach can achieve 25.45 BLEU score, which improves the state-of-the-art IR-based approach, neural-based approach, and their combination by 41%, 26%, and 7%, respectively. We propose a straightforward but effective dynamic combination of IR-based and neural-based comment generation, which outperforms state-of-the-art approaches by a substantial margin.
翻译:代码生成技术旨在生成源代码的自然语言描述。 但是, 我们的实验研究显示, 目前结合方法不是通用的, 并且可能导致性能退化。 在本文件中, 我们建议一种直接而有效的方法来解决这两种备注生成方法的现有组合问题。 与其以IR为基础的输入代码及其类似的代码片断一起, 我们以动态方式将它们结合在一起。 具体地说, 以基于神经的方法来输出低频单词和进一步改进性能的能力, 这可以提高基于神经的方法从源代码中获取类似的代码片断的能力。 然而, 尽管取得了巨大的进步, 我们的实验研究显示, 目前结合方法不是通用的, 并可能导致性能退化。 在本文中, 我们建议一种直接但有效的方法来解决这两种备评分方法的现有组合问题。 而不是基于IR- 和基于神经的代码片断, 我们的基于基于 Crosy- Encoder 的组合方法, 我们可以直接使用一个真实的版本的版本。