Parallel Data Mining and Quality Control › Contamination Checks

Michael BrenndoerferNovember 26, 20266 min read
Language AI HandbookAll chapters
Part 27 of 67Machine Translation and Speech Translation
Chapter 192Parallel Data Mining and Quality Control › Contamination Checks
Reading section 11 of 14 · Contamination Checks · 6 minSection 11 of 14 · 6 min

Section 11 of 14 · 6 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

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 xx with nn-grams Gn(x)G_n(x), compute the fraction of nn-grams that also appear in the training corpus T\mathcal{T}:

containment(x,T)=∣Gn(x)∩Gn(T)∣∣Gn(x)∣\text{containment}(x, \mathcal{T}) = \frac{|G_n(x) \cap G_n(\mathcal{T})|}{|G_n(x)|}

where:

  • xx: a test sentence
  • T\mathcal{T}: the training corpus
  • Gn(x)G_n(x): the set of nn-grams extracted from the test sentence
  • Gn(T)G_n(\mathcal{T}): the set of nn-grams occurring anywhere in the training corpus
  • ∣Gn(x)∩Gn(T)∣|G_n(x) \cap G_n(\mathcal{T})|: the number of test nn-grams that also occur in the training corpus
  • ∣Gn(x)∣|G_n(x)|: the total number of test nn-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 nn has no nn-grams to compare.

  • Replacing one token affects at most nn contiguous length-nn 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 nn 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 nn tokens is present after the same preprocessing, all of its grams occur in the corpus.

PythonIn [23]
CollapseExpand
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.",
]
Out[24]:
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 n=3n=3, the exact copy scores 11, the date replacement scores 4/74/7, the terminology replacement scores 2/32/3, and the new topic scores 00. 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]
CollapseExpand
Bar chart of three-gram containment scores for four test sentences with a threshold line.
The exact copy and both edited sentences reach the illustrative three-gram cutoff. The fourth sentence shares no trigrams with the training fixture.

At n=7n=7, the exact copy still has all of its grams in the corpus. The date replacement has none. At n=13n=13 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.

Contamination is not binary

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!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy