Evaluating AI systemsMiddleLesson 2186 min read

Contamination: when the test leaked

Models learn from huge amounts of web text, which can include the very test questions used to judge them. Learn the signs, and how held-out and fresh test sets protect you.

Lesson in motion

In 60 seconds

Contamination: when the test leaked

Models learn from huge amounts of web text, which can include the very test questions used to judge them. Learn the signs, and how held-out and fresh test sets protect you.

1/4
In simple words
If the board exam paper leaks on WhatsApp the night before, the marks next day do not show who studied. They show who saw the paper. When test questions leak into an AI's training data, its score stops showing what it can really do.
Data contamination means that test items, or close copies of them, were in the data used to train the model. The model may then give the right answer from memory, not from skill. Its score looks better than its real ability.

How the test gets in

  • Web crawls: benchmark questions and answers are posted on GitHub, blogs, forums and course notes. Large crawls pick them up.
  • Rewritten copies: a question translated into another language or reworded in a tutorial still teaches the answer.
  • Fine-tuning data: instruction datasets sometimes include benchmark-style items, or items generated by models that saw them.
  • Your own leaks: you paste test cases into prompts while debugging, or add failed test items to training data "to fix them".
Watch out
The last point is the one you control. If you train or tune on your test items, your test is no longer a test. Keep evaluation data and training data separate, always.

Signs that a score may be contaminated

SignWhat you seeWhy it points to leakage
Old beats newMuch better on items published long ago than on similar new items.Old items had more time to spread across the web before training.
Paraphrase dropAccuracy falls when you reword questions or change the numbers.Real skill survives rewording. Memory of the exact text does not.
Verbatim recallGiven the start of a test item, the model completes it word for word.It has seen the item text, not just the topic.
Too good to be trueA huge jump on one benchmark but no change on related tasks.Real improvements usually spread across similar tasks.
None of these signs proves contamination alone. Some items are simply easier, and rewording can make a question harder by accident. Look for several signs together.

Checking for overlap

If you have access to the training text (for example, your own fine-tuning data), you can check for overlap directly. A common method is to break both texts into n-grams (runs of n words) and see how many of a test item's n-grams also appear in the training text.
Python: share of a test item's 8-word runs that appear in training textpython
def ngrams(text, n=8):
    words = text.lower().split()
    return {tuple(words[i:i + n]) for i in range(len(words) - n + 1)}

def overlap(test_item, training_ngrams, n=8):
    grams = ngrams(test_item, n)
    if not grams:
        return 0.0
    return len(grams & training_ngrams) / len(grams)

training_text = "... your fine-tuning data joined together ..."
train_grams = ngrams(training_text)
score = overlap("the test question you want to check goes here in full", train_grams)
print(f"overlap: {score:.0%}")
Note
Exact n-gram checks miss translated or reworded copies, so a low overlap does not prove the item is clean. Some benchmark authors add a unique "canary" string to their files so that model builders can find and remove them from training data.

Protecting your evaluation

  1. 1

    Hold data out

    Split off test data before any training or prompt tuning, and never look at it while tuning.
  2. 2

    Keep it private

    Do not post your test set online or paste it into public tools.
  3. 3

    Refresh it

    Add fresh items written after the model's training cutoff, for example from this month's real user questions.
  4. 4

    Compare old and new

    If the model does much better on old items than new ones, investigate.
Some public benchmarks now use this idea: they keep adding new problems published after models were trained, or keep a hidden test set that is never released. When you read a score, ask: could this model have seen these items?
Try this. Take five questions from a public quiz or exam paper that has been online for years. Reword each one and change any numbers. Ask a chatbot both versions. Does it do equally well on both?

Watch and read more

Lab

A small contamination check: an n-gram overlap script plus an old-versus-reworded test.

~30 min

The problem

  1. Copy the starter script. Paste in any text you are allowed to use as a stand-in for "training data" (for example, a public-domain article or your own notes).
  2. Write five "test items": two copied from inside that text, one heavily reworded from it, and two brand new.
  3. Run the script and record the overlap for each item. Which items does it catch? Which does it miss?
  4. Write two sentences on what this check can and cannot tell you.

Practice lab

Edit the code and run it. Python runs in your browser — nothing is sent to our server.

Output

No output. Add print(...) to see values.

You are done when

Hard questions

Try to answer before you reveal. If you can answer these, you understood the lesson.

Q1Why is the number 8 a trade-off in an 8-gram check?Reveal

Short n-grams (say 3 words) match common phrases like "one of the", so many clean items look contaminated. Long n-grams (say 20 words) only match near-exact copies, so light edits hide real leaks. A middle value balances false alarms against misses. Teams often try several values and look at the matches by hand.

Q2A vendor says their model "has no contamination" on a public benchmark. What would you ask?Reveal

Ask how they checked: which training data they searched, what matching method and threshold they used, whether they checked for paraphrases and translations, and whether they report results on items published after their training cutoff. Then run your own reworded or fresh items. A claim without a method is not evidence.

Please sign in to continue.

Questions people ask

Is contamination the same as cheating?

Usually not. Most contamination is accidental: training sets are so large that nobody reads them all. But the effect is the same as cheating for the person reading the score, so it must be checked.

Can I check a closed model for contamination?

Only indirectly, because you cannot see its training data. Use the signs: compare old and new items, reword questions, and test whether it completes test items word for word. Treat the results as evidence, not proof.

If a model has memorised an answer, is that always bad?

Not for users: remembering facts is useful. It is bad for measurement, because the test was meant to check a skill such as reasoning or coding on new problems. A memorised answer tells you nothing about the next new problem.

How often should I refresh my private test set?

There is no fixed rule. Add new real examples regularly, especially after your product or users change. Keep a stable core set so you can compare over time, plus a fresh slice that no model could have seen.

Lesson test

5 questions. Get 3 right (60%) to pass and complete this lesson.

Sign in to take the test and save your progress