Bridging Pre-trained Models and Downstream Tasks for Source Code Understanding

Deze Wang, Zhouyang Jia, Shanshan Li, Yue Yu, Yun Xiong, Wei Dong, Xiangke Liao

Abstract

Large-scale pre-trained models (PTMs) have significantly advanced natural language processing and software engineering tasks. However, applying these models to source code understanding remains challenging due to semantic mismatches and overfitting on small datasets. This paper introduces DACL (Data Augmentation and Curriculum Learning), a lightweight fine-tuning approach that combines semantic-preserving data augmentation with curriculum learning. By training models on increasingly complex code transformations, DACL enables general-purpose models like RoBERTa to outperform specialized code models. Experimental results on the CodeXGLUE benchmark demonstrate substantial improvements in algorithm classification, code search, and clone detection.

Introduction

The emergence of pre-trained models (PTMs) such as BERT and RoBERTa has transformed the landscape of code understanding. Specialized variants like CodeBERT and GraphCodeBERT further tailor these architectures to software engineering. Despite their success, two primary issues persist:

  1. Semantic Mismatch: Many models treat code as text, failing to recognize that syntactically different snippets (e.g., a for loop vs. a while loop) can be semantically identical.
  2. Overfitting and Fragility: Fine-tuning high-parameter models on small downstream datasets often leads to overfitting, making them sensitive to minor syntactic variations.

The proposed DACL framework addresses these gaps by bridging general pre-training with specific code tasks without the prohibitive cost of training new models from scratch.

Methodology: The DACL Framework

The DACL approach integrates three core components: Semantic-Preserving Data Augmentation, Curriculum Learning, and Test-Time Augmentation.

The DACL framework overview, illustrating the pipeline from training set augmentation to test-time evaluation.

Semantic-Preserving Data Augmentation (DA)

To teach models the underlying logic of code rather than just its surface syntax, the authors employ a source-to-source compiler. This tool generates multiple versions of the same code snippet by applying transformations that preserve original semantics. These include control flow changes (e.g., converting for loops to while loops) and API or declaration swaps.

Example of sequential semantic-preserving transformations applied to a C++ code snippet.

Curriculum Learning (CL)

Rather than training on all augmented data simultaneously, DACL uses a "curriculum" to guide the model from simple to complex samples. This prevents the model from being overwhelmed by noisy, highly transformed data early in training. Difficulty is determined either by the number of transformations applied or through a class-based "leave-one-out" strategy.

Test-Time Augmentation (TTA)

During the evaluation phase, the model generates predictions for the original code and several transformed variants. By averaging these predictions, the final output becomes significantly more robust to syntactic noise.

Experimental Evaluation

The DACL framework was evaluated using three benchmarks from the CodeXGLUE suite: POJ104 (algorithm classification), BigCloneBench (clone detection), and CodeSearchNet (code search).

Key Results

  • Performance Gains: DACL improved Mean Average Precision (MAP) in algorithm classification by 10.24% over previous state-of-the-art methods. In code search, it achieved a record Mean Reciprocal Rank (MRR) of 0.720.
  • Data Efficiency: In clone detection tasks, CodeBERT trained with DACL on only 10% of the dataset outperformed a standard CodeBERT model trained on 100% of the data.
  • Model Versatility: A surprising finding was that RoBERTa, originally trained only on natural language, outperformed the code-specific CodeBERT when fine-tuned using the DACL approach.

Discussion and Insights

The success of DACL highlights that transformed code can serve as effective "adversarial examples," forcing the model to learn features invariant to syntax. The curriculum learning component is vital; randomizing the order of augmented data resulted in lower performance, confirming that building a stable foundation with "easy" samples is necessary before introducing complexity.

Conclusion and Future Work

While DACL significantly improves understanding tasks, its application to generative tasks remains a challenge, as Test-Time Augmentation is not easily adaptable to sequence generation. Future research may explore combining DACL with prompt-based learning to further enhance the capabilities of generative models in software engineering.

Summary updated

BibTeX
@inproceedings{wang2022bridging,
  author = {Deze Wang and Zhouyang Jia and Shanshan Li and Yue Yu and Yun Xiong and Wei Dong and Xiangke Liao},
  title = {{Bridging Pre-trained Models and Downstream Tasks for Source Code Understanding}},
  booktitle = {ICSE},
  year = {2022},
  doi = {10.1145/3510003.3510062},
}
Figure