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

MixCode: Enhancing Code Classification by Mixup-Based Data Augmentation

Zeming Dong, Qiang Hu, Yuejun Guo, Maxime Cordy, Mike Papadakis, Zhenya Zhang, Yves Le Traon, Jianjun Zhao

Abstract

Deep learning models for source code analysis require massive amounts of labeled data, which is notoriously expensive and time-consuming to produce. This paper introduces MIXCODE, a novel data augmentation framework that adapts the "Mixup" technique from computer vision to source code by linearly mixing original code representations with refactored versions. This approach significantly boosts both the accuracy and robustness of code classification models without requiring any additional human labeling.

Introduction

Deep Neural Networks (DNNs) are increasingly being used to automate software engineering tasks like bug detection and code classification. However, DNNs are data-hungry. While raw source code is abundant on platforms like GitHub, labeled source code is scarce because annotating it requires sophisticated domain expertise.

To mitigate this, researchers use data augmentation—generating synthetic training data from existing samples. In the context of source code, this typically involves applying label-preserving transformations such as renaming variables or adding dead code. However, simply adding these refactored examples to the training set often yields only marginal performance improvements and fails to significantly enhance a model's generalization (robustness) to unseen data. MIXCODE seeks a more effective way to leverage augmented code data.

The MIXCODE Framework

The authors propose MIXCODE, which adapts the Mixup data augmentation strategy for the programming language domain. Originally designed for image classification, Mixup works by taking two training examples and creating a new, synthetic example by linearly interpolating both their input features and their labels.

The MIXCODE workflow: Original code is refactored, then both versions are converted to vector representations and mixed to create new training data.

As shown in the workflow above, MIXCODE operates in two main stages:

  1. Code Refactoring: For a given piece of original code, the system randomly applies one of 18 label-preserving refactoring methods (e.g., API renaming, adding unused variables, duplicating statements) to create a "transformed" version.
  2. Mixup: The system takes the vector representation of the original code and the vector representation of the transformed code. It then mathematically mixes them together based on a weight parameter ($\lambda$, drawn from a Beta distribution). It performs the same interpolation for their labels.

Representation Mixing

Instead of training on just the original or just the refactored code, the DNN is trained on these newly synthesized, "mixed" continuous representations. This process allows the model to explore the space between discrete code samples.

An example of MIXCODE applying linear interpolation to the tensor representations of two different programs to create a mixed data point.

The figure above illustrates how the tensors for Program A and Program B are combined. In practice, the authors found that mixing the original code with its transformed counterpart consistently yielded the best results, effectively bridging the gap between the original data distribution and the augmented distribution.

Experimental Evaluation

The authors evaluated MIXCODE across two programming languages (Java and Python) and two downstream tasks (problem classification and bug detection) using four datasets: JAVA250, Python800, CodRep1, and Refactory. The framework was tested across seven different model architectures, including CNNs, Graph Neural Networks (GCN, GAT), and large pre-trained models like CodeBERT and GraphCodeBERT.

Key Results

  • Accuracy: MIXCODE outperformed the basic data augmentation baseline (simply adding refactored code to the training set) by up to 6.24% in test accuracy.
  • Robustness: When evaluated on a test set of unseen, transformed code, MIXCODE achieved a massive boost in robustness—improving performance by up to 26.06% (and 5.58% on average) compared to the baseline.
  • Convergence: Models trained with MIXCODE converged faster during training than those trained with standard methods.

Discussion and Insights

A critical finding of this research is the sensitivity of code to heavy mixing. In image classification, a 50/50 mix ($\alpha=0.5$) often provides useful signals. However, in the code domain, mixing representations too heavily causes the data to lose semantic meaning. The authors determined that a very small mixing parameter ($\alpha \in [0.05, 0.1]$) is required to prevent the mixed code vectors from becoming useless noise.

Furthermore, the study highlights an "Accuracy vs. Robustness" trade-off. Training on data generated by a single refactoring method might yield high test accuracy on standard data, but robustness to other unseen transformations plummets. Diversity in refactoring methods is crucial for real-world generalization.

Conclusion

MIXCODE demonstrates that adapting interpolation-based augmentation to the discrete world of source code is not only possible but highly effective. By mixing original and refactored representations, the framework provides a significant boost to model performance and robustness without the need for additional manual labeling. Future work may explore adaptive refactoring selection and mixing at different layers of the neural network.

Summary updated

BibTeX
@inproceedings{dong2023mixcode,
  author = {Zeming Dong and Qiang Hu and Yuejun Guo and Maxime Cordy and Mike Papadakis and Zhenya Zhang and Yves Le Traon and Jianjun Zhao},
  title = {{MixCode: Enhancing Code Classification by Mixup-Based Data Augmentation}},
  booktitle = {SANER},
  year = {2023},
  doi = {10.1109/saner56733.2023.00043},
}
Figure