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.
| Effect | Mechanism | What deduplication changes |
|---|---|---|
| Memorization | Repeated sequences receive many gradient updates | Fewer verbatim regurgitations |
| Contamination | Benchmark items appear in training text | More trustworthy evaluation scores |
| Wasted compute | Tokens spent on content already seen | More unique tokens per training budget |
| Distribution skew | Templates and boilerplate dominate | More balanced coverage of topics |
| Overfitting | Validation overlaps with training | Honest train-test split |
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.
| Method | Detects | Typical cost | Main limitation |
|---|---|---|---|
| Exact hashing | Byte-identical documents after normalization | Very low | Misses small edits |
| MinHash with LSH | Lexically similar documents | Moderate | Threshold tuning, shingle choice |
| SimHash | Near-identical documents via bit fingerprints | Low | Weaker on long, partly overlapping texts |
| Suffix-array substring | Repeated spans inside documents | High memory | Can leave fragmented text |
| Semantic (embedding) | Paraphrases and translations | High, needs GPU inference | Risk of removing related but distinct items |
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.
| Parameter | Typical range | Effect of increasing it |
|---|---|---|
| Shingle size | 3 to 13 tokens or characters | Fewer false matches, lower recall |
| Number of hash functions | 64 to 256 | More precise similarity estimate, more memory |
| Bands and rows | For example 20 bands of 10 rows | Shifts the effective similarity threshold |
| Similarity threshold | 0.7 to 0.85 Jaccard | Removes only very close duplicates |
| Scope | Per crawl snapshot or global | Global scope removes more, costs more |
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.
| Symptom | Likely cause | Remedy |
|---|---|---|
| Legitimate texts removed | Threshold too low for short documents | Raise threshold or skip very short texts |
| Duplicates still present | Shingle size too large, too few bands | Tune LSH bands against a labeled sample |
| Broken paragraphs | Span removal inside documents | Drop whole lines or documents instead |
| Benchmark leakage | No decontamination against test sets | Run n-gram overlap checks per benchmark |
| Minority content lost | Templated languages or domains flagged | Audit removal rates per language and domain |
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.