Skip to main content
QUICK REVIEW

[Paper 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 ResearchComputer Science5 citations
TL;DR

This paper proposes RADAR, a framework that enhances pre-trained code generation models (PCGMs) by improving method name robustness through adversarial attacks and defense mechanisms. RADAR-Attack generates semantically similar but misleading method names that reduce CodeBLEU by up to 38.74% and Pass@1 by up to 44.42%, while RADAR-Defense synthesizes accurate method names from functional descriptions, restoring model performance and demonstrating the critical role of good method names in neural code generation.

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.

Motivation & Objective

  • To investigate the role of method names in neural code generation from a model robustness perspective.
  • To demonstrate that poor or adversarial method names can severely degrade PCGM performance.
  • To develop a defense mechanism that synthesizes accurate method names to restore model robustness.
  • To evaluate the impact of method names on both fine-tuning and zero-shot code generation tasks.
  • To provide empirical evidence that method name quality is a critical factor in PCGM reliability and performance.

Proposed method

  • RADAR consists of two components: RADAR-Attack and RADAR-Defense.
  • RADAR-Attack generates adversarial method names that are semantically and visually similar to the original but mislead the PCGM into generating incorrect code.
  • RADAR-Defense synthesizes new, accurate method names from the functional description to counteract adversarial inputs.
  • The method uses pre-trained models to generate and evaluate method names, leveraging functional descriptions to improve robustness.
  • The framework is evaluated on three state-of-the-art PCGMs in fine-tuning (CodeGPT, PLBART, CodeT5) and zero-shot (Replit, CodeGen, CodeT5+) settings.
  • Evaluation uses CodeBLEU for fine-tuning tasks and Pass@1 for zero-shot tasks to measure performance degradation and recovery.

Experimental results

Research questions

  • RQ1How do adversarial method names affect the performance of pre-trained code generation models?
  • RQ2To what extent do method names influence the robustness of neural code generation models?
  • RQ3Can synthesized method names effectively restore the performance of PCGMs under adversarial conditions?
  • RQ4How do different PCGMs respond to perturbations in method names across fine-tuning and zero-shot settings?
  • RQ5What is the relative contribution of method names versus other signature components in code generation quality?

Key findings

  • RADAR-Attack reduced CodeBLEU scores by 19.72% to 38.74% across three fine-tuning PCGMs (CodeGPT, PLBART, CodeT5).
  • RADAR-Attack reduced Pass@1 scores by 32.28% to 44.42% across three zero-shot PCGMs (Replit, CodeGen, CodeT5+).
  • RADAR-Defense successfully restored the performance of PCGMs by generating accurate method names from functional descriptions.
  • Synthesized method names from RADAR-Defense were more accurate than those from baseline methods when compared to human-written names.
  • The study confirms that method names significantly influence PCGM robustness and performance, especially in zero-shot and fine-tuned settings.
  • The results highlight the importance of method name quality and suggest that robustness should be a key design consideration in neural code generation.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.