Concept · Chapter 9: How an LLM Is Actually Built
Deduplication and MinHash
Deduplication removes repeated and near-identical documents from training data, usually by comparing sets of overlapping word sequences with MinHash signatures, so that copies are neither memorised nor overweighted.
The problem
The web is full of copies (mirrors, syndicated articles, templates, boilerplate), and comparing every pair of billions of documents is impossible.
The solution
Turn each document into a set of shingles (overlapping k-word sequences), compress the set into a short MinHash signature, and use banded hashing so only likely duplicates are ever compared.
The consequence
Models trained on deduplicated data memorise less, train more efficiently and are evaluated more honestly. The method is probabilistic, with a tunable threshold, and it catches copied text, not copied ideas.
You should understand first
- Text as Data
- Probability and Distributions
- Conditional Probability and Bayes' Theorem
- Probability of Sequences
- Language Modeling
- Vectors
- Dot Product
- Embeddings
- Attention
- Softmax
- Self-Attention
- Causal Masking
- Entropy
- Loss Functions
- Cross-Entropy Loss
- Autoregressive Next-Token Prediction
- Pretraining at Scale
- One-Hot Encoding
- Tokenization
- Building a Pretraining Dataset
- Deduplication and MinHash
Why bother?
Lee and colleagues found a single 61-word English sentence repeated over 60,000 times in the C4 dataset Established. A model sees such text thousands of times and memorises it. Deduplicating the training data let them train models that emitted memorised text ten times less often and needed fewer training steps for the same or better accuracy Established. Duplicates also leak between training and test sets: over 4% of the validation sets of standard datasets overlapped with their training data Established.
From documents to sets
Exact deduplication is easy: hash each document and drop repeated hashes. But a syndicated article with a different footer, or a recipe with one edited sentence, hashes completely differently.
So compare documents as sets of shingles: every run of k consecutive words. Two pages that share most of their text share most of their shingles. Their Jaccard similarity is
Tiny example. "the cat sat on the mat" has the 3-word shingles the cat sat, cat sat on, sat on the, on the mat. Change the last word to "rug" and only the last shingle changes: 3 shared out of 5 distinct, so J = 0.6.
MinHash: a signature that estimates Jaccard
Apply a random hash function to every shingle of both documents and keep each document's minimum. The probability that the two minimums are equal is exactly the Jaccard similarity Established (Broder, 1997). Repeat with many independent hash functions, and the fraction of matching minimums estimates J. Each document becomes a short, fixed-size signature, say 112 numbers, however long it is.
LSH: compare only likely pairs
Even with signatures, comparing every pair of a billion documents is too much. Locality-sensitive hashing splits each signature into b bands of r numbers and puts documents into buckets by each band. Only documents sharing a bucket are compared. A pair with similarity s becomes a candidate with probability
an S-shaped curve with its steep part near . FineWeb used word 5-grams and 112 hash functions in 14 bands of 8, targeting documents at least 75% similar Established. Try it in the lab, and watch an edited recipe slip under the threshold.
Try it · toy model
Run the deduplication method web-scale datasets use (shingles, MinHash and banded hashing) on a dozen made-up web pages, and tune what counts as a copy.
Surprises at scale
More deduplication is not automatically better. FineWeb's team found that deduplicating across all 96 crawl snapshots at once gave worse models than deduplicating each snapshot separately: in older snapshots, the small share of data that survived global deduplication was of lower quality than what was removed Established. One explanation they offer is that the main benefit comes from removing large clusters of duplicates present in every crawl Interpretation.
What to remember
- Exact hashing only catches identical copies; near-duplicates need a similarity measure.
- Jaccard similarity of shingle sets: shared shingles ÷ all distinct shingles.
- MinHash: the chance two documents share a minimum hash equals their Jaccard similarity.
- LSH bands: a pair becomes a candidate if any band of r hashes matches; P = 1 − (1 − s^r)^b.
- FineWeb: word 5-grams, 112 hashes in 14 bands of 8, aimed at pages at least 75% similar.
Key papers
On the resemblance and containment of documents
Andrei Z. Broder · 1997 · Compression and Complexity of SEQUENCES 1997
Introduced the shingling and min-wise hashing (MinHash) technique that pretraining pipelines still use to find near-duplicate web pages at scale.
How to read it: Read the definitions of resemblance and the sketching argument; skip the containment variant on a first pass.
Deduplicating Training Data Makes Language Models Better
Katherine Lee, Daphne Ippolito et al. · 2021
Showed that standard training sets are full of duplicates, and that removing them reduces memorisation and leaks between training and test data.
The FineWeb Datasets: Decanting the Web for the Finest Text Data at Scale
Guilherme Penedo, Hynek Kydlíček et al. · 2024 · NeurIPS 2024
The most thoroughly documented open recipe for turning Common Crawl into pretraining data, with an ablation for every step.
How to read it: Section 3 walks through the pipeline step by step; the global-deduplication surprise is in 3.4.
Watch
Stanford Online
Stanford CS336 Language Modeling from Scratch | Spring 2025 | Lecture 13: Data 1
A tour of what real pretraining datasets contain and how they were built, from a course that argues data matters most.