Skip to main content
QUICK REVIEW

[论文解读] CodeBLEU: a Method for Automatic Evaluation of Code Synthesis

Shuo Ren, Daya Guo|arXiv (Cornell University)|Sep 22, 2020
Software Engineering Research参考文献 27被引用 185
一句话总结

CodeBLEU 引入了一种新的代码合成自动评估指标,它将 BLEU 与句法(AST)和语义(数据流)匹配相结合,在文本到代码、代码翻译和代码改进任务中与人类判断的相关性更高。

ABSTRACT

Evaluation metrics play a vital role in the growth of an area as it defines the standard of distinguishing between good and bad models. In the area of code synthesis, the commonly used evaluation metric is BLEU or perfect accuracy, but they are not suitable enough to evaluate codes, because BLEU is originally designed to evaluate the natural language, neglecting important syntactic and semantic features of codes, and perfect accuracy is too strict thus it underestimates different outputs with the same semantic logic. To remedy this, we introduce a new automatic evaluation metric, dubbed CodeBLEU. It absorbs the strength of BLEU in the n-gram match and further injects code syntax via abstract syntax trees (AST) and code semantics via data-flow. We conduct experiments by evaluating the correlation coefficient between CodeBLEU and quality scores assigned by the programmers on three code synthesis tasks, i.e., text-to-code, code translation, and code refinement. Experimental results show that our proposed CodeBLEU can achieve a better correlation with programmer assigned scores compared with BLEU and accuracy.

研究动机与目标

  • 推进自动评估超越 BLEU,并实现代码合成的完美准确性的动机。
  • 提出 CodeBLEU 作为表层、句法和语义匹配的加权组合,以捕捉代码正确性。
  • 在三个代码任务中评估 CodeBLEU 与人类程序员分数的相关性。
  • 展示 CodeBLEU 在区分系统方面比 BLEU 更有效,并且与人类分数的相关性更高。

提出的方法

  • 将 CodeBLEU 定义为四个组成部分的加权和:BLEU、加权 BLEU(BLEU_weight)、Match_ast(句法 AST 匹配)和 Match_df(语义数据流匹配)。
  • 引入加权 n-gram 匹配,对关键字赋予更高权重(关键字的权重为其他标记的 5 倍)。
  • 通过提取并比较 AST 的子树来计算句法 AST 匹配(忽略叶节点)。
  • 通过从变量构建数据流图并对名称进行规范化来计算语义数据流匹配,然后比较候选流与参考流。
  • 在三个任务(文本到代码、代码翻译、代码改进)上使用皮尔逊相关系数评估与人类分数的相关性。

实验结果

研究问题

  • RQ1CodeBLEU 在多项代码合成任务中是否与人类评估分数的相关性高于 BLEU?
  • RQ2句法(AST)和语义(数据流)组件是否显著有助于与人类判断的一致性?
  • RQ3CodeBLEU 在区分不同系统以及在不同代码任务中的消融分析表现如何?

主要发现

  • CodeBLEU 在文本到代码、代码翻译和代码改进任务中,与人类分数的皮尔逊相关性高于 BLEU。
  • 消融研究表明,AST 和数据流组件在多数任务中对与人类判断相关性的贡献大于基本 n-gram 匹配。
  • 超参数分析表明给句法和语义组件赋予更大权重可以提高相关性,实践中推荐的设置大约为 alpha=0.25、beta=0.25、gamma=0.25、delta=0.25,或者对后两个组件给予更高权重。
  • CodeBLEU 比 BLEU 更可靠地区分系统,且在可观的测试集规模下方差处于合理范围。

更好的研究,从现在开始

从论文设计到论文写作,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。