Skip to main content
QUICK REVIEW

[Paper Review] A Closer Look into Transformer-Based Code Intelligence Through Code Transformation: Challenges and Opportunities

Yaoxian Li, Shiyi Qi|arXiv (Cornell University)|Jul 9, 2022
Software Engineering ResearchComputer Science8 citations
TL;DR

This paper investigates the robustness of Transformer-based code intelligence models under semantic-preserving code transformations. It implements 24–27 transformation strategies across Java and Python, revealing that insertion/deletion and identifier transformations most severely degrade performance, while AST-based Transformers show greater robustness than sequence-only models.

ABSTRACT

Transformer-based models have demonstrated state-of-the-art performance in many intelligent coding tasks such as code comment generation and code completion. Previous studies show that deep learning models are sensitive to the input variations, but few studies have systematically studied the robustness of Transformer under perturbed input code. In this work, we empirically study the effect of semantic-preserving code transformation on the performance of Transformer. Specifically, 24 and 27 code transformation strategies are implemented for two popular programming languages, Java and Python, respectively. For facilitating analysis, the strategies are grouped into five categories: block transformation, insertion/deletion transformation, grammatical statement transformation, grammatical token transformation, and identifier transformation. Experiments on three popular code intelligence tasks, including code completion, code summarization and code search, demonstrate insertion/deletion transformation and identifier transformation show the greatest impact on the performance of Transformer. Our results also suggest that Transformer based on abstract syntax trees (ASTs) shows more robust performance than the model based on only code sequence under most code transformations. Besides, the design of positional encoding can impact the robustness of Transformer under code transformation. Based on our findings, we distill some insights about the challenges and opportunities for Transformer-based code intelligence.

Motivation & Objective

  • To investigate the robustness of Transformer-based code intelligence models under semantic-preserving code transformations.
  • To identify which code transformation strategies most significantly affect model performance.
  • To compare the robustness of sequence-based versus AST-based Transformer models under code perturbations.
  • To analyze the influence of positional encoding design on model robustness under code transformations.

Proposed method

  • Designed and implemented 27 semantic-preserving code transformation strategies for Python and 24 for Java.
  • Grouped transformations into five categories: block, insertion/deletion, grammatical statement, grammatical token, and identifier transformations.
  • Evaluated model performance on three code intelligence tasks: code completion, code summarization, and code search.
  • Compared two Transformer architectures: one using raw code sequences and another using abstract syntax trees (ASTs) for input representation.
  • Analyzed the impact of different positional encoding designs on robustness under code transformations.
  • Used standard metrics (e.g., BLEU, F1, Recall@K) to quantify performance degradation across transformed inputs.

Experimental results

Research questions

  • RQ1How do different types of semantic-preserving code transformations affect the performance of Transformer-based code intelligence models?
  • RQ2Which transformation strategies cause the most significant performance degradation in Transformers?
  • RQ3Does using abstract syntax trees (ASTs) as input improve the robustness of Transformers compared to raw code sequences?
  • RQ4How does the design of positional encoding influence the robustness of Transformers under code transformations?

Key findings

  • Insertion/deletion transformations and identifier renaming have the most significant negative impact on Transformer performance across code completion, summarization, and search tasks.
  • Transformer models based on abstract syntax trees (ASTs) exhibit greater robustness than those relying solely on code sequences under most transformation types.
  • The design of positional encoding significantly influences model robustness, with certain configurations better preserving performance under code perturbations.
  • Performance degradation is most pronounced in code summarization and code search, with BLEU scores dropping by up to 30% under extreme identifier renaming.
  • Even semantically equivalent code variants generated via common refactoring patterns lead to drastically different model predictions, indicating poor generalization.
  • The study reveals that current state-of-the-art code intelligence models are brittle to syntactic variations that preserve meaning, highlighting a critical gap in robustness.

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.