Parallel Data Mining and Quality Control › Contamination Checks
Language AI HandbookAll chapters Training–evaluation contamination occurs when training includes content the evaluation is meant to hold out. Shared sources are a reason to audit actual membership. FLORES-101 used Wikipedia in its original release, while the IWSLT 2014 evaluation used TED and TEDx talks. Check the exact release and split against your own data. FLORES-101 paper · IWSLT 2014 organizers
Suppose a crawl and a later evaluation both draw from the same news site. The crawl might contain a test article, a revised copy, or another article about the same event. Compare the actual training and evaluation texts before interpreting a benchmark score as evidence of generalization.
The two screens here compare lexical overlap and embedding similarity. Both propose candidate overlaps for inspection.
N-gram overlap
For each test sentence with -grams , compute the fraction of -grams that also appear in the training corpus :
where:
- : a test sentence
- : the training corpus
- : the set of -grams extracted from the test sentence
- : the set of -grams occurring anywhere in the training corpus
- : the number of test -grams that also occur in the training corpus
- : the total number of test -grams, which normalizes the count into a fraction
Choose the n-gram length and flagging threshold for the kind of overlap you want to catch. A test string shorter than has no -grams to compare.
- Replacing one token affects at most contiguous length- windows. The token's position, the sentence length, and repeated grams determine how many distinct grams are lost. Short grams can also match common phrases in unrelated text.
- Larger requires longer shared sequences and can miss rewritten sentences.
The example uses lowercase whitespace tokens and a set of distinct grams. Choose preprocessing rules to match the risk you want to measure and report those rules with the overlap results.
Containment measures the fraction of test grams found anywhere in training. Distinct grams can be scattered across unrelated training rows, so a score of one alone does not establish a verbatim copy. If an exact test string with at least tokens is present after the same preprocessing, all of its grams occur in the corpus.
PythonIn [23]Expand
def ngram_set(text: str, n: int) -> set:
tokens = text.lower().split()
return {
tuple(tokens[i : i + n]) for i in range(max(len(tokens) - n + 1, 0))
}
def containment(test: str, corpus: list[str], n: int = 3) -> float | None:
if n < 1:
raise ValueError("n must be positive")
test_ng = ngram_set(test, n)
if not test_ng:
return None
corpus_ng = set()
for doc in corpus:
corpus_ng |= ngram_set(doc, n)
return len(test_ng & corpus_ng) / len(test_ng)
train_corpus = [
"The quick brown fox jumps over the lazy dog.",
"Machine translation systems rely on large parallel corpora.",
"Neural networks learn distributed representations of words.",
"The committee met on Tuesday to discuss the budget.",
]
test_sents = [
"The committee met on Tuesday to discuss the budget.",
"The committee met on Thursday to discuss the budget.",
"Machine translation systems rely on large monolingual corpora.",
"A new restaurant opened downtown last week.",
]| test_sentence | containment_3gram | flagged | |
|---|---|---|---|
| 0 | The committee met on Tuesday to discuss the bu... | 1.000000 | True |
| 1 | The committee met on Thursday to discuss the b... | 0.571429 | True |
| 2 | Machine translation systems rely on large mono... | 0.666667 | True |
| 3 | A new restaurant opened downtown last week. | 0.000000 | False |
At , the exact copy scores , the date replacement scores , the terminology replacement scores , and the new topic scores . The cutoff flags the first three rows, including the terminology replacement, which shares a prefix with its training neighbor. These scores are overlap signals. The two changed sentences have different edits and lengths, so there is no reason for their scores to be in narrative order.
The containment scores from the table are easier to compare as a bar chart.
VisualizationOut [25]Expand

At , the exact copy still has all of its grams in the corpus. The date replacement has none. At every test row is too short to evaluate. Report those rows as unscored or check them using a separate exact string match.
Embedding similarity
Two paraphrases can share no word n-grams. A multilingual encoder can propose additional candidates by retrieving close training vectors for each evaluation sentence. Calibrate the score and check the returned texts, including translations and same-topic nonmatches.
Run lexical matching first if it reduces the volume of work for the embedding step in your setup. Use embedding similarity to look for some paraphrases or translations that wording-based matching misses.
A lexical comparison can identify exact copies under its tokenization and surface some near copies. A semantic comparison can retrieve independent texts on the same topic and still miss paraphrases or translations. Report what each pass searches and inspect examples it flags or misses.
Removing contamination
An overlap report can flag a test item or a training document for action. Use the decision that matches which artifact you can change:
- Replace flagged evaluation items. Document how the revised evaluation changes coverage and report its version.
- Exclude flagged training pairs. Record the rejected row IDs and look for remaining copies elsewhere in the corpus.
- Exclude flagged training documents. Remove their candidate pairs when surrounding context or repeated versions make row-by-row removal inadequate.
Removing a flagged document preserves benchmark membership and excludes all pairs you derived from that document. An undetected copy in a second document or a reformulation may remain. The fixture above reports flags and does not simulate document deletion.
For a release you control, publish which splits and languages you compared, the normalization or encoder, the cutoff, and how you handled flagged items. We return to benchmark validity in Benchmark Evaluation.
A pair can overlap by exact text, near copy, paraphrase, or translation. Detection depends on the benchmark and comparison method. Yang et al. found that lexical screening missed translated contamination in their settings and that the tested semantic methods differed. Yang et al., §5.2.1 and Table 5
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!