一句话:提出 DECOM 多轮审议框架,以检索到的注释为初稿迭代润色,并由评估模型决定终止,从而生成更优代码注释。
自动注释生成旨在为代码片段生成自然语言描述。受人类「先写草稿、再反复润色」这一认知过程启发,作者提出 DECOM——一个面向自动注释生成的多轮审议框架,由多个审议模型(Deliberation Model)与一个评估模型(Evaluation Model)组成。给定代码片段,先从中抽取关键词,并从预定义语料库中检索相似代码片段,将其注释作为初始草稿;随后把草稿、代码与关键词一并输入 DECOM 开始迭代审议:每轮由审议模型润色草稿并生成新注释,评估模型度量新注释质量,据此决定是否终止迭代。迭代结束后选取最佳注释作为目标注释。在 Java(87K)与 Python(108K)两个真实数据集上的实验表明,该方法优于当前最先进基线;人工评估也证实 DECOM 生成的注释通常更可读、信息量更大且更有用。
Deliberation is a common and natural behavior in human daily life. For example, when writing papers or articles, we usually first write drafts, and then iteratively polish them until satisfied. In light of such a human cognitive process, we propose DECOM, which is a multi-pass deliberation framework for automatic comment generation. DECOM consists of multiple Deliberation Models and one Evaluation Model. Given a code snippet, we first extract keywords from the code and retrieve a similar code fragment from a pre-defined corpus. Then, we treat the comment of the retrieved code as the initial draft and input it with the code and keywords into DECOM to start the iterative deliberation process. At each deliberation, the deliberation model polishes the draft and generates a new comment. The evaluation model measures the quality of the newly generated comment to determine whether to end the iterative process or not. When the iterative process is terminated, the best-generated comment will be selected as the target comment. Our approach is evaluated on two real-world datasets in Java (87K) and Python (108K), and experiment results show that our approach outperforms the state-of-the-art baselines. A human evaluation study also confirms the comments generated by DECOM tend to be more readable, informative, and useful.