TL;DR
SrDetection is a novel, self-referential framework designed to detect data leakage in Code Large Language Models (Code LLMs) without requiring access to proprietary training corpora or relying on brittle, manually tuned thresholds. By generating semantically equivalent variants of a code snippet and comparing the model's behavior on the original versus the variants, it accurately identifies memorized data, improving leakage detection by up to 21.5 F1 points over traditional baselines.
What Problem Does This Paper Address?
When evaluating Code LLMs on public benchmarks, there is a high risk of data leakage—meaning the model was exposed to the benchmark data during its massive pre-training phase. This exposure artificially inflates performance metrics, making it difficult to discern whether a model possesses genuine reasoning capabilities or is simply reciting memorized code.
Existing data leakage detectors suffer from severe practical limitations:
- Corpus-dependent methods require access to the model's exact pre-training data, which is almost always proprietary and undisclosed.
- Time-based heuristics assume that code published after a certain date couldn't possibly be leaked, ignoring the pervasive nature of code reuse, inheritance, and repository forking.
- Confidence-based methods (like tracking Perplexity) require external reference datasets to calibrate a global decision threshold. However, thresholds calibrated on natural language transfer poorly to the highly structured regularities of source code.
Methods
SrDetection bypasses the need for external anchors or global thresholds by using a self-referential approach. The core hypothesis is simple: if a model has memorized a specific code snippet, it will find the exact original surface form disproportionately "easier" to process than semantically identical variations.
The framework operates in two main stages:
- Code Transformation Module: An auxiliary LLM generates a contrastive set of semantically equivalent variants ($V$) from the original code sample ($x_0$). It applies three localized, functionality-preserving edits:
- Function Name Renaming ($\tau_f$): Swapping function names with synonyms (e.g.,
solvetocompute). - Variable Name Renaming ($\tau_v$): Systematically altering variable identifiers throughout the scope.
- Test Case Transformation ($\tau_t$): Proposing new, structurally similar test inputs and validating them via execution to ensure semantic fidelity.
- Leakage Decision Module: SrDetection evaluates the target model's behavior across the original code and its variants under two distinct access settings:
- Gray-box Setting (Access to Logits): The framework calculates the Perplexity (PPL) for all variants. If the original sample $x_0$ yields the absolute lowest perplexity in the set, it is flagged as leaked.
- Black-box Setting (Access to Outputs Only): The model is prompted to complete code suffixes from given prefixes. The framework measures the N-gram Overlap (NGO) between the generated and ground-truth suffixes. If the original sample achieves the highest overlap, it indicates leakage.
Datasets
- Controlled Testbed: The authors built a controlled evaluation environment using the APPS dataset. Samples were filtered to remove pre-existing exposure, split 1:1 into training and test sets, and then explicitly leaked into target models (Qwen2.5-7B and LLaMA-3.1-8B) via continued pre-training mixed with general web data from The Pile.
- Real-World Benchmarks: To measure real-world contamination across 15 mainstream Code LLMs, the authors evaluated four popular benchmarks: APPS, HumanEval, MBPP, and BigCodeBench.
Key Insights and Ideas
- The Fragility of Memorization: Code LLM memorization is highly sensitive to exact lexical and syntactic surface forms. Even minor refactoring—like changing a variable name—breaks the "memorization spell," causing the model's perplexity to spike. SrDetection exploits this exact behavioral delta.
- Intra-Sample Relativity over Global Thresholds: Instead of trying to find a magic absolute perplexity score to separate leaked text from clean text across different models, looking at the relative ranking within a single code sample's family provides a remarkably stable and robust signal.
Key Results
- Performance Leap: In controlled testbed experiments, SrDetection consistently outperformed state-of-the-art baselines, yielding an average F1-score improvement of 21.52 points in gray-box settings and 14.46 points in black-box settings.
- Widespread Real-World Leakage: When applied to 15 popular open-source models, SrDetection uncovered massive benchmark contamination. Notably, BigCodeBench demonstrated severe leakage rates across almost all tested models, with some Qwen and LLaMA variants exhibiting leakage rates exceeding 90%. Conversely, MBPP remained largely clean across the board.
Limitations and Future Work
The authors note that SrDetection's effectiveness heavily relies on the diversity and quality of the generated code variants. If the transformations are too minor, the contrastive signal weakens. Additionally, in black-box settings, very large or heavily instruction-tuned models can sometimes mask subtle output discrepancies, making detection more challenging.
Future work will focus on expanding the framework to support broader code modalities and developing adaptive transformation strategies that better mimic real-world code variability.
Summary updated