[Paper Review] ReCode: Robustness Evaluation of Code Generation Models
This paper introduces ReCode, the first comprehensive benchmark for evaluating the robustness of code generation models. It applies over 30 natural, semantics-preserving perturbations—spanning docstrings, function names, syntax, and formatting—to assess model stability under realistic input variations, revealing that models like CodeGen show better robustness than InCoder or GPT-J, especially under syntax and format perturbations.
Code generation models have achieved impressive performance. However, they tend to be brittle as slight edits to a prompt could lead to very different generations; these robustness properties, critical for user experience when deployed in real-life applications, are not well understood. Most existing works on robustness in text or code tasks have focused on classification, while robustness in generation tasks is an uncharted area and to date there is no comprehensive benchmark for robustness in code generation. In this paper, we propose ReCode, a comprehensive robustness evaluation benchmark for code generation models. We customize over 30 transformations specifically for code on docstrings, function and variable names, code syntax, and code format. They are carefully designed to be natural in real-life coding practice, preserve the original semantic meaning, and thus provide multifaceted assessments of a model's robustness performance. With human annotators, we verified that over 90% of the perturbed prompts do not alter the semantic meaning of the original prompt. In addition, we define robustness metrics for code generation models considering the worst-case behavior under each type of perturbation, taking advantage of the fact that executing the generated code can serve as objective evaluation. We demonstrate ReCode on SOTA models using HumanEval, MBPP, as well as function completion tasks derived from them. Interesting observations include: better robustness for CodeGen over InCoder and GPT-J; models are most sensitive to syntax perturbations; more challenging robustness evaluation on MBPP over HumanEval.
Motivation & Objective
- To address the lack of comprehensive, quantitative benchmarks for evaluating the robustness of code generation models in real-world scenarios.
- To identify and characterize model brittleness caused by minor, natural perturbations in prompts—such as rephrased docstrings or renamed variables—that do not alter semantic meaning.
- To develop a generalizable evaluation framework that leverages code execution as objective evaluation, enabling robustness metrics that reflect real-world reliability.
- To provide a standardized, extensible benchmark for comparing state-of-the-art code generation models across diverse perturbation types and datasets like HumanEval and MBPP.
Proposed method
- Design and apply over 30 natural, semantics-preserving transformations across four code aspects: docstrings (e.g., back-translation, paraphrasing), function/variable names (e.g., camelCase renaming, synonym substitution), code syntax (e.g., reordering statements, changing operators), and code format (e.g., indentation, line breaks).
- Use human evaluation and semantic similarity scores (e.g., BERTScore) to verify that >90% of perturbed prompts preserve the original meaning and maintain naturalness.
- Define three robustness metrics: Robust Pass @k (accuracy on perturbed prompts), Robust Drop @k (relative accuracy drop from nominal prompts), and Robust Relative @k (general instability measure), using execution-based correctness as ground truth.
- Apply the benchmark to SOTA models (CodeGen, InCoder, GPT-J) on HumanEval and MBPP, using top-p sampling with temperature 0.2 and n=100 for stable estimation.
- Use execution of generated code as objective evaluation, ensuring correctness is measured by functional behavior rather than surface-level string matching.
- Evaluate robustness across multiple perturbation types and model variants, including different sizes and architectures (e.g., mono vs. multi, 2B to 16B parameters).
Experimental results
Research questions
- RQ1How do state-of-the-art code generation models perform under natural, semantics-preserving perturbations to prompts?
- RQ2Which types of perturbations—docstrings, naming, syntax, or formatting—most severely degrade model robustness?
- RQ3How does model architecture and pretraining data diversity affect robustness to prompt variations?
- RQ4How do robustness metrics like Robust Pass, Robust Drop, and Robust Relative correlate with model performance and stability across different datasets?
- RQ5Is robustness performance consistent across different code generation benchmarks like HumanEval and MBPP?
Key findings
- CodeGen models exhibit significantly better robustness than InCoder and GPT-J across all perturbation types, with Robust Pass @1 on HumanEval reaching 0.306 for CodeGen-16B-mono under nominal conditions.
- Syntax perturbations cause the largest drop in performance, with Robust Drop @1 reaching 60.87% for CodeGen-16B-mono, indicating high sensitivity to structural changes.
- Format perturbations, especially newline and tab-indent changes, lead to substantial robustness degradation: Robust Drop @1 reaches 39.13% for format changes and 45.42% for newline-after-code perturbations on MBPP.
- Models show higher robustness on HumanEval than on MBPP, with Robust Drop @1 for MBPP reaching 45.42% (InCoder-6B) compared to 16.67% (CodeGen-2B-mono) on HumanEval under similar perturbations.
- Robust Drop remains stable across different sampling temperatures and n-values, while Robust Pass and Robust Relative increase with k, indicating consistent metric behavior under varied inference settings.
- Human evaluation confirms that over 90% of perturbed prompts preserve semantic meaning, validating the naturalness and validity of the ReCode benchmark.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.