[论文解读] CodeScore: Evaluating Code Generation by Learning Code Execution
CodeScore 是一个基于 LLM 的代码评估度量,通过 UniCE 框架学习代码执行,在 Ref-only、NL-only、和 Ref&NL 输入上估计功能正确性,在多个数据集上与真实功能正确性具有最先进的相关性。
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.
研究动机与目标
- 激发需要能够捕捉功能正确性、超越表面相似性的评估指标的需求。
- 提出 CodeScore,一种基于 LLM 的度量,用于在多种输入格式下估计代码执行正确性。
- 引入 UniCE,一种统一的学习框架,用于训练LLMs以预测基于执行的分数。
- 创建并使用三个代码评估数据集(APPS-Eval、MBPP-Eval、HE-Eval)来基准测试 CEMs。
提出的方法
- 将 PassRatio 定义为生成代码输出与预期输出相匹配的测试用例所占的比例。
- 引入 Executability,用于在 PassRatio 为零时区分可执行与不可执行的代码。
- 提出 UniCE,一种多格式输入学习框架,使用分层池化和首个标记嵌入来产生 CodeScore 和 Exec。
- 用损失 L = L_C + L_E 训练 UniCE,其中 L_C 使 CodeScore 与 PassRatio 对齐,L_E 建模 Executability。
- 实现多任务训练,通过 L^{Ref}、L^{NL}、L^{Ref+NL} 损失,分别处理 Ref-only、NL-only 和 Ref&NL 输入格式。
- 在三个数据集上,将 CodeScore 与基线的匹配-based、基于 LLm 的、和基于执行的度量进行对比评估,使用 Kendall-Tau、Spearman 的 rs、Pearson 的 rp 以及 MAE 作为与真实值的相关性指标。
实验结果
研究问题
- RQ1RQ1:与其他评估指标相比,CodeScore 与功能正确性的相关性如何?
- RQ2RQ2:在满足依赖关系时,Exec 在识别生成代码的可执行性方面有多有效?
- RQ3RQ3:在不同输入格式下,UniCE 损失 L^{Uni} 的影响如何?
- RQ4RQ4:人工评估者在判断功能正确性时对 CodeScore 及其他指标的评价如何?
- RQ5RQ5:CodeScore 与基线在实际代码评估场景中的表现如何?
主要发现
- CodeScore 在 APPS-Eval 上与功能正确性的相关性显著高于基于匹配的和其他基于 LLM 的指标(τ、rs、rp 分别提升 40.56%、55.07%、58.87%)。
- CodeScore 在 APPS-Eval 与 Ground Truth 之间取得强相关性(例如 rs>0.6),并且在基线中 MAE 最低。
- CodeScore 的执行时间与其他基于 LLM 的度量相当,且比基于执行的大规模 CEM 快上数千到上万倍(例如 1000–20000× 更快)。
- CodeScore 在 MBPP-Eval 和 HE-Eval 上通过微调/零-shot 泛化,保持相对于基线的优越相关性。
- UniCE 损失 L^{Uni} 在 Ref-only、NL-only 和 Ref&NL 格式中提升 CodeScore,Ref&NL 常常产生最佳结果。
- 人工评估显示 CodeScore 优于其他指标(CodeScore 3.4 对比 Ground Truth 4.6,在 0–5 量表上),具有显著的统计支持。
更好的研究,从现在开始
从论文设计到论文写作,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。