TL;DR
This paper explores whether natural language processing (NLP) data augmentation techniques can boost the performance of source code learning models. The authors find that some text-oriented methods, particularly those that linearly mix embeddings (like SenMixup), improve accuracy, and surprisingly, even methods that slightly break code syntax can be beneficial.
What Problem Does This Paper Address?
Deep neural networks (DNNs) have shown remarkable success in various software engineering tasks, but they heavily rely on large amounts of high-quality training data. Data augmentation, a common technique to artificially increase training data, is widely used in fields like computer vision. However, in source code learning, this practice is largely limited to simple, syntax-preserving methods like code refactoring. This paper addresses the gap by investigating whether more sophisticated text-based data augmentation techniques, commonly used in NLP, can effectively improve source code learning models, even if they slightly deviate from strict code syntax.
Methods
The authors adapt and evaluate 8 data augmentation methods originally designed for NLP. These methods are categorized into three groups:
- Paraphrasing: Back-translation (BT) is used to generate semantically similar but syntactically different code snippets.
- Noising-based methods: These methods introduce small perturbations to the code. The paper tests Synonym Replacement (SR), Random Insertion (RI), Random Swap (RS), and Random Deletion (RD).
- Sampling-based methods: These methods generate new data by linearly mixing latent embeddings. The paper uses WordMixup and SenMixup, inspired by the Mixup technique from computer vision.
The study focuses on code classification tasks and compares these methods against training without augmentation and with traditional code refactoring.
Datasets
The study utilizes several datasets for training and evaluation, covering various programming languages and tasks:
- Most common programming languages:
- Java250 (Java, Problem Classification)
- Python800 (Python, Problem Classification)
- CodRep1 (Java, Bug Detection)
- Refactory (Python, Bug Detection)
- GCJ (Python, Authorship Attribution)
- BigCloneBench (Java, Clone Detection)
- Low-resource programming languages:
- Ruby300 (Ruby, Problem Classification)
- Go250 (Go, Problem Classification)
Key Insights and Ideas
- NLP Augmentation is Promising: Text-oriented data augmentation methods, especially those that linearly mix embeddings (like SenMixup), can significantly improve model accuracy, sometimes outperforming traditional code refactoring.
- Syntax Isn't Always King: Surprisingly, data augmentation methods that slightly break source code syntax (e.g., RS, RD) can still be beneficial for model training, suggesting that code models can be robust to minor syntactic deviations.
- Data Scarcity Amplifies Benefits: The effectiveness of data augmentation is particularly pronounced when training data is scarce, leading to substantial improvements in both accuracy and robustness.
- Pre-trained Models vs. Augmentation: While data augmentation is crucial for training models from scratch, its benefits are less pronounced when using pre-trained models, as pre-training itself offers some form of data augmentation.
Key Results
The paper reports several key findings across different research questions:
- Accuracy: SenMixup showed the best performance in improving accuracy for task-specific models (BagofToken, SeqofToken), outperforming "No Aug" by up to 8.74% and "Refactor" by up to 6.63%. For pre-trained models (CodeBERT, GraphCodeBERT), text-oriented methods like RS and RD were more effective than refactoring, especially when data was limited.
- Robustness: Text-oriented methods showed limited but notable improvements in robustness. RS and RD were highlighted as particularly effective, reducing attack success rates (ASR) by up to 5.67% and 5.10% respectively in certain scenarios.
- Data Volume: When training data was scarce (10%, 5%, 3%, 1%), data augmentation methods, especially SenMixup and RI, significantly improved accuracy and robustness. RI was particularly effective in producing robust models in low-data scenarios.
- Low-Resource Languages: For low-resource languages (Ruby, Go), text-oriented methods like RS, RD, and SenMixup showed significant advantages in robustness improvement, though their impact on accuracy was less pronounced.
Limitations and Future Work
- Statistical Significance: While some methods showed performance gains, statistical analysis indicated that the advantages of existing text-oriented data augmentation methods were not always statistically significant, suggesting room for improvement.
- Pre-trained Models: The benefits of data augmentation were less pronounced for pre-trained models, hinting at the need for more advanced techniques that can complement pre-training.
- Embedding-Level Augmentation: The authors suggest that focusing on data augmentation from the embedding level, rather than just the raw input level, could be a promising research direction.
- Syntax-Breaking Methods: The effectiveness of syntax-breaking methods like Random Deletion and Random Swap for robustness improvement in pre-trained models warrants further investigation.
- Combined Methods: The paper hints that randomly combining different refactoring methods might be more effective than using a single one for robustness.
Summary updated