Data Decontamination
Data decontamination is the removal, from a training set, of examples that also appear in an evaluation set, including examples that are copies with small changes. It exists because a model that has seen the test items during training can score well by recall, and the evaluation number then measures exposure and not the ability it was meant to measure.
What is being removed
Contamination means content from an evaluation set, or something equivalent to it, is present in the training data. Equivalent includes the question with extra whitespace, a translation, a paraphrase, and the same problem with changed names or numbers when the change still exposes the evaluation answer or the specific skill being tested. A template with different numbers (2+3 versus 2+4) is a different item with a different answer, so it is a template overlap to weigh and not an answer leak by itself. The goal is not to make the two files disjoint as strings but to ensure the model has no training signal that gives away the evaluation answers. Decontamination is applied to the training side because the evaluation set is the fixed reference; if a conflict is found, the training example is dropped or the evaluation item is retired.
Methods
Exact match after normalization. Lowercase, collapse whitespace, strip punctuation, and hash. It catches verbatim copies only.
N-gram overlap. Compute all word \(n\)-grams of each evaluation item and flag any training document that shares one (or more than a chosen fraction). Large \(n\) is conservative: a 13-gram match is almost certainly a copy, which keeps false positives low. Smaller \(n\) catches lightly edited copies and flags more innocent text.
A hypothetical example uses the explicit 43-word problem and four documents below. The tokenizer lowercases text and extracts alphabetic words; the edited copy changes word positions 2 and 35, counting from zero. For \(n=13\) it contains 31 distinct 13-grams, and the results against four training documents are:
import re
item = "Two trains leave nearby stations at noon and travel toward each other along a straight track. One travels sixty kilometers per hour and the other forty. If their stations are two hundred kilometers apart, how many hours pass before the trains finally meet?"
words = re.findall(r"[a-z]+", item.lower())
edited = words.copy(); edited[2] = "depart"; edited[35] = "few"
docs = {
"verbatim": "A forum question: " + item,
"two edits": " ".join(edited),
"paraphrase": "Starting simultaneously, a pair of rail vehicles close a 200 km gap at speeds of 60 and 40 km per hour. Determine their meeting time.",
"unrelated": "Gardeners planted herbs beside the house after the rain.",
}
def grams(text, n):
w = re.findall(r"[a-z]+", text.lower())
return {tuple(w[i:i+n]) for i in range(len(w)-n+1)}
print("words", len(words), "edits", [(i, words[i], edited[i]) for i in (2,35)])
for n in (13,8,4):
base = grams(item,n)
print("n",n,"distinct",len(base))
for name,text in docs.items():
shared = len(base & grams(text,n))
print(name, shared, f"{shared/len(base):.3f}")
| training document | shared 13-grams | fraction of item |
|---|---|---|
| verbatim copy inside a forum post | 31 | 1.00 |
| copy with two words changed | 20 | 0.65 |
| paraphrase (same problem reworded) | 0 | 0.00 |
| unrelated text | 0 | 0.00 |
Dropping to \(n=8\) or \(n=4\) raises the lightly edited copy to 25/36 (0.694) or 33/40 (0.825) but still gives the paraphrase 0, because the reworded problem shares no run of even four consecutive words with the original.
Near-duplicate and embedding search. Shingle-set similarity with MinHash finds heavily overlapping text at scale. Embedding similarity (nearest neighbors in a vector space) finds paraphrases that share meaning but not words; its false positives need review, and no threshold separates paraphrase from a legitimately similar but different problem.
Model-based judgment. Yang et al. report that rephrasing or translating benchmark samples evades n-gram decontamination, and that a model could be trained on rewritten test data and still pass those checks. They propose a method that uses a language model to identify rewritten samples. This catches more, at the cost of compute and its own error rate.
Limits
- A check certifies only what it tests. Passing a 13-gram filter says no long verbatim run is shared; it does not say the content is absent.
- Contamination you do not control cannot be removed. The base model’s pretraining data is usually uninspectable, so a public benchmark score is a reference point and not an unbiased estimate. A newly written evaluation set, or one written from private material, is the usual protection.
- Thresholds are trade-offs: loose filters remove legitimate training examples about the same topic (for example, many valid problems are about trains and distances), strict filters miss rewrites.
- Selection against the test set is a separate leak: choosing prompts or checkpoints by test results shapes the model without any test example being in the training files. Decontamination does not touch that.
Practice
A layered approach works better than any single method: exact and near-duplicate removal between training and every evaluation set; group-level splitting so related items stay on one side; embedding search for the most similar pairs with a person reviewing them; and a record of what was checked and with which thresholds, so a later reader knows what the score can support.
References
- Yang et al., “Rethinking Benchmark and Contamination for Language Models with Rephrased Samples” โ https://arxiv.org/abs/2311.04850
Discover more from Insightful Data Lab
Subscribe to get the latest posts sent to your email.
