Abstract
Deep learning models for source code tasks are often limited by the availability of high-quality annotated data. While traditional data augmentation in this domain relies on complex, syntax-preserving refactoring, this study investigates the efficacy of text-oriented augmentation techniques borrowed from Natural Language Processing (NLP). We evaluate 25 methods—including paraphrasing, noising, and sampling-based mixup—across 4,560 models and multiple benchmarks. Our findings reveal that text-oriented methods, even those that disrupt code syntax, frequently outperform traditional refactoring. Notably, SenMixup provides significant accuracy gains, particularly in low-resource scenarios, suggesting that the "naturalness" of code allows models to learn robust features from noisy text-level perturbations.
Introduction
The advancement of deep learning has significantly impacted software engineering, enabling automated bug detection, code generation, and clone detection. However, these models are notoriously data-hungry, requiring vast amounts of annotated source code. In domains like computer vision, data augmentation (e.g., flipping or rotating images) is a standard practice to expand training sets. In contrast, source code learning (ML4Code) has primarily relied on complex, semantics-preserving refactoring techniques, such as variable renaming.
This paper explores whether simpler, more aggressive text-oriented augmentation methods from NLP can be effectively applied to source code. We investigate if the rigid syntax of programming languages is a barrier or if models can benefit from "noisy" data that may not even compile.
Methodology
The researchers evaluated 25 data augmentation methods, broadly categorized into code-level and text-level approaches. These were compared against a baseline of no augmentation to determine their relative effectiveness across different tasks.
Augmentation Categories
- Code-level (Refactoring): 18 traditional methods such as variable renaming and dead code insertion that preserve the program's semantics.
- Text-level (NLP-oriented):
- Paraphrasing: Back-translation (BT) of code statements.
- Noising-based: Token-level edits like Synonym Replacement (SR), Random Insertion (RI), Random Swap (RS), and Random Deletion (RD).
- Sampling-based (Mixup): Advanced techniques like WordMixup and SenMixup that linearly interpolate embeddings of different code snippets.
Experimental Setup
The study involved training 4,560 models across various benchmarks, including problem classification (Java250, Python800), bug detection (CodRep1, Refactory), authorship attribution (GCJ), and clone detection (BigCloneBench). To test the limits of these methods, the authors also introduced low-resource datasets for Ruby and Go, simulating environments where data is extremely scarce.
Key Insights
The Resilience of Code Models to Syntax Errors
A pivotal finding is that models are surprisingly robust to syntactic errors introduced by text-oriented methods. Techniques like Random Swap (RS) and Random Deletion (RD), which often break code syntax, proved highly effective. This supports the "naturalness of source code" hypothesis, suggesting that models learn from the underlying statistical patterns rather than just formal grammar.
The Power of Mixup and NLP Methods
SenMixup emerged as a top performer, enhancing accuracy by up to 8.74%. By smoothing decision boundaries, it effectively prevents overfitting. Furthermore, simple text-based noise often outperformed complex, semantics-preserving refactoring, challenging the assumption that augmentation must maintain code validity to be useful.
Results
- Low-Resource Performance: Data augmentation is most impactful when data is scarce. For instance, with only 1% of training data, SenMixup improved CodeBERT's accuracy by 12.92%.
- Robustness: Random Deletion (RD) was particularly effective at improving adversarial robustness, reducing attack success rates by 5.67%.
- Cross-Language Versatility: Text-oriented methods consistently outperformed traditional refactoring across different programming languages, including low-resource ones like Ruby and Go.
Conclusion
This empirical study demonstrates that text-oriented data augmentation is a powerful and versatile tool for source code learning. While pre-trained models like CodeBERT see slightly smaller gains, the benefits for from-scratch models and low-resource scenarios are substantial. Future work should explore embedding-level augmentations and applications to generative tasks.
Summary updated