Since the rise of neural natural-language-to-code models (NL->Code) that can generate long expressions and statements rather than a single next-token, one of the major problems has been reliably evaluating their generated output. In this paper, we propose CodeBERTScore: an evaluation metric for code generation, which builds on BERTScore (Zhang et al., 2020). Instead of encoding only the generated tokens as in BERTScore, CodeBERTScore also encodes the natural language input preceding the generated code, thus modeling the consistency between the generated code and its given natural language context as well. We perform an extensive evaluation of CodeBERTScore across four programming languages. We find that CodeBERTScore achieves a higher correlation with human preference and with functional correctness than all existing metrics. That is, generated code that receives a higher score by CodeBERTScore is more likely to be preferred by humans, as well as to function correctly when executed. We release five language-specific pretrained models to use with our publicly available code. Our language-specific models have been downloaded more than 1,000,000 times from the Huggingface Hub. Our code and data are available at https://github.com/neulab/code-bert-score
翻译:自神经自然语言到代码模型(NL->Code)兴起以来,这类模型已能生成较长的表达式和语句而非单一后续词元,其生成输出的可靠评估始终是主要难题之一。本文提出CodeBERTScore:一种基于BERTScore(Zhang 等,2020)构建的代码生成评估指标。与BERTScore仅编码生成词元不同,CodeBERTScore同时编码生成代码之前的自然语言输入,从而对生成代码与其给定自然语言上下文之间的一致性进行建模。我们在四种编程语言上对CodeBERTScore进行了全面评估,发现该指标与人类偏好及功能正确性的相关性均优于现有所有指标。即,CodeBERTScore评分越高的生成代码,越可能获得人类青睐,且在运行时功能正确率越高。我们发布了五种语言专用预训练模型,配合公开代码使用。这些语言专用模型在Huggingface Hub的下载量已超过一百万次。代码与数据可访问https://github.com/neulab/code-bert-score。