NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Data Augmentation Approaches for Source Code Models: A Survey

Terry Yue Zhuo, Zhou Yang, Zhensu Sun, Yufei Wang, Li Li, Xiaoning Du, Zhenchang Xing, David Lo · DOI

Abstract

Deep learning models have become integral to modern software engineering, yet they remain data-hungry and sensitive to the quality of training sets. This paper provides the first comprehensive survey of data augmentation (DA) techniques specifically designed for source code. By categorizing research into rule-based, model-based, and interpolation-based methods, the survey explains how to increase training diversity while respecting the strict syntactic and functional requirements of computer programs.

The Challenge of Code Augmentation

Deep learning models are increasingly deployed for critical tasks such as code completion, defect detection, and summarization. While Natural Language Processing (NLP) has long benefited from simple data augmentation tricks like synonym swapping, applying these directly to source code is fraught with risk.

Source code possesses a "dual-modality": it serves as a formal language for machines and a natural-ish language for humans (via comments and identifiers). Unlike natural language, code is governed by strict context-free grammars where a single character change can lead to compilation errors. Furthermore, code has long-range dependencies; a variable renamed in one scope might break references across multiple files. This survey addresses how to systematically expand code datasets while preserving original logic and syntax.

Taxonomy of Data Augmentation Methods

The authors categorize DA for source code into three primary pillars:

1. Rule-based Techniques

These methods use predefined rules to transform code snippets. Most leverage Abstract Syntax Trees (ASTs) to ensure that the resulting transformations remain syntactically valid. Common examples include:

  • Identifier Renaming: Replacing variable names (e.g., x to counter) consistently throughout a scope.
  • Statement Permutation: Swapping independent lines of code that do not have data dependencies.
  • Loop Exchange: Converting a for loop into a functionally equivalent while loop.
Common rule-based data augmentation techniques including variable renaming, statement permutation, and loop exchange.

2. Model-based Techniques

These techniques employ secondary models to generate new training data.

  • Back-translation: A snippet is translated into a natural language summary and then back into a different programming language or a different variation of the original language.
  • Generative Models: GANs or BERT-style models are used to replace non-keyword tokens or generate semantically identical but syntactically distinct code snippets.

3. Example Interpolation

Inspired by the "Mixup" technique in computer vision, methods like MixCode blend the vector representations (embeddings) of two different code snippets. This creates "synthetic" training examples that exist in the mathematical space between real samples, helping the model generalize better.

The survey identifies a massive surge in academic and industrial interest in this field. As shown in the figure below, the number of publications dedicated to code DA has grown exponentially in recent years.

The number of publications on data augmentation for source code has seen a significant increase from 2019 to 2023.

Researchers typically evaluate these methods on standard benchmarks such as CodeSearchNet, CodeXGLUE, and BigCloneBench. The survey notes that DA is particularly effective for "low-resource" languages like Rust or Ruby, where human-labeled data is significantly scarcer than for Python or Java.

Key Insights: Robustness and Synergy

A major finding of the survey is that DA is not just a tool for expanding small datasets; it is a primary defense against adversarial attacks. By training on "obfuscated" code—code that is intentionally difficult to read but functionally identical—models become more syntactically robust.

Furthermore, the authors highlight the synergy between DA and Contrastive Learning. In this paradigm, a model learns that a piece of code and its augmented version should have similar internal representations, while two unrelated programs should be distinct. The survey also finds that "method stacking" (combining different DA types like renaming plus back-translation) often yields superior results compared to any single method.

Future Directions and Limitations

Despite the progress, several gaps remain:

  • Lack of Unification: There is no standard library for code DA (akin to torchvision), leading to fragmented implementations that are difficult to compare.
  • Project-Level Context: Most current DA occurs at the function level. There is a critical need for techniques that understand inter-dependencies across an entire software project.
  • Theoretical Understanding: While empirical results are strong, the mathematical "why" behind which transformations provide the most informative signals remains under-explored.
  • Social Bias Mitigation: DA could potentially be used to "de-bias" datasets by systematically swapping demographic terms in docstrings or comments, addressing inherited biases in large-scale code models.

Summary updated

BibTeX
@misc{zhuo2023data,
  author = {Terry Yue Zhuo and Zhou Yang and Zhensu Sun and Yufei Wang and Li Li and Xiaoning Du and Zhenchang Xing and David Lo},
  title = {{Data Augmentation Approaches for Source Code Models: A Survey}},
  year = {2023},
  eprint = {2305.19915},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2305.19915},
}
Figure