Foundations to Frontier
Tests

Contamination

Contamination means benchmark questions, or close paraphrases of them, are in a model's training data. Scores then measure memory instead of ability. Web-scale pretraining makes this common, because benchmarks are posted, discussed and copied online. This page covers how contamination happens and how to detect it. Detection methods include n-gram overlap, membership-inference scores such as Min-K% probability and likelihood ratios against a reference model, canary strings, time-split benchmarks and perturbed re-tests. The page also covers how to report results honestly. In the exercises you implement n-gram overlap and the Min-K% score. You then leak 20% of a 500-item test set into a training corpus, half verbatim and half paraphrased. 13-gram overlap caught every copy and no paraphrase. Raw Min-K% barely separated seen from unseen items (AUC 0.57). A likelihood ratio against a reference model reached 0.90. Leaks raised the reported accuracy from a true 0.514 to 0.566. Removing the items flagged by n-gram overlap left 0.533.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

When the exam questions leaked

If students saw the exam questions the night before, their marks say little about what they learned. Language models read much of the internet, where benchmark questions are posted and discussed, so they may have seen the test. Copies are easy to find by searching for long matching phrases; reworded copies are much harder. The demo shows how much a few memorised questions inflate a score.

Evaluation lab
Reported accuracy 59.0%, of which 9.0 points come from memorised test items.
Why engineers care

When choosing a model for engineering use, prefer evaluations on private or fresh questions that cannot have leaked.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Contamination means the test was…
  2. 2. Exact copies are found by…
  3. 3. Reworded copies are…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Sources: benchmark files on GitHub and the web, forum discussions, solution blogs, synthetic data generated from benchmark-like prompts, and fine-tuning sets built from benchmarks.
  • n-gram overlap: GPT-3 flagged items sharing a 13-gram with the training data; Llama reports use token-overlap thresholds. Needs access to the corpus; misses paraphrases and translations.
  • Membership inference: perplexity, Min-K% probability (mean of the least likely tokens), zlib ratio, and likelihood ratio against a reference model; works without the corpus but is weak for single items.
  • Behavioural tests: guided completion (can the model finish the question verbatim?), option-order permutations, perturbed or regenerated questions (GSM1k), time splits after the training cutoff (LiveCodeBench).
  • Prevention: canary strings, encrypted or private test sets, held-out refreshes.
  • Reporting: state decontamination method, report clean-subset scores, and treat large gains on old public benchmarks with caution.
📝 Quick check (Level 1)
0/3 answered
  1. 1. GPT-3 decontamination used…
  2. 2. Membership inference needs…
  3. 3. A time split evaluates on…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Checking for contamination

Exercise 1.

  • n-gram overlap against a corpus.
  • The Min-K% probability score.

Practice.

  • With corpus access: build an n-gram index (suffix arrays or Bloom filters; tools such as WIMBD, infini-gram) and flag overlapping items.
  • Without it: compute Min-K% or likelihood ratios against a smaller reference model; test guided completion of question prefixes.
  • Create perturbed versions of your benchmark (new numbers, rephrasings) and compare scores.
  • Put a canary GUID in benchmark files you publish; keep a private split.
  • Report clean and full scores and the method used.
import numpy as np
def token_logprobs(model, tok, text):
    import torch
    ids = tok(text, return_tensors="pt").input_ids
    with torch.no_grad(): lp = model(ids).logits.log_softmax(-1)[0, :-1]
    return lp.gather(1, ids[0, 1:, None])[:, 0].numpy()
target, ref = token_logprobs(big, tok, item), token_logprobs(small, tok, item)
min_k = np.sort(target)[: max(1, len(target) // 5)].mean(); ratio = (target - ref).mean()
🐍 Exercise 1: overlap and membership scores
Flag n-gram overlap with a corpus and compute the Min-K% probability score.
📝 Quick check (Level 2)
0/3 answered
  1. 1. A tool for searching huge corpora for n-grams:
  2. 2. Perturbed re-tests compare scores on…
  3. 3. Publish benchmarks with…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Why raw likelihood is weak. A text’s log-probability depends mostly on how predictable it is (common phrases, formulaic maths) and only a little on whether it was seen. The variance from predictability swamps the membership signal, so thresholds on perplexity or Min-K% separate seen from unseen items only slightly better than chance.

Calibration. Subtracting the log-probability under a reference model that did not see the item cancels the shared predictability term: the likelihood ratio isolates what training on the item added.

Inflation. With leak share c, clean accuracy a and accuracy on leaked items m, the reported score is (1 − c) a + c m. Removing only the detected leaks removes only their share of the inflation.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Raw likelihood mostly reflects…
  2. 2. A reference model cancels…
  3. 3. Reported accuracy with leaks is…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

How well do overlap and likelihood-based methods detect contamination, and how much inflation survives decontamination?

History.

  • T. Brown et al., “Language models are few-shot learners” (GPT-3, 2020), 13-gram decontamination.
  • W. Shi et al., “Detecting pretraining data from large language models” (Min-K%, 2024).
  • H. Zhang et al., “A careful examination of LLM performance on grade school arithmetic” (GSM1k, 2024).

Exercise 2. A simulated leak.

  • Test set: 500 items of 30 tokens (vocabulary 1000). About 10% are copied verbatim into a 20000-document corpus and 10% paraphrased (each token swapped for a synonym with probability 0.5).
  • Detectors: 13-gram overlap; Min-K% (lowest 20% of token log-probabilities); mean log-likelihood ratio against a reference model.
  • Model log-probabilities: per-item predictability N(0, 1) plus token noise; exact leaks gain +1.5 on half their tokens, paraphrased leaks +0.3 on all.
  • Accuracy: 0.50 on clean items, 0.95 on copies, 0.75 on paraphrases.
detector copies paraphrases false positives
13-gram overlap (recall) 1.0 0.0 0.0
Min-K% (AUC) 0.575 0.549 –
likelihood ratio (AUC) 0.897 0.773 –
accuracy seed 0
reported, all 500 0.566
after removing 13-gram matches 0.533
truly clean items 0.514
  • Overlap is exact for copies and blind to paraphrases.
  • Min-K% alone was weak because predictability varied more than memorisation.
  • The likelihood ratio cancelled predictability and detected both kinds of leak.
  • Decontamination removed about 60% of the inflation (5.2 → 1.9 points).
  • Seeds 1 and 2: ratio AUC for copies 0.916 and 0.899, for paraphrases 0.639 and 0.785 (only about 50 paraphrased items, so this varies); Min-K% for copies 0.597 and 0.634.
  • Caveat: log-probability effects are simulated; real membership inference on large models is often weaker.
🐍 Exercise 2 (research): how well do overlap and likelihood-based methods detect contamination, and how much inflation survives decontamination?
Leak benchmark items into a corpus, detect them with n-gram overlap and likelihood scores, and measure score inflation before and after decontamination.

Contamination in AI, robotics and aerospace

  • Internal evaluations: keep engineering test sets off shared drives used for training data and fine-tuning.
  • Vendor claims: ask model providers for clean-subset scores on your domain tasks.
  • Robotics: simulated benchmark scenes reused in training data inflate success rates in the same way.

References

  1. T. Brown et al. (2020). “Language models are few-shot learners.” NeurIPS.
  2. W. Shi et al. (2024). “Detecting pretraining data from large language models.” ICLR.
  3. H. Zhang et al. (2024). “A careful examination of large language model performance on grade school arithmetic.” NeurIPS.
  4. N. Jain et al. (2024). “LiveCodeBench: holistic and contamination free evaluation of large language models for code.” arXiv.