TL;DR
This paper investigates the reliability of automated metrics like BLEU for evaluating code generation models, finding that they often fail to align with human judgment, especially for small score differences. The authors propose ChrF as a better alternative and call for more robust evaluation practices, including reporting statistical significance and developing new, code-aware metrics.
What Problem Does This Paper Address?
The rapid advancement of code generation models has led to a proliferation of new models and techniques. To keep pace, researchers rely on automated metrics, most notably BLEU, to assess model quality without the prohibitive cost of human evaluation. However, BLEU, originally designed for machine translation, has questionable applicability to code generation. It's unclear if BLEU and other similar metrics truly capture human preferences for code quality, how significant a score difference needs to be to declare one model superior, and how well these metrics correlate with human judgment on code generation tasks. This paper aims to bridge this gap by rigorously evaluating several popular metrics against human assessments on diverse code generation datasets.
Methods
The authors employ a multi-faceted approach to evaluate automated metrics:
- Dataset and Model Collection: They utilize two distinct datasets: CoNaLa (Python one-liners from Stack Overflow) and Hearthstone (Python classes for a game). They also gather outputs from several state-of-the-art code generation models for each dataset.
- Human Evaluation: A crucial component involves human annotators (software developers) rating the quality of generated code snippets on a scale. For CoNaLa, they collected an average of 4.5 grades per snippet from 16 participants. For Hearthstone, 4 participants graded all snippets.
- Synthetic Model Creation: To address the scarcity of diverse models and to simulate a wider range of score differences, they create synthetic models. These models are generated by replacing a percentage of predictions from real models with better or worse ones, based on human assessment scores. This allows for a more granular analysis of metric performance across various score differentials.
- Statistical Analysis: They use paired bootstrap resampling to statistically test the significance of differences in both automated metric scores and human judgments. This helps determine if observed differences are genuine or due to random chance.
- Disagreement Rate Analysis: The core of their evaluation involves comparing metric assessments with human judgments. They quantify "mismatches" where a metric indicates a significant difference between models, but humans do not, or vice-versa (Type-I and Type-II errors). This analysis is performed across different "bins" of score differences to understand how metric reliability changes with the magnitude of the score difference.
Datasets
- CoNaLa: A dataset of 2,879 Python code generation examples (2,379 training, 500 test) derived from Stack Overflow questions and answers. It features diverse intents and generally short, single-line code snippets.
- Card2code Hearthstone: A dataset containing 665 pairs of Hearthstone card descriptions and corresponding Python class implementations. These snippets have a more rigid structure, focusing on class definitions.
Key Insights and Ideas
- BLEU's Limitations: The paper strongly suggests that BLEU, despite its popularity, is often a poor proxy for human judgment in code generation. It frequently fails to distinguish between models that humans perceive as having different quality levels, especially when score differences are small.
- The Importance of Statistical Significance: Simply reporting metric score improvements is insufficient. The study highlights that differences of less than 2 points (and even up to 5 points for BLEU on CoNaLa) are often statistically insignificant, meaning they don't reliably indicate a true improvement in quality.
- ChrF as a Promising Alternative: Among the evaluated metrics, ChrF (character n-gram F-score) consistently shows better agreement with human judgment than BLEU and CodeBLEU, particularly on the CoNaLa dataset.
- Code-Specific Metrics Aren't Always Better: Surprisingly, metrics specifically designed for code, like RUBY and CodeBLEU, do not consistently outperform traditional NLP metrics like ChrF and ROUGE-L in aligning with human assessments.
- Dataset Structure Matters: The rigidity of the Hearthstone dataset's code structure makes it harder for metrics to capture nuanced differences compared to the more varied CoNaLa dataset.
Key Results
- CoNaLa Dataset:
- For Python one-liners, none of the tested metrics can reliably emulate human judgment with >95% certainty if the difference in model scores is less than 5 points.
- ChrF and ROUGE-L are identified as the best-performing metrics for this dataset.
- Hearthstone Dataset:
- For structured code like classes, a difference of at least 2 points in metric scores is needed to claim superiority with >95% certainty.
- ROUGE-L and ChrF are the best-performing metrics for this dataset.
- General Findings:
- For most metrics, a score difference of less than 2 points is insufficient to claim a statistically significant difference between models, even if the difference is statistically significant according to the metric itself.
- Metrics often disagree with human judgment in more than 5% of cases, even for significant score differences.
Limitations and Future Work
- External Validity: The study is limited to two Python datasets with specific characteristics. The generalizability to other programming languages or datasets with different structures is not guaranteed. The authors acknowledge the limited choice of publicly available datasets and models.
- Internal Validity: The relatively small number of human graders per snippet is a potential limitation, though comparable to other studies. The authors mitigated potential bias by shuffling snippets and not revealing correct answers.
- Future Work:
- Extend the study to more programming languages, datasets, and models to assess metric applicability more broadly.
- Conduct more extensive human assessments, aiming for at least 15 assessments per snippet to enable snippet-level analysis.
- Develop new, code-aware metrics, potentially inspired by ML-enhanced metrics like BERTScore, that can better capture code semantics and structure. The authors have made their human assessment scores publicly available to facilitate this.
Summary updated