Skip to main content
QUICK REVIEW

[Paper Review] CodeScore: Evaluating Code Generation by Learning Code Execution

Yihong Dong, Jiazheng Ding|arXiv (Cornell University)|Jan 22, 2023
Software Engineering ResearchComputer Science10 citations
TL;DR

CodeScore is an LLM-based code evaluation metric that estimates functional correctness across Ref-only, NL-only, and Ref&NL inputs by learning code execution through the UniCE framework, achieving state-of-the-art correlation with true functional correctness on multiple datasets.

ABSTRACT

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.

Motivation & Objective

  • Motivate the need for evaluation metrics that capture functional correctness beyond surface similarity.
  • Propose CodeScore, an LLM-based metric that estimates code execution correctness across multiple input formats.
  • Introduce UniCE, a unified learning framework to train LLMs to predict execution-based scores.
  • Create and utilize three code-evaluation datasets (APPS-Eval, MBPP-Eval, HE-Eval) to benchmark CEMs.

Proposed method

  • Define PassRatio as the fraction of test cases where generated code outputs match expected outputs.
  • Introduce Executability to distinguish executable vs. non-executable code when PassRatio is zero.
  • Propose UniCE, a multi-format input learning framework that uses layer-wise pooling and first-token embeddings to produce CodeScore and Exec.
  • Train UniCE with a loss L = L_C + L_E, where L_C aligns CodeScore with PassRatio and L_E models Executability.
  • Implement multi-task training to handle Ref-only, NL-only, and Ref&NL input formats via L^{Ref}, L^{NL}, and L^{Ref+NL} losses, respectively.
  • Evaluate CodeScore against baseline match-based, LLM-based, and execution-based metrics on three datasets, using Kendall-Tau, Spearman’s rs, Pearson rp, and MAE as correlations to ground truth.

Experimental results

Research questions

  • RQ1RQ1: How does CodeScore correlate with functional correctness compared to other evaluation metrics?
  • RQ2RQ2: How effective is Exec at identifying executability of generated code when dependencies are met?
  • RQ3RQ3: What is the impact of the UniCE loss L^{Uni} across different input formats?
  • RQ4RQ4: How well do human evaluators regard CodeScore and other metrics in judging functional correctness?
  • RQ5RQ5: How do CodeScore and baselines perform in practical code evaluation scenarios?

Key findings

  • CodeScore shows significantly higher correlation with functional correctness than both match-based and other LLM-based metrics on APPS-Eval (τ, rs, rp improvements of 40.56%, 55.07%, and 58.87% respectively).
  • CodeScore achieves strong correlations (e.g., rs > 0.6) with Ground Truth and the lowest MAE among baselines on APPS-Eval.
  • Execution time for CodeScore is comparable to other LLM-based metrics and orders of magnitude faster than large-scale execution-based CEMs (e.g., 1k–20k× faster).
  • CodeScore generalizes to MBPP-Eval and HE-Eval with fine-tuning/zero-shot, maintaining superior correlation against baselines.
  • The UniCE loss L^{Uni} improves CodeScore across Ref-only, NL-only, and Ref&NL formats, with Ref&NL often yielding best results.
  • Human evaluation shows CodeScore outperforms other metrics (CodeScore 3.4 vs Ground Truth 4.6 on a 0–5 scale), with significant statistical support.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.