The problem: your data is riddled with duplicates
Common Crawl, the most widely used web data source for training LLMs, is riddled with duplicates and near-duplicates. Mirror pages, syndicated content copied across dozens of sites, near-identical e-commerce templates with just the product name changed... To give one published order of magnitude: in the RefinedWeb pipeline (the team behind the Falcon model, 2023), deduplication halves a corpus that has already been filtered for language and quality. If you train a model on this raw data, you're massively wasting compute on redundant information.
And the consequences go well beyond waste:
- Memorization: the model memorizes repeated passages instead of generalizing. It can regurgitate entire paragraphs from its training data verbatim.
- Amplified biases: overrepresented sources dominate the model. If 30% of your data comes from Wikipedia because every page is duplicated 5 times, your model will have an encyclopedic bias.
- Wasted compute: duplicated tokens provide no new information. You're paying the same GPU cost for zero learning.
- Corrupted evaluation: if examples from your test set appear in the training set (via duplicates), your metrics are lying. You think your model generalizes, but it's just reciting.

The reference study (Lee et al., 2021) measures this: after deduplication, models emit memorized text ten times less often, reach equal or better accuracy in fewer training steps, and evaluation becomes more trustworthy (train-test overlap affected over 4% of validation sets). You often read that deduplication "improves perplexity by 5 to 10%": that figure does not come from this study, and it is better to cite the effects actually measured. It remains one of the most cost-effective interventions on dataset quality.
Deduplicating Training Data Makes Language Models Better (Lee et al., 2021)Cleaning first, deduplication second
Before looking for duplicates, you need to clean the raw data. It's like sorting your belongings before looking for duplicates in your library: there's no point comparing two books if one of them is actually a flyer.
- HTML to text extraction: trafilatura or resiliparse extract useful content from a web page by stripping HTML
- Unicode normalization: standardize to NFKC so that "é" (one character) and "é" (an "e" plus a combining accent) are identical
- Boilerplate removal: navigation menus, footers, ads, sidebars. This isn't useful content.
- Language filtering: fastText lid detects the language. If you want a French dataset, discard the English.
- Length filtering: documents that are too short (a few words) or too long (database dumps) are rarely useful
- Non-textual lines: source code, long URL lists, page counters. Filter based on your needs.
- Quality heuristics: are words well-formed? Do sentences have structure? Is the vocabulary diverse?
- PII removal: emails, phone numbers, addresses. Mandatory for GDPR compliance.
Simple but remarkably effective heuristics
| Rule | What it detects |
|---|---|
ratio_words_to_chars > X | Weird text, random characters (remove) |
lines_ending_with_period > Y% | Real paragraphs of written text (keep) |
lines_duplicate_in_doc > Z% | Spammy document or template (remove) |
The major reference datasets (C4, FineWeb, RedPajama) use these heuristics. It's not sophisticated science, it's pragmatic engineering that works remarkably well.
The right thresholds for these heuristics are found empirically. Manually inspect hundreds of examples at the boundaries of your filters, adjust the thresholds, iterate. The best datasets in the world are the result of dozens of iterations of this process. It's never 100% automated.
Exact deduplication: the simple case
By cryptographic hash
Compute the SHA-256 (or MD5) of each document. Two documents with the same hash = byte-for-byte identical content. Remove the duplicates.
Advantages: fast to compute, zero false positives (it's practically impossible to have the same hash for two different contents)
Limitations: a single character difference produces a completely different hash. Near-duplicates (99% identical) slip through the net.
By normalized URL
Remove documents from the same URL after normalization: stripping tracking parameters (?utm_source=...), normalizing protocol (http vs https), etc.
Limitations: two different URLs can point to the same content (mirror pages, CDN, repost).
Fuzzy deduplication with MinHash: the heart of the matter
The near-duplicate problem
A document that's 95% identical is not 100% identical, but it's still a duplicate for your training purposes. You need an approximate similarity measure that scales.
Jaccard similarity: the founding idea
For two sets A and B:
Represent each document as a set of n-grams (subsequences of n consecutive words, typically n=5). The Jaccard similarity between two sets of n-grams measures the textual overlap between documents.

The problem: comparing all document pairs = O(N^2). For a billion documents, that's approximately 10^18 comparisons. Completely impractical.
MinHash: the brilliant probabilistic trick
The idea: instead of storing all n-grams of a document (potentially thousands), create a compact fixed-size signature.
Choose k random hash functions. For each document, apply the k functions to all its n-grams and keep only the minimum for each function (hence the name "MinHash"). A document's signature = these k minimum values.
The fundamental mathematical property:
The probability that two documents share the same minimum for a random hash function is exactly equal to their Jaccard similarity. It's elegant and mathematically provable.
With k hash functions, the estimate of the Jaccard similarity has a variance of , so at most : the typical error shrinks like . With k = 128, it is about 4 similarity points in the worst case. The larger k is, the more precise the estimate, and the heavier the signatures. In practice, k between 100 and 256 offers a good precision/memory tradeoff (FineWeb uses 112).
LSH: avoiding comparing all pairs
You now have compact signatures, but comparing all pairs is still O(N^2). This is where LSH (Locality-Sensitive Hashing) comes in.
Divide the k signature values into b bands of r rows (k = b x r). For each band, hash the r values together into a hash table. Two documents are candidates (potential duplicates) if they share at least one identical band.
Then, compare in detail only the candidate pairs. The number of candidates is drastically smaller than the total number of pairs.
Tuning b and r is the main lever:
- Larger b (many small bands): many candidates, high recall, but more false positives to check
- Larger r (few large bands): few candidates, high precision, but you miss some duplicates
For a similarity threshold of 0.8 (80% similar), a typical configuration is k=128, b=20, r=5 (20 bands of 5 rows).

10 billion documents x 128 hashes x 4 bytes = 5 TB just to store the signatures. LSH tables add even more memory. At this scale, you absolutely need distributed computing (Spark, Dask, Ray). That's why large datasets are always processed on clusters.
At FineWeb and DCLM scale: what large corpora taught us
When you go from a few million documents to tens of billions, two unexpected lessons appear.
Lesson 1: deduplicating more is not always better
To build FineWeb (15 trillion tokens drawn from 96 Common Crawl snapshots), Hugging Face ran MinHash on 5-grams, with 112 hash functions split into 14 bands of 8, which targets documents about 75% similar. The surprise came from the scope.
- Global deduplication, each snapshot compared against all the others: only 4 trillion tokens remain, and models trained on them do barely better than with undeduplicated data. Looking at the oldest snapshot, the team found that the 10% of documents kept were of worse quality than the 90% removed: more ads, keyword lists, badly formatted text. Good content, re-published year after year, had been eliminated as a duplicate of recent snapshots; what remained was what nobody had ever copied.
- Per-snapshot deduplication, each month processed separately: 20 trillion tokens, and performance on par with the best corpora of the time.
The authors' hypothesis: most of the gain comes from removing the huge clusters of duplicates (hundreds of thousands of copies of the same text), not from hunting down documents copied a handful of times.
The FineWeb Datasets: Decanting the Web for the Finest Text Data at Scale (Penedo et al., 2024)Lesson 2: the number of copies is also information
A text copied by many sites is sometimes spam, but sometimes a useful, well-liked text. FineWeb2, the 2025 multilingual version, draws a consequence: after deduplication, you can reintroduce a limited number of copies of documents that were heavily duplicated and of good quality, which improves results further. The duplicate count becomes one signal among others, rather than only a defect to erase.
FineWeb2: One Pipeline to Scale Them All -- Adapting Pre-Training Data Processing to Every Language (Penedo et al., 2025)Tools for scale
At this scale, memory is the limiting factor. DCLM (DataComp for Language Models, 2024), which starts from a pool of 240 trillion tokens, replaced MinHash with a Bloom filter for its main corpus: a probabilistic data structure that answers "have I already seen this passage?" using very little memory, at the cost of rare false positives (it can wrongly say "yes," never wrongly "no"). Applied to paragraphs as well as documents, it gives results comparable to MinHash but scales far more easily beyond 10 terabytes of text.
DataComp-LM: In search of the next generation of training sets for language models (Li et al., 2024)Beyond words: semantic deduplication
MinHash compares word sequences. Two texts saying the same thing in different words (a wire story rewritten by two newspapers, a paraphrased explanation) escape it. Semantic deduplication compares meaning rather than form:
- each document is turned into an embedding, a vector of numbers produced by a pre-trained model, such that texts with similar meanings get nearby vectors;
- vectors are grouped into clusters, so that only neighbouring documents get compared;
- within each cluster, pairs whose similarity exceeds a threshold are removed, keeping only one.
SemDeDup (Meta, 2023) showed what the method can do: on a subset of the LAION image-caption dataset, it removes 50% of the data with minimal performance loss, halving training time, and it also improves language model training on C4. D4 (2023) combines it with a search for diversity: on a 6.7-billion-parameter model, about 20% efficiency gains and up to 2 points of average accuracy over 16 tasks, with the notable finding that repeating well-chosen data beats baseline training, while repeating random data does worse.
SemDeDup: Data-efficient learning at web-scale through semantic deduplication (Abbas et al., 2023) D4: Improving LLM Pretraining via Document De-Duplication and Diversification (Tirumala et al., 2023)Semantic deduplication is expensive (you need an embedding per document) and does not replace a quality filter: in DCLM's comparison, used alone as a selection method, it does clearly worse than a quality classifier. Its main use is removing the redundancy that remains after the classic stages. See data quality.
Duplication and memorization: a proven link
The first bullet at the top, "the model memorizes repeated passages," is one of the best-established results in the field.
- Kandpal et al. (2022): how often a model regenerates a sequence grows faster than proportionally with its number of copies. A sequence present 10 times in the data is regenerated on average about 1,000 times more often than one present once (that is the chart above). After deduplication, attacks that try to extract training data become far less effective.
- Carlini et al. (2022) describe three regular (log-linear) relationships: memorization grows with model size, with the number of duplicates of an example, and with the length of the opening text given to the model to prompt it to continue. In other words, the bigger models get, the more deduplication matters.
But deduplication reduces memorization without eliminating it: a model can also retain passages seen only once, and researchers have extracted training data from production models. The stakes (personal data, word-for-word reproduction of copyrighted works) and the measurement methods are covered on memorization and extraction.
Sub-document deduplication: repeated passages
Suffix Array Substring Dedup
The same paragraph (legal disclaimer, standard description, cookie policy) can appear in 1,000 different documents. Even if the documents overall are different, these repeated passages pollute training.
The technique:
- Concatenate all documents into a single giant string
- Build the suffix array (a data structure that sorts all suffixes)
- Identify substrings that appear more than N times
- Remove them from the documents
N-gram frequency
Simpler approach: compute the frequency of each long n-gram (10-20 words) across the entire corpus. Passages containing ultra-frequent n-grams are probably repetitive boilerplate. Remove them.
Practical tools
- text-dedup: Python library for MinHash and SimHash, easy to use
- datatrove (HuggingFace): complete pipeline for LLM data preparation, includes deduplication; it is the tool used to build FineWeb
- NeMo Curator (NVIDIA): GPU-accelerated exact, fuzzy and semantic deduplication for very large volumes
- datasketch: Python implementation of MinHash + LSH, very popular
- Spark MinHashLSH: native distributed implementation in Spark for very large volumes
Best practices for effective deduplication
- Multi-level: proceed in stages. First exact (URL, hash), then fuzzy (MinHash), then sub-document. Each level catches what the previous one missed.
- Calibrate visually: at each threshold, manually inspect dozens of examples near the threshold to verify you're not removing useful content
- Deduplicate between train and test: if test set examples are in the training set, your evaluation metrics are invalid. Cross-split deduplication is mandatory.
- Document the parameters: the choices (k, b, r, threshold) enormously affect the final dataset. Document them for reproducibility.
- Iterate: a first pass never catches all duplicates. The best pipelines make multiple passes with different parameters.
- Measure before deduplicating harder: FineWeb's lesson is that more aggressive deduplication can keep the worst. Train small models on the kept data and on the removed data, and compare.
Deduplication is not a one-shot you do once and forget. It's an iterative process that requires attention and common sense.
1. After deduplicating with SHA-256 hashes, two documents that are 99% identical both remain in the dataset. Is that a bug?
2. What makes the MinHash signature so useful for estimating similarity between documents?
3. What is LSH for, once the MinHash signatures have been computed?
4. Why is MinHash deduplication of very large corpora always done on distributed clusters?
5. Why is deduplicating between the train set and the test set described as mandatory?
6. For FineWeb, Hugging Face compared global deduplication (all snapshots together) with per-snapshot deduplication. What did it find?