A proper code evaluation metric (CEM) profoundly impacts the evolution of code generation, which is an important research field in NLP and software engineering. Prevailing match-based CEMs (e.g., BLEU, Accuracy, and CodeBLEU) suffer from two significant drawbacks. 1. They primarily measure the surface differences between codes without considering their functional equivalence. However, functional equivalence is pivotal in evaluating the effectiveness of code generation, as different codes can perform identical operations. 2. They are predominantly designed for the Ref-only input format. However, code evaluation necessitates versatility in input formats. Aside from Ref-only, there are NL-only and Ref\&NL formats, which existing match-based CEMs cannot effectively accommodate. In this paper, we propose CodeScore, a large language model (LLM)-based CEM, which estimates the functional correctness of generated code on three input types. To acquire CodeScore, we present UniCE, a unified code generation learning framework, for LLMs to learn code execution (i.e., learning PassRatio and Executability of generated code) with unified input. Extensive experimental results on multiple code evaluation datasets demonstrate that CodeScore absolutely improves up to 58.87% correlation with functional correctness compared to other CEMs, achieves state-of-the-art performance, and effectively handles three input formats.
翻译:一种恰当的代码评估指标深刻影响着代码生成的演进,而代码生成是自然语言处理与软件工程领域的重要研究方向。现有基于匹配的代码评估指标(如BLEU、准确率和CodeBLEU)存在两个显著缺陷:1)它们主要衡量代码之间的表层差异,未考虑代码的功能等价性。然而,功能等价性对评估代码生成效果至关重要——不同代码可能执行相同操作。2)它们主要针对仅参考输入格式设计。但代码评估需要兼容多种输入格式,除仅参考格式外,还存在纯自然语言与参考&自然语言格式,现有基于匹配的评估指标无法有效适配这些场景。本文提出CodeScore——一种基于大语言模型的代码评估指标,可针对三种输入类型评估生成代码的功能正确性。为获得CodeScore,我们提出UniCE(统一代码生成学习框架),使大语言模型通过统一输入学习代码执行(即学习生成代码的通过率与可执行性)。在多个代码评估数据集上的大量实验表明:相比其他代码评估指标,CodeScore与功能正确性的相关性最高提升58.87%,达到了最先进性能,并能有效处理三种输入格式。