R e C ode: Robustness Evaluation of Code Generation Models (2023)

Abstract: 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.

## introduction code generation has emerged as an important ai application. multiple models @xcite @xcite have been proposed and achieved impressive performance on generating code using a natural-language description, on completing partial lines and functions, and even on solving complex coding-contest problems. they can offer real-life help to software engineers and enhance their productivity, and multiple commercial offerings exist today for aipowered code generation @xcite . however, one important aspect, robustness of the code generation models, is commonly overlooked. anecdotally, people know that these models are sensitive to perturbations over prompts: sometimes just an extra space in a line or a slight change to a function name would lead to completely different generations, with potentially negative impacts to usability. in fig. 1 and fig. 2 , we show two failure cases on incoder-6b @xcite and codegen-16b-mono @xcite where they perform correctly on regular prompts but fail on our perturbed ones after docstring paraphrasing and function camel case renaming in our recode benchmark. the perturbed prompts are natural and retain the original meaning, indicating weakness of these models if deployed in real-life applications. there exists no comprehensive and quantitative robustness benchmark for code generation models. @xcite includes a brief study on robustness but it has limited perturbation types and is in a setting with massive numbers of samples, unrealistic in practice. other existing works on robustness in text or code tasks have focused on classification and are not directly applicable to code generation @xcite . in this paper, we present recode, a robustness evaluation framework for code, aiming to provide comprehensive assessment for robustness of code generation models. recode includes only transformations that (1) appear naturally in practice and (2) preserve the semantic meaning of the original inputs. we carefully collect and customize a comprehensive list of natural transformations on docstrings, function and variable names, code syntax, and code format, providing multifaceted assessments of a model's robustness performance. we verify the quality of the perturbed data using both human evaluation and objective similarity scores. we take advantage of the fact that executing the generated code can serve as objective evaluation and define three robustness evaluation metrics that aggregate a model's correctness across randomized transformations and transformation types. these metrics quantify a model's accuracy on perturbed prompts, its relative accuracy drop from original prompts, as well as its general instability. we summarize our contributions below: ## methodology in this section, we introduce the transformations to perturb prompts on both text (docstring) and code. we then propose new robust evaluation metrics. ## conclusion in this paper, we propose recode, a comprehensive robustness evaluation benchmark for code generation models. we collect and customize over 30 natural transformations under categories of docstrings, function names, code syntax, and code format perturbations. these transformations are carefully selected and designed to be natural in practice and preserve the semantic meaning after perturbations. we further propose general worst-case robustness metrics to give a unified overview of the model robustness performance. we empirically demonstrate our recode benchmark on popular models including codegen, incoder, and gpt-j using humaneval and mbpp datasets and function completion tasks derived from them. with human evaluation, over 90% of our perturbed data are confirmed to preserve the original semantic meaning; sentence similarity and codebleu scores additionally support the quality of perturbations in recode.