[论文解读] ReCode: Robustness Evaluation of Code Generation Models
本文提出了 ReCode,这是首个用于评估代码生成模型鲁棒性的综合性基准。它应用了三十余种自然的、语义保持的扰动——涵盖文档字符串、函数名、语法和格式——以评估模型在现实输入变化下的稳定性,结果表明,如 CodeGen 这类模型在语法和格式扰动下表现出优于 InCoder 或 GPT-J 的鲁棒性。
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.
研究动机与目标
- 为解决在真实场景中缺乏全面、定量的代码生成模型鲁棒性评估基准的问题。
- 识别并表征由提示中微小但自然的扰动(如改写文档字符串或重命名变量)引起的模型脆弱性,这些扰动不改变语义含义。
- 开发一个可泛化的评估框架,利用代码执行作为客观评估手段,生成反映真实世界可靠性的鲁棒性度量。
- 提供一个标准化、可扩展的基准,用于在多样化的扰动类型和数据集(如 HumanEval 和 MBPP)上比较最先进代码生成模型。
提出的方法
- 设计并应用三十余种自然的、语义保持的转换,覆盖代码的四个方面:文档字符串(例如,回译、改写)、函数/变量名(例如,驼峰命名重命名、同义词替换)、代码语法(例如,语句重排、操作符更改)以及代码格式(例如,缩进、换行)。
- 使用人工评估和语义相似度分数(例如,BERTScore)验证超过90%的扰动提示保留了原始语义并保持自然性。
- 定义三种鲁棒性度量:Robust Pass @k(在扰动提示上的准确率)、Robust Drop @k(与标准提示相比的准确率相对下降)、Robust Relative @k(通用不稳定性度量),以代码执行结果作为真实标签。
- 在 HumanEval 和 MBPP 上对 SOTA 模型(CodeGen、InCoder、GPT-J)应用该基准,使用 top-p 采样,温度为 0.2,n=100 以获得稳定的估计。
- 使用生成代码的执行作为客观评估手段,确保正确性通过功能行为而非表面字符串匹配来衡量。
- 在多种扰动类型和模型变体(包括不同尺寸和架构,如单任务与多任务,2B 到 16B 参数)上评估鲁棒性。
实验结果
研究问题
- RQ1在提示中存在自然的、语义保持的扰动时,最先进代码生成模型的表现如何?
- RQ2在文档字符串、命名、语法或格式扰动中,哪类扰动对模型鲁棒性的影响最严重?
- RQ3模型架构和预训练数据多样性如何影响模型对提示变化的鲁棒性?
- RQ4Robust Pass、Robust Drop 和 Robust Relative 等鲁棒性度量如何与不同数据集上的模型性能和稳定性相关联?
- RQ5在 HumanEval 和 MBPP 等不同代码生成基准上,鲁棒性表现是否一致?
主要发现
- CodeGen 模型在所有扰动类型下均表现出显著优于 InCoder 和 GPT-J 的鲁棒性,在标准条件下,CodeGen-16B-mono 在 HumanEval 上的 Robust Pass @1 达到 0.306。
- 语法扰动导致性能下降最大,CodeGen-16B-mono 的 Robust Drop @1 高达 60.87%,表明对结构变化高度敏感。
- 格式扰动,尤其是换行符和制表符缩进的改变,导致显著的鲁棒性下降:在 MBPP 上,格式变化的 Robust Drop @1 达到 39.13%,而代码后换行扰动的 Robust Drop @1 高达 45.42%。
- 模型在 HumanEval 上的鲁棒性高于在 MBPP 上,MBPP 上的 Robust Drop @1 高达 45.42%(InCoder-6B),而 HumanEval 上类似扰动下的 Robust Drop @1 仅为 16.67%(CodeGen-2B-mono)。
- Robust Drop 在不同采样温度和 n 值下保持稳定,而 Robust Pass 和 Robust Relative 随 k 增加而上升,表明在不同推理设置下度量行为一致。
- 人工评估确认超过 90% 的扰动提示保留了语义含义,验证了 ReCode 基准的自然性和有效性。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。