Skip to main content
QUICK REVIEW

[论文解读] How Important are Good Method Names in Neural Code Generation? A Model Robustness Perspective

Guang Yang, Yu Zhou|arXiv (Cornell University)|Nov 29, 2022
Software Engineering Research被引用 5
一句话总结

本文提出 RADAR 框架,通过对抗性攻击与防御机制提升预训练代码生成模型(PCGMs)的函数名鲁棒性。RADAR-Attack 生成语义相似但具有误导性的函数名,使 CodeBLEU 最多降低 38.74%,Pass@1 最多降低 44.42%;而 RADAR-Defense 从功能描述中合成准确的函数名,恢复模型性能,凸显了良好函数名在神经代码生成中的关键作用。

ABSTRACT

Pre-trained code generation models (PCGMs) have been widely applied in neural code generation which can generate executable code from functional descriptions in natural languages, possibly together with signatures. Despite substantial performance improvement of PCGMs, the role of method names in neural code generation has not been thoroughly investigated. In this paper, we study and demonstrate the potential of benefiting from method names to enhance the performance of PCGMs, from a model robustness perspective. Specifically, we propose a novel approach, named RADAR (neuRAl coDe generAtor Robustifier). RADAR consists of two components: RADAR-Attack and RADAR-Defense. The former attacks a PCGM by generating adversarial method names as part of the input, which are semantic and visual similar to the original input, but may trick the PCGM to generate completely unrelated code snippets. As a countermeasure to such attacks, RADAR-Defense synthesizes a new method name from the functional description and supplies it to the PCGM. Evaluation results show that RADAR-Attack can reduce the CodeBLEU of generated code by 19.72% to 38.74% in three state-of-the-art PCGMs (i.e., CodeGPT, PLBART, and CodeT5) in the fine-tuning code generation task, and reduce the Pass@1 of generated code by 32.28% to 44.42% in three state-of-the-art PCGMs (i.e., Replit, CodeGen, and CodeT5+) in the zero-shot code generation task. Moreover, RADAR-Defense is able to reinstate the performance of PCGMs with synthesized method names. These results highlight the importance of good method names in neural code generation and implicate the benefits of studying model robustness in software engineering.

研究动机与目标

  • 从模型鲁棒性的角度探究函数名在神经代码生成中的作用。
  • 证明不良或对抗性函数名会严重降低 PCGM 的性能。
  • 开发一种防御机制,通过合成准确的函数名来恢复模型鲁棒性。
  • 评估函数名对微调和零样本代码生成任务的影响。
  • 提供实证证据表明,函数名质量是 PCGM 可靠性与性能的关键因素。

提出的方法

  • RADAR 由两部分组成:RADAR-Attack 和 RADAR-Defense。
  • RADAR-Attack 生成在语义和视觉上与原始函数名相似但具有误导性的函数名,使 PCGM 生成错误代码。
  • RADAR-Defense 从功能描述中合成新的、准确的函数名,以对抗对抗性输入。
  • 该方法使用预训练模型生成并评估函数名,利用功能描述提升鲁棒性。
  • 该框架在三种最先进的 PCGM 上进行评估,涵盖微调(CodeGPT、PLBART、CodeT5)和零样本(Replit、CodeGen、CodeT5+)设置。
  • 评估使用 CodeBLEU 衡量微调任务性能,使用 Pass@1 衡量零样本任务性能,以测量性能下降与恢复情况。

实验结果

研究问题

  • RQ1对抗性函数名如何影响预训练代码生成模型的性能?
  • RQ2函数名在多大程度上影响神经代码生成模型的鲁棒性?
  • RQ3合成的函数名能否有效恢复 PCGM 在对抗性条件下的性能?
  • RQ4不同 PCGM 在微调和零样本设置下对函数名扰动的响应有何差异?
  • RQ5函数名与其他签名组件相比,在代码生成质量中的相对贡献如何?

主要发现

  • RADAR-Attack 在三种微调 PCGM(CodeGPT、PLBART、CodeT5)上使 CodeBLEU 分数降低 19.72% 至 38.74%。
  • RADAR-Attack 在三种零样本 PCGM(Replit、CodeGen、CodeT5+)上使 Pass@1 分数降低 32.28% 至 44.42%。
  • RADAR-Defense 通过从功能描述中生成准确的函数名,成功恢复了 PCGM 的性能。
  • 与基线方法相比,RADAR-Defense 合成的函数名在与人工编写的名称对比时更加准确。
  • 本研究证实,函数名显著影响 PCGM 的鲁棒性与性能,尤其在零样本和微调设置中。
  • 结果凸显了函数名质量的重要性,并表明鲁棒性应成为神经代码生成设计的关键考量。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。