Test Set Leakage in LLM Benchmarks: Can We Still Trust the Scores?
Baidu's latest foundation model earned a perfect score on a widely used code generation benchmark, which raised questions about test set leakage and data contamination. This article explains how benchmark questions and answers can end up in training data, why leakage is hard to prevent and detect, and how teams can build more reliable evaluations using perturbation tests, time-sliced testing, and private test sets.
1. A Perfect Score That Prompted Reflection
During routine evaluation of a new-generation foundation model released by Baidu, we noticed a result worth watching: the model earned a perfect score on a widely used code generation benchmark. A perfect score means the model produced a standard answer that passed all unit tests for every problem in the test set. A few years ago, that level of performance was hard to imagine.
This could reflect a major leap in model capability. Based on our observations over recent months, however, we lean toward a different explanation: more and more high scores come from models that have seen the exam paper, not from models that have truly learned how to solve the problems. In the industry, this is called test set leakage or data contamination.
To understand how serious this is, we first need to look at how large models “learn.”
2. How Large Models Learn: Where Capabilities Come From
2.1 Pretraining: Absorbing Half the Internet
Large model capabilities mainly come from the pretraining stage. During this stage, a model consumes massive amounts of text, including web pages, books, public code on code hosting platforms, and content from Q&A communities. It learns language patterns and knowledge by predicting the next token.
The problem is that the questions and answers in public benchmarks are often part of public data. A classic programming problem may be quoted repeatedly across countless blogs, tutorials, solution write-ups, and code repositories. When the training corpus is crawled broadly enough, these exam questions with their standard answers almost inevitably end up in the training set.
2.2 Post-Training: The Gray Area of Targeted “Cramming”
After pretraining, models go through post-training steps such as instruction fine-tuning and human preference alignment. This stage uses less data, but the data is highly targeted. If post-training data includes samples that closely resemble an evaluation benchmark, even reworded versions, the model’s scores on that benchmark can rise significantly.
This boost does not necessarily mean the model cheated. In many cases, it is accidental. When engineers build training data, they collect samples from public question banks and community discussions, and it is hard to check each sample against every benchmark. Whether intentional or not, the result is the same: evaluation scores no longer purely reflect generalization ability.
3. Why Leakage Is So Common
3.1 The Uncontrollability of Web-Scraped Data
Modern training corpora reach tens of trillions of tokens and come from large-scale web crawling. No team can review this data item by item. A popular programming problem may appear in thousands of variants across the web, including reposted original text, translations, rewritten solutions, and transcripts of video lectures. Traditional exact-match deduplication cannot catch most of them.
3.2 The Fame Paradox of Benchmarks
The more authoritative and popular a benchmark is, the more discussions, solutions, and study guides surround it. Its content is then more likely to enter training corpora. In other words, the greater a benchmark’s influence, the faster it becomes contaminated. This creates a paradox: the evaluations we most need to trust are the ones most likely to fail.
3.3 The Technical Difficulty of Contamination Detection
Determining whether a model has seen a particular problem is much harder than it sounds. Does a reworded version with different wording but identical meaning count as seen? Does a partially quoted answer count? N-gram overlap analysis misses many paraphrased samples, while semantic similarity can wrongly flag legitimate capability samples. The industry has not yet agreed on a perfect detection standard.
4. How to Identify and Address Data Contamination
As model users and evaluators, we can build a more rigorous methodology.
4.1 Common Approaches to Contamination Detection
- N-gram overlap analysis: Measure the n-gram overlap between test samples and training corpora, if accessible. It is the cheapest first-pass screening method.
- Perturbation test: Apply meaning-preserving changes to test problems, such as renaming variables, rephrasing the problem statement, or rewriting constraints in equivalent forms. If a model scores perfectly on the original problems but its scores drop sharply on the perturbed versions, it is likely memorizing rather than understanding.
- Membership inference: Compare the model’s confidence or perplexity on test samples with its confidence on newly constructed samples. This comparison helps infer whether a sample appeared in the training set.
The following is an illustrative perturbation comparison flow:
def contamination_probe(model, original_item, perturbed_item):"""Compare model performance on original and perturbed items"""score_orig = evaluate(model, original_item)score_pert = evaluate(model, perturbed_item)gap = score_orig - score_pertif gap > THRESHOLD:flag_suspected_leakage(original_item, gap)return {"original": score_orig, "perturbed": score_pert, "gap": gap}
4.2 Building a More Trustworthy Evaluation System
- Use a privately held, regularly updated test set: Build new problems on a regular basis and never publish them. This cuts off the chance that the model saw them in advance. This is the most direct and effective approach.
- Cross-validate across multiple benchmarks: Do not rely on a single leaderboard. Combine several benchmarks that cover different capabilities, such as reasoning, code, knowledge, and long context. Check whether the results are consistent, rather than looking for one metric that stands out abnormally.
- Use time-sliced evaluation: Evaluate the model on problems published after its training data cutoff. If the model could not have seen the problems, that is the strongest evidence.
- Run process-based evaluation: Do not check only final answers. Ask the model to show intermediate reasoning, explain design trade-offs, and correct errors under follow-up questions. Models that rely on memorization often expose themselves during follow-up questioning.
- Run regression tests on real business tasks: The most reliable evaluation is always your own business scenario. Build an internal evaluation set from real tasks. The gap between these results and public leaderboard results is itself valuable information.
4.3 Practical Engineering Recommendations
In team workflows, we recommend building the evaluation process into a platform. Store private test sets in object storage with strictly controlled access permissions. Run isolated evaluation tasks on a container platform. Track the inputs, outputs, and score fluctuations of each evaluation through a log service and monitoring alerts, so every evaluation is reproducible and auditable. Any unusually high score should trigger a contamination investigation before it is written into a report.
5. Redefining Criteria for Model Capability
Test set leakage points to a more fundamental question: when the signal from public leaderboards weakens, what should we rely on when selecting a model?
We suggest shifting the focus of evaluation from static scores to three more robust metrics:
- Generalization robustness: Whether performance degrades gradually on unseen or perturbed tasks.
- Interactivity: Performance in real collaborative scenarios, such as multi-turn dialogue, requirement clarification, and error correction.
- Cost efficiency: The stable output quality that each unit of cost delivers for your specific workload.
Leaderboards will not disappear, and they should not. They remain a quick way to screen models. Treat them as reference lines, not final verdicts. What truly determines a model’s value is whether it reliably solves your problems with your data, your workflows, and your constraints.
A perfect score deserves applause, but it also raises a question: did this model really never see this exam?
