论文标题

在神经代码生成中,好的方法名称有多重要?模型鲁棒性的观点

How Important are Good Method Names in Neural Code Generation? A Model Robustness Perspective

论文作者

Yang, Guang, Zhou, Yu, Yang, Wenhua, Yue, Tao, Chen, Xiang, Chen, Taolue

论文摘要

预先训练的代码生成模型(PCGM)已被广泛应用于神经代码生成中,该模型可以从自然语言的功能描述中生成可执行的代码,这可能与签名一起生成。尽管PCGM的性能大大提高,但尚未对方法名称在神经代码生成中的作用进行彻底研究。在本文中,我们研究并展示了从方法名称中受益的潜力,从模型稳健性的角度来看,从而增强了PCGM的性能。具体而言,我们提出了一种新型方法,名为Radar(神经代码生成器鲁棒)。雷达由两个组成部分组成:雷达攻击和雷达防御。前者通过生成对抗方法名称作为输入的一部分来攻击PCGM,该名称具有类似于原始输入的语义和视觉效果,但可能会欺骗PCGM生成完全无关的代码片段。作为与此类攻击的对策,Radar-Defense从功能描述中综合了一个新方法名称,并将其提供给PCGM。评估结果表明,在三个最先进的PCGM(即CodeGPT,PLBART和CODET5)中,雷达攻击可以将生成的代码的代码减少19.72%,至38.74%,并在微型代码生成任务中减少,并将生成的代码的PASS@1置于32.28%至44.42%的PCG中,并将其减少为44.42%的PCG,并将其降低。在零击代码生成任务中的codet5+)。此外,雷达防御能够使用合成的方法名称恢复PCGM的性能。这些结果强调了良好方法名称在神经代码生成中的重要性,并暗示了研究软件工程中模型鲁棒性的好处。

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.

扫码加入交流群

加入微信交流群

微信交流群二维码

扫码加入学术交流群,获取更多资源