[Paper Review] CodeBLEU: a Method for Automatic Evaluation of Code Synthesis
CodeBLEU introduces a new automatic evaluation metric for code synthesis that combines BLEU with syntactic (AST) and semantic (data-flow) matches, achieving better correlation with human judgments across text-to-code, code translation, and code refinement tasks.
Evaluation metrics play a vital role in the growth of an area as it defines the standard of distinguishing between good and bad models. In the area of code synthesis, the commonly used evaluation metric is BLEU or perfect accuracy, but they are not suitable enough to evaluate codes, because BLEU is originally designed to evaluate the natural language, neglecting important syntactic and semantic features of codes, and perfect accuracy is too strict thus it underestimates different outputs with the same semantic logic. To remedy this, we introduce a new automatic evaluation metric, dubbed CodeBLEU. It absorbs the strength of BLEU in the n-gram match and further injects code syntax via abstract syntax trees (AST) and code semantics via data-flow. We conduct experiments by evaluating the correlation coefficient between CodeBLEU and quality scores assigned by the programmers on three code synthesis tasks, i.e., text-to-code, code translation, and code refinement. Experimental results show that our proposed CodeBLEU can achieve a better correlation with programmer assigned scores compared with BLEU and accuracy.
Motivation & Objective
- Motivation to improve automatic evaluation beyond BLEU and perfect accuracy for code synthesis.
- Propose CodeBLEU as a weighted combination of surface, syntactic, and semantic matches to capture code correctness.
- Evaluate CodeBLEU’s correlation with human programmer scores across three code tasks.
- Demonstrate that CodeBLEU differentiates systems more effectively and correlates better with human scores than BLEU.
Proposed method
- Define CodeBLEU as a weighted sum of four components: BLEU, weighted BLEU (BLEU_weight), Match_ast (syntactic AST match), and Match_df (semantic data-flow match).
- Introduce weighted n-gram matching that assigns higher weights to keywords (keywords have 5x weight of other tokens).
- Compute syntactic AST match by extracting and comparing sub-trees from ASTs (ignoring leaves).
- Compute semantic data-flow match by constructing data-flow graphs from variables and normalizing names, then comparing candidate vs reference flows.
- Evaluate correlations with human scores using Pearson correlation across three tasks (text-to-code, code translation, code refinement).
Experimental results
Research questions
- RQ1Does CodeBLEU correlate more strongly with human evaluation scores than BLEU across multiple code synthesis tasks?
- RQ2Do the syntactic (AST) and semantic (data-flow) components contribute significantly to alignment with human judgments?
- RQ3How does CodeBLEU perform in differentiating systems and in ablation analyses across different code tasks?
Key findings
- CodeBLEU shows higher Pearson correlation with human scores than BLEU across text-to-code, code translation, and code refinement tasks.
- Ablation studies indicate the AST and data-flow components contribute more to correlation with human judgments than the basic n-gram match in most tasks.
- Hyper-parameter analysis suggests giving more weight to the syntactic and semantic components improves correlation, with a recommended setting around alpha=0.25, beta=0.25, gamma=0.25, delta=0.25 or higher emphasis on the last two components in practice.
- CodeBLEU can distinguish between systems more reliably than BLEU, and its variance is within a reasonable range for sizeable test sets.
Better researchstarts right now
From reading papers to final review, dramatically reduce your research time.
No credit card · Free plan available
This review was created by AI and reviewed by human editors.