论文标题
LAMNER:使用字符语言模型和命名实体识别的代码评论生成
LAMNER: Code Comment Generation Using Character Language Model and Named Entity Recognition
论文作者
论文摘要
代码注释生成是为给定代码方法或功能生成高级自然语言描述的任务。尽管研究人员一直在研究自动生成代码注释的多种方法,但以前的工作主要考虑代表代码令牌的整体语义形式(例如,使用语言模型来学习代码令牌的语义),以及其他代码属性的其他代码属性,例如代码的树结构作为辅助输入,以供该模型进行辅助输入。有两个局限性:1)以整体形式学习代码令牌可能无法在源代码中简洁地捕获信息,而2)代码令牌不包含其他句法信息,在编程语言中固有重要的信息。 在本文中,我们介绍了语言模型和命名实体识别(LAMNER),这是一个能够有效编码代码构造并捕获代码令牌的结构属性的代码注释生成器。字符级的语言模型用于学习语义表示以编码代码令牌。对于令牌的结构属性,训练了命名的实体识别模型以学习不同类型的代码令牌。然后将这些表示形式馈送到编码器架构中以生成代码注释。我们在流行的Java数据集上评估了Lamner和其他基线的生成评论,该数据集具有四个常用的指标。我们的结果表明,Lamner具有有效性,比BLEU-1,BLEU-2,BLEU-3,BLEU-4,ROUGE-L,Meteor和Cider的最佳基线模型提高了14.34%,18.98%,21.55%,21.55%,23.00%,23.00%,10.52%,1.44%和25.86%。此外,我们将Lamner的代码表示与基线模型融合在一起,并且融合模型始终显示出对非融合模型的改进。人类评估进一步表明,Lamner产生了高质量的代码评论。
Code comment generation is the task of generating a high-level natural language description for a given code method or function. Although researchers have been studying multiple ways to generate code comments automatically, previous work mainly considers representing a code token in its entirety semantics form only (e.g., a language model is used to learn the semantics of a code token), and additional code properties such as the tree structure of a code are included as an auxiliary input to the model. There are two limitations: 1) Learning the code token in its entirety form may not be able to capture information succinctly in source code, and 2) The code token does not contain additional syntactic information, inherently important in programming languages. In this paper, we present LAnguage Model and Named Entity Recognition (LAMNER), a code comment generator capable of encoding code constructs effectively and capturing the structural property of a code token. A character-level language model is used to learn the semantic representation to encode a code token. For the structural property of a token, a Named Entity Recognition model is trained to learn the different types of code tokens. These representations are then fed into an encoder-decoder architecture to generate code comments. We evaluate the generated comments from LAMNER and other baselines on a popular Java dataset with four commonly used metrics. Our results show that LAMNER is effective and improves over the best baseline model in BLEU-1, BLEU-2, BLEU-3, BLEU-4, ROUGE-L, METEOR, and CIDEr by 14.34%, 18.98%, 21.55%, 23.00%, 10.52%, 1.44%, and 25.86%, respectively. Additionally, we fused LAMNER's code representation with the baseline models, and the fused models consistently showed improvement over the non-fused models. The human evaluation further shows that LAMNER produces high-quality code comments.