CODECLEANER: Elevating Standards with A Robust Data Contamination Mitigation Toolkit

Jialun Cao, Songqiang Chen, Wuqi Zhang, Hau Ching Lo, Shing-Chi CheungarXiv 2024 · DOI

Abstract

Data contamination—the inclusion of evaluation benchmarks within training corpora—presents a significant challenge to the integrity of Code Language Models (CLMs). This paper presents CODECLEANER, an open-source toolkit designed to mitigate contamination through automated, semantics-preserving code refactoring. By systematically altering code structure, naming conventions, and stylistic elements, CODECLEANER disrupts memorized token sequences. Our evaluation demonstrates that CODECLEANER can reduce median data overlap from 87% to 22%, providing a more accurate benchmark for assessing the genuine logical reasoning of programming models.

Introduction

The rapid advancement of Large Language Models (LLMs) for code generation, such as GPT-4 and StarCoder, is largely attributed to training on massive public datasets like GitHub. However, this breadth introduces "data contamination," where models inadvertently memorize benchmark solutions. This phenomenon artificially inflates performance metrics, creating a "mirage" of capability that often fails when applied to novel, proprietary codebases. For industrial stakeholders, this discrepancy represents a major hurdle in deploying reliable AI-assisted software engineering tools.

Methodology: The CODECLEANER Framework

To address this, we propose automated code refactoring as a lightweight mitigation strategy. The objective is to transform the code's syntax and style while maintaining its original functional semantics. CODECLEANER implements 11 refactoring operators categorized into three distinct levels:

  1. Syntactic Operators: These modify the control flow and logical structure (e.g., flipping if-else branches or transforming for loops into while loops).
  2. Semantic Operators: These introduce or perturb non-functional information, such as "Identifier Renaming" or adding performance decorators.
  3. Code Style Operators: These focus on normalizing stylistic choices, such as whitespace or naming conventions (e.g., snake_case vs. camelCase).
Figure 1: Taxonomy of CODECLEANER refactoring operators across syntactic, semantic, and stylistic levels.

As illustrated in Figure 1, these operators target different granularities, from method-level logic to cross-class inheritance structures. For instance, a loop transformation (shown in Figure 2) forces the model to process the logic through a different syntactic template, breaking the reliance on long-range token memorization.

Figure 2: An example of a Loop Transformation (for to while) which preserves semantics while significantly altering the token sequence.

Experimental Design

The effectiveness of CODECLEANER was evaluated using The Stack v1.2 (2.9 TB) as the reference training corpus. The study utilized a diverse set of evaluation data, including 384 Python methods, 324 Python classes from major libraries (e.g., Scikit-learn, Pandas), and 384 Java classes to test cross-language generalizability. Metrics included N-gram overlap (data-wise) and perplexity (model-wise).

Results and Analysis

The application of the full CODECLEANER suite resulted in a dramatic reduction in data overlap, dropping from a median of 87% to 22%—a 65% total reduction.

Key Findings:

  • The Power of Renaming: Semantic operators, particularly Identifier Renaming, proved most effective at disrupting model familiarity. Syntactic changes alone are often insufficient to break the deep memorization patterns of state-of-the-art CLMs.
  • Language Disparities: Contamination levels in Java were found to be significantly higher (~98%) than in Python (~92%), suggesting that Java-based benchmarks may be particularly prone to overestimation.
  • Token Disruption: The primary mechanism for success is the disruption of consecutive tokens. By injecting small but functional changes, CODECLEANER forces the model to "re-read" the logic rather than "recite" it.

Conclusion

CODECLEANER provides a robust, automated path toward more honest evaluation of code models. By reducing the reliance on memorized patterns, it allows researchers and developers to distinguish between true algorithmic understanding and simple data retrieval. The toolkit is open-sourced to encourage the community to adopt cleaner benchmarking standards.

Toolkit available at: https://github.com/ArabelaTso/CodeCleaner-v1/

Summary updated

BibTeX
@misc{cao2024codecleaner,
  author = {Jialun Cao and Songqiang Chen and Wuqi Zhang and Hau Ching Lo and Shing-Chi Cheung},
  title = {{CODECLEANER: Elevating Standards with A Robust Data Contamination Mitigation Toolkit}},
  year = {2024},
  eprint = {2411.10842},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2411.10842},
}
Figure