Training data deduplication

Also known as: near-duplicate removal · MinHash deduplication

On this page 8

Training data deduplication is the process of finding and removing exact and near-duplicate examples from a dataset before a model is trained on it. In artificial intelligence, and especially in the curation of large training data for language and vision models, it reduces memorization, saves compute and prevents test-set contamination, where evaluation examples quietly appear in the training corpus.

Deduplication operates at several granularities, from whole documents to individual paragraphs and repeated substrings. Its most widely used form, MinHash deduplication with locality-sensitive hashing, is a near-duplicate removal technique that scales to billions of web pages at a manageable cost.

Why duplicates harm model training

Duplicates harm training because they distort the effective data distribution: a passage that appears thousands of times receives thousands of times more gradient updates than a unique passage. Web crawls such as Common Crawl contain boilerplate, mirrored sites, license texts, templated product pages and syndicated news, so raw duplication rates are high, often well above a third of all documents depending on the crawl and the definition of a duplicate.

The consequences are measurable. Models trained on heavily duplicated text reproduce training sequences verbatim more often, which creates privacy and copyright exposure. Duplicates also inflate benchmark scores when evaluation items leak into the corpus, and they waste the compute budget on repeated content instead of new information.

The following table summarizes the main effects of duplication and what deduplication changes.

EffectMechanismWhat deduplication changes
MemorizationRepeated sequences receive many gradient updatesFewer verbatim regurgitations
ContaminationBenchmark items appear in training textMore trustworthy evaluation scores
Wasted computeTokens spent on content already seenMore unique tokens per training budget
Distribution skewTemplates and boilerplate dominateMore balanced coverage of topics
OverfittingValidation overlaps with trainingHonest train-test split
Effects of duplicated training data

How exact and near-duplicate detection work

Exact deduplication compares a cryptographic or fast non-cryptographic hash of each normalized document, for example SHA-256 or xxHash after lowercasing and whitespace normalization. Identical hashes mean identical content, so the check is cheap and has no false positives, but it misses documents that differ by a single timestamp, advertisement or navigation link.

Near-duplicate detection estimates similarity instead of identity. The standard pipeline splits each document into shingles, such as overlapping word 5-grams, and approximates the Jaccard similarity between shingle sets. MinHash computes, for each of many hash functions, the minimum hash value over the shingles; the fraction of matching minima between two documents is an unbiased estimate of Jaccard similarity.

Comparing every pair of documents is impossible at web scale, so locality-sensitive hashing (LSH) groups the MinHash signature into bands. Documents that share any identical band become candidate pairs, and only those pairs are verified. The band count and band width set an S-shaped probability curve around the chosen similarity threshold, commonly about 0.7 to 0.85 Jaccard.

A third family works on substrings rather than documents. Suffix-array methods find every repeated span longer than a threshold, for example 50 tokens, and remove those spans while keeping the rest of each document. Semantic deduplication embeds documents with a neural encoder and clusters them, removing items whose cosine similarity exceeds a threshold even when the wording differs.

Methods and their trade-offs

Each method trades recall, precision and cost differently, and production pipelines usually chain several of them. The table below compares the common approaches.

MethodDetectsTypical costMain limitation
Exact hashingByte-identical documents after normalizationVery lowMisses small edits
MinHash with LSHLexically similar documentsModerateThreshold tuning, shingle choice
SimHashNear-identical documents via bit fingerprintsLowWeaker on long, partly overlapping texts
Suffix-array substringRepeated spans inside documentsHigh memoryCan leave fragmented text
Semantic (embedding)Paraphrases and translationsHigh, needs GPU inferenceRisk of removing related but distinct items
Comparison of deduplication methods

The choice of granularity matters as much as the algorithm. Document-level removal is simple but discards a whole page when only its footer repeats, while line-level or span-level removal preserves unique content but can break sentence flow. Many corpora such as FineWeb, Dolma and RedPajama combine document-level MinHash with line-level filtering of repeated boilerplate.

Key parameters in a deduplication pipeline

A deduplication pipeline is controlled by a small set of parameters, and small changes shift the removal rate considerably. The values below are typical starting points for English web text, not universal constants.

ParameterTypical rangeEffect of increasing it
Shingle size3 to 13 tokens or charactersFewer false matches, lower recall
Number of hash functions64 to 256More precise similarity estimate, more memory
Bands and rowsFor example 20 bands of 10 rowsShifts the effective similarity threshold
Similarity threshold0.7 to 0.85 JaccardRemoves only very close duplicates
ScopePer crawl snapshot or globalGlobal scope removes more, costs more
Typical parameters for MinHash deduplication

Scope is a strategic decision. Deduplicating across all crawl snapshots removes the most content but can leave a corpus dominated by older pages, whereas per-snapshot deduplication keeps more data. Some teams found that aggressive global deduplication reduced downstream quality, because pages repeated across crawls are often the higher-quality ones. The retention rule also matters: keeping the longest, earliest or highest-quality copy in each cluster changes the final corpus.

Deduplication within data curation

Deduplication is one stage of data curation, usually placed after language identification and before or alongside data quality filtering. It differs from data pruning, which removes unique but low-value examples, and from dataset distillation, which synthesizes a small replacement set. Deduplication removes redundancy only; it does not judge whether content is useful.

A dedicated step called decontamination applies the same techniques against evaluation sets. Teams compute n-gram overlap, often 13-grams, between training documents and benchmark items and remove matches. Instruction datasets and code corpora such as The Stack need it as much as web text, because popular problems and answers are copied widely across forums and repositories.

Limitations and common mistakes

Deduplication is not free of risk, and over-removal is as harmful as under-removal. The most frequent problems are listed below with their causes and remedies.

SymptomLikely causeRemedy
Legitimate texts removedThreshold too low for short documentsRaise threshold or skip very short texts
Duplicates still presentShingle size too large, too few bandsTune LSH bands against a labeled sample
Broken paragraphsSpan removal inside documentsDrop whole lines or documents instead
Benchmark leakageNo decontamination against test setsRun n-gram overlap checks per benchmark
Minority content lostTemplated languages or domains flaggedAudit removal rates per language and domain
Common deduplication mistakes

A subtle limitation is that some repetition is useful. Legal texts, mathematical definitions and widely quoted passages repeat because they matter, and research on language model scaling suggests that a few epochs over high-quality data can be acceptable. Deduplication should therefore be measured with downstream evaluations, not judged only by the share of data removed.

A plain-language summary

Imagine studying for an exam from a pile of notes. Half of the pile is the same page photocopied many times. You would waste hours rereading it. You might also memorize that page word for word and miss everything else.

Training data deduplication solves the same problem for AI models. It finds copies and near-copies in the data and keeps only one. The model then sees more varied material in the same training time. Test questions are also less likely to hide in the study pile, so scores stay honest.

An example from practice

A research team prepares a 1-trillion-token web corpus for a mid-sized language model. Exact hashing first removes byte-identical pages. The team then runs MinHash with 128 hash functions on word 5-grams, with LSH bands tuned to a Jaccard threshold of about 0.8, and keeps one document per cluster.

The two stages together remove roughly 40 percent of documents, mostly mirrored blogs, product listings and cookie notices. A final decontamination pass removes a few thousand pages containing 13-gram overlaps with the team’s benchmarks. Compared with a pilot model trained on the undeduplicated data at the same compute budget, the new model reproduces training text verbatim far less often and scores slightly higher on held-out evaluations, which confirms that the removed material added cost but little knowledge.