一句话:提出 CrystalBLEU,通过降低平凡共享 n-gram 噪声,更精确高效地评估代码预测的相似性。
近年来代码预测任务(如代码补全、迁移、修复和自然语言到代码翻译)广泛使用 BLEU 这类 n-gram 指标进行自动评估。然而,编程语言的语法冗长和编码惯例导致不相关代码也共享大量 n-gram,削弱了 BLEU 区分真正相似代码的能力。本文提出 CrystalBLEU,通过降低这些平凡共享 n-gram 带来的噪声,同时保留 BLEU 语言无关、可处理不完整或部分错误代码且高效等优点,从而更精确高效地度量代码相似性。作者在两个已有数据集和一个新构建的语义等价程序标注数据集上评估,结果显示 CrystalBLEU 区分相似与不相似代码的效果比原始 BLEU 及先前面向代码的 BLEU 变体高 1.9–4.5 倍。
Recent years have brought a surge of work on predicting pieces of source code, e.g., for code completion, code migration, program repair, or translating natural language into code. All this work faces the challenge of evaluating the quality of a prediction w.r.t. some oracle, typically in the form of a reference solution. A common evaluation metric is the BLEU score, an n-gram-based metric originally proposed for evaluating natural language translation, but adopted in software engineering because it can be easily computed on any programming language and enables automated evaluation at scale. However, a key difference between natural and programming languages is that in the latter, completely unrelated pieces of code may have many common n-grams simply because of the syntactic verbosity and coding conventions of programming languages. We observe that these trivially shared n-grams hamper the ability of the metric to distinguish between truly similar code examples and code examples that are merely written in the same language. This paper presents CrystalBLEU, an evaluation metric based on BLEU, that allows for precisely and efficiently measuring the similarity of code. Our metric preserves the desirable properties of BLEU, such as being language-agnostic, able to handle incomplete or partially incorrect code, and efficient, while reducing the noise caused by trivially shared n-grams. We evaluate CrystalBLEU on two datasets from prior work and on a new, labeled dataset of semantically equivalent programs. Our results show that CrystalBLEU can distinguish similar from dissimilar code examples 1.9–4.5 times more effectively, when compared to the original BLEU score and a previously proposed variant of BLEU for code.