codebleu
CodeBLEU: a Method for Automatic Evaluation of Code Synthesis — Ren et al. (2020) (arXiv:2009.10297, 2020)
What this evaluates
Evaluates the validity of the CodeBLEU metric for code synthesis by measuring its correlation with human programmer judgments across text-to-code generation, code translation, and code refinement tasks.
Datasets
- Iyer et al. [2018] dataset — total 104000; splits: train (100000), val (2000), test (2000)
- Code translation dataset (Java to C#) — total 11800; splits: dev (500), test (1000)
- Tufano et al. [2019] dataset — total ?; splits: train_small (46680), dev_small (5835), test_small (5835), train_medium (52364), dev_medium (6545), test_medium (6545)
Metrics
CodeBLEU (primary) — range: [0, 100]
- Combines weighted n-gram matching (BLEU), AST subtree alignment, and semantic similarity via data-flow analysis using hyperparameters α, β, γ, δ. Scaled to 0-100.
Input / output format
Input: Natural language documentation and class environment (variable names/types, method names/return types) for text-to-code; Java method code for translation; buggy Java function code for refinement.
Output: Generated code (Java method/function or C# method).
Scoring recipe
def compute_codebleu(predictions, references):
bleu = compute_ngram_precision(predictions, references)
ast_match = compute_ast_subtree_match(predictions, references)
df_match = compute_dataflow_similarity(predictions, references)
# Default weights: alpha=0.25, beta=0.25, gamma=0.25, delta=0.25
score = 0.25 * bleu + 0.25 * ast_match + 0.25 * df_match
return score * 100 # Paper reports scores in [0, 100]
Common pitfalls
- CodeBLEU scores are scaled to 0-100, not 0-1.
- Human evaluation uses a 1-5 Likert scale, not a percentage or 0-1 score.
- The metric's validity is assessed via Pearson correlation with human scores, not direct task accuracy.
- Hyperparameters α, β, γ, δ significantly impact correlation; default is not always optimal.
Evidence (verbatim from paper)
For each task, we calculate the Pearson correlation coefficient to check the correlation between the scores given by our proposed CodeBLEU and the scores assigned by programmers (human evaluation scores).
Citation
@misc{ren2020codebleu,
title={CodeBLEU: a Method for Automatic Evaluation of Code Synthesis},
author={Ren et al. (2020)},
year={2020},
note={arXiv:2009.10297}
}
1---2name: codebleu3description: Evaluates the validity of the CodeBLEU metric for code synthesis by measuring its correlation with human programmer judgments across text-to-code generation, code translation, and code refinement tasks. Use when the user has predictions and gold and needs to compute CodeBLEU.4---56# codebleu78> CodeBLEU: a Method for Automatic Evaluation of Code Synthesis — Ren et al. (2020) (arXiv:2009.10297, 2020)910## What this evaluates1112Evaluates the validity of the CodeBLEU metric for code synthesis by measuring its correlation with human programmer judgments across text-to-code generation, code translation, and code refinement tasks.1314## Datasets1516- **Iyer et al. [2018] dataset** — total 104000; splits: train (100000), val (2000), test (2000)17- **Code translation dataset (Java to C#)** — total 11800; splits: dev (500), test (1000)18- **Tufano et al. [2019] dataset** — total ?; splits: train_small (46680), dev_small (5835), test_small (5835), train_medium (52364), dev_medium (6545), test_medium (6545)1920## Metrics2122- `CodeBLEU` **(primary)** — range: [0, 100]23 - Combines weighted n-gram matching (BLEU), AST subtree alignment, and semantic similarity via data-flow analysis using hyperparameters α, β, γ, δ. Scaled to 0-100.2425## Input / output format2627**Input**: Natural language documentation and class environment (variable names/types, method names/return types) for text-to-code; Java method code for translation; buggy Java function code for refinement.2829**Output**: Generated code (Java method/function or C# method).3031## Scoring recipe3233```python34def compute_codebleu(predictions, references):35 bleu = compute_ngram_precision(predictions, references)36 ast_match = compute_ast_subtree_match(predictions, references)37 df_match = compute_dataflow_similarity(predictions, references)38 # Default weights: alpha=0.25, beta=0.25, gamma=0.25, delta=0.2539 score = 0.25 * bleu + 0.25 * ast_match + 0.25 * df_match40 return score * 100 # Paper reports scores in [0, 100]41```4243## Common pitfalls4445- CodeBLEU scores are scaled to 0-100, not 0-1.46- Human evaluation uses a 1-5 Likert scale, not a percentage or 0-1 score.47- The metric's validity is assessed via Pearson correlation with human scores, not direct task accuracy.48- Hyperparameters α, β, γ, δ significantly impact correlation; default is not always optimal.4950## Evidence (verbatim from paper)5152> For each task, we calculate the Pearson correlation coefficient to check the correlation between the scores given by our proposed CodeBLEU and the scores assigned by programmers (human evaluation scores).5354## Citation5556```bibtex57@misc{ren2020codebleu,58 title={CodeBLEU: a Method for Automatic Evaluation of Code Synthesis},59 author={Ren et al. (2020)},60 year={2020},61 note={arXiv:2009.10297}62}63```6465- arXiv: 2009.10297