LLM Benchmark Contamination: When 96% of the Test Set Can Be Recited From Memory

    Can large language model benchmark scores still be trusted when public test sets may already exist in training data? This article examines a case where a base model reproduced 96% of a public coding benchmark verbatim, causing its net score to fall from a perfect 100 to 3.66. It explains how contamination enters the pre-training, post-training, and evaluation stages, presents three reproducible probes for detecting memorization, and outlines practical decontamination workflows, robust code evaluation design, and engineering practices for trustworthy benchmark pipelines.

    1. An Anomaly: The Model Is Reciting, Not Solving

    We gave a newly released base model a coding problem drawn from a widely used public code evaluation set (164 problems in total) and provided only problem 66. After returning the correct answer, the model did not stop. It continued to output the statements, examples, and official reference answers for problems 67, 68, 69, and 70 in their original order, word for word. It even reproduced a typo from the original example (the word “example” misspelled as “example” in the source was copied exactly as written).

    None of this content appeared in the input. Running the full set produced a striking result: 158 of the 164 problems could be written out “from thin air,” statement and answer together, a rate of about 96%. Under standard evaluation, the same model scored a perfect 100 on this coding capability. Once those 158 “reritable” problems were removed from the statistics, the score dropped to 3.66. The average ranking of four evaluated models shifted from first place to last, while another model rose to first. That model could barely recite any problems, showing that high scores are achievable without relying on memorization.

    This is not an isolated failure but a structural one: when the exam paper is public, the exam is no longer an exam.

    2. How Models “Go to School”: Three Stages and Contamination Entry Points

    Understanding the risk requires understanding the training pipeline. A large model grows in roughly three steps:

    • Pre-training: equivalent to reading through an entire library, ingesting massive amounts of web pages, books, and code to produce a base model. It is knowledgeable but not yet good at following instructions.
    • Post-training: equivalent to on-the-job training, using instruction fine-tuning, preference alignment, tool use, and agent behavior training to turn it into a usable assistant.
    • Evaluation: equivalent to an exam, where the industry scores models on public standard test sets. Most score tables shown at launch events come from this stage.

    The problem is that the statements and answers of public test sets may already exist in the pre-training corpus (problems scraped, reposted, or included in code repositories and Q&A sites). They may also enter post-training data (human annotations, synthetic data, rejection-sampling samples, agent trajectories), or leak a second time during evaluation due to framework caching and reused prompt templates. A failure at any of the three stages distorts the score.

    Contamination also varies in severity. The lighter form is “familiarity with problem types”: the model has seen similar questions and formed a solving prior. The heavier form is “having the original paper”: the model memorized the mapping from statements to answers, and evaluation degrades into retrieval. The two require different remedies, so they must be distinguished first.

    3. How to Determine “Memorization”: Three Reproducible Probes

    Do not judge by intuition; use reproducible experimental designs. The following three probes are low-cost and high-signal:

    1. Continuation probe. Provide only problem k and observe whether the model continues to output the statement and reference answer of problem k+1 in the original order. Verbatim reproduction, consistent ordering, and even preserved original typos are strong evidence of memory rather than reasoning.
    2. Perturbation probe. Keep the semantics unchanged while altering variable names, function names, parameter order, boundary conditions, units, and formatting, or even translating the problem into another natural language. True capability is robust to perturbation; memory collapses quickly.
    3. Counterfactual probe. Construct new problems that are “isomorphic but with different solutions,” or modify constraints so the original answer no longer holds. If the model still outputs the original answer, it is retrieving rather than solving.

    Illustrative pseudocode (for batch execution of continuation and perturbation detection):

    1. def contamination_probe(model, items, k=1):
    2. hits = []
    3. for i in range(len(items) - k):
    4. prompt = items[i].prompt # Provide only problem i
    5. out = model.generate(prompt, max_tokens=2048)
    6. target = items[i + k] # The problem expected to be "recited," i+k
    7. if verbatim_similarity(out, target.answer) > 0.95:
    8. hits.append((i, i + k, "verbatim"))
    9. elif accuracy(model, perturb(target)) < 0.2:
    10. hits.append((i, i + k, "fragile"))
    11. return hits

    Decision thresholds should be set according to business risk, but the combination of “extremely high verbatim similarity plus a sharp accuracy drop after perturbation” can generally be characterized as memory-dominated.

    4. Decontaminated Evaluation: After Removing the Recitable Problems

    The first step in remediation is not retraining but making the evaluation clean. A practical workflow has four parts:

    • Corpus-level deduplication. Apply n-gram overlap, MinHash/SimHash near-duplicate detection, and exact substring matching between training corpora and test sets. Remove or downweight matched samples according to policy, and keep audit logs.
    • Dual-track scoring. Report both the “raw score” and the “net score after removing recitable problems.” The larger the gap, the lower the credibility. Only a gap close to zero indicates the score mainly reflects capability.
    • Holdout set. Build a private evaluation set that is never made public, sampled in a stratified manner by capability dimension, with periodic rotation of problems and controlled exposure cycles.
    • Time-based split. Use only problems created after the model’s training cutoff for “future problem” evaluation, naturally avoiding historical contamination.

    The net score calculation can be simple:

    1. net_score = (correct_total - correct_memorized) / (total - memorized)

    When the denominator is too small (for example, too few problems remain after removal), a confidence interval should be reported alongside, to avoid drawing ranking conclusions from very few samples.

    5. How to Evaluate Coding Capability Without Relying on Memorization

    Code evaluation is especially prone to contamination because public problems are limited in number, have unique answers, and are easy to repost. A more robust approach is “capability matrix + dynamic generation + execution verification”:

    • Capability matrix. Stratify problems by difficulty, dependencies, and constraint type (boundary conditions, error handling, performance complexity, concurrency safety), and report stratified scores rather than a single total.
    • Dynamic generation. Use parameterized templates to randomly generate problem statements and constraints, ensuring each evaluation uses different problem instances while keeping the difficulty distribution controllable.
    • Execution verification. Use unit test pass rate as the core metric, covering normal paths, boundaries, and abnormal inputs, and add complexity and resource limits to prevent “runs but times out or exceeds memory.”
    • Process metrics. Record first-pass rate, repair rounds, per-problem time, and token consumption to assess real engineering usability.
    • Leakage prevention in prompts. Do not include problem numbers, sources, or original example text in evaluation prompts, to avoid inadvertently triggering memory.

    An example of a minimal viable evaluation item structure:

    1. {
    2. "id": "random-uuid",
    3. "spec": {"language": "python", "timeout_ms": 2000},
    4. "prompt": "Implement function f(nums, k) satisfying constraints C1..Cn",
    5. "tests": ["assert f([1,2],1) == ...", "assert f([],0) == ..."],
    6. "meta": {"difficulty": "hard", "category": "edge-cases"}
    7. }

    6. Engineering: Making Credibility Part of the Pipeline

    Evaluation credibility is not a one-time activity but should be embedded in continuous integration:

    • Data lineage. Record the sources, versions, and licenses of pre-training and post-training data, supporting traceback by source and batch removal.
    • Automated contamination scanning. Before each release, run the continuation, perturbation, and counterfactual probes, output the contamination rate and net score, and set release gates (for example, block the release directly if the net score is below a threshold).
    • Leaderboard governance. For the same model, annotate the evaluation date, problem version, and whether decontamination was applied, to avoid direct cross-version comparison.
    • Reproducible results. Fix random seeds, decoding parameters, and prompt templates, and save raw outputs for third-party review.
    • Monitoring and alerts. Sample online outputs to monitor “suspected memorized outputs” (long verbatim reproductions, high similarity to known problems) and trigger manual review.

    If this pipeline is hosted on general cloud capabilities, object storage can hold evaluation assets and raw outputs, container platforms can run evaluation tasks, message queues can distribute tasks, and logging and monitoring services can track gate results, turning “credibility” into a sustainable engineering metric.

    7. Conclusion: Check These Three Things Before Looking at Rankings

    Faced with a polished score table, ask three questions first: are the problems public and possibly in the training data; is a net score after removing recitable problems reported; and is there a private holdout set and time-split evaluation for cross-validation.

    The signal from this observation is direct: a base model scored perfectly on a public code set, yet 96% of the problems could be recited verbatim, leaving a net score of only 3.66 and a ranking that fell from first to last. Meanwhile, a model that could barely recite any problems still achieved a high score. This shows that a high score does not necessarily equal capability. Benchmarks must rest on the triple constraints of “decontamination + private holdout + execution verification” to have value for selection and acceptance.