Deduplication: exact, MinHash, suffix arrays, semantic

Reading: 34 min, plus 23 in closed details. Measured on the topic's running example (one Common Crawl WARC of CC-MAIN-2024-30) on an Apple M1 Pro CPU, published results kept apart. Child of Topic: data-curation-and-datasets. Data as of October 2026.

Every dedup method turns "is this a copy?" into a key that copies share (a hash, a band of MinHash minimums, neighbouring entries of a sorted suffix list, a nearby embedding), groups items by that key so nothing is compared pair by pair, and keeps one item per group. The key decides which copies a method can see; the scope it runs over (one file, one crawl, every crawl) decides how many it finds.

You need: the root's running example (Topic: data-curation-and-datasets): one WARC file (Common Crawl's raw archive of HTTP responses) from the July 2024 crawl CC-MAIN-2024-30, 20,991 responses, taken through a FineWeb-style datatrove pipeline (run0): 19,241 extracted documents, 2,692 filtered documents (English, passed the quality rules; this is what reaches dedup), 2,617 final. Embeddings for section 8 (Topic: rag-and-retrieval). Labels: measured on an Apple M1 Pro, CPU only, October 2026; published by the authors, with the table; derived with its formula; vendor claims by the tool's maker.

Four keys, four kinds of copy: each step catches what the one before cannot see

1Exact hash

key: a 64-bit hash of a URL, document, paragraph or line
catches byte-identical copies, recrawls, menu lines
one WARC50 of 2,692 documents
web scaleDolma 3: 67% of its pool

2MinHash + LSH

key: all 8 minimums of one band equal (FineWeb 14 × 8)
catches near copies, Jaccard about 0.75 and up: templates, syndication
one WARC25 more documents (75 on its own)
web scaleDolma 3: 23% removed by this step

3Semantic

key: cosine ≥ 1 − ε inside one k-means cluster
catches paraphrases that share no 5-word phrase
one WARC6 more documents at ε 0.05
50k rowsFineWeb-Edu: 96 of 50,000 at ε 0.05

4Suffix array

key: neighbours in sorted suffix order sharing ≥ 230 bytes
catches a banner or disclaimer repeated inside otherwise unique pages
one WARC14.1 kB cut from 25 survivors (keep one copy)
web scaleDolma 3: 14% of text

measured one WARC: the running example's 2,692 filtered documents through the four steps in this order (the Method comparer runs every combination). published web scale: Dolma 3 (allenai/dolma3 pool README), which runs exact, MinHash and suffix arrays over a whole multi-crawl pool; the semantic number is our run on 50,000 already deduplicated FineWeb-Edu rows (section 8). The gap between the two rows is the point: one file has 2.8% near-duplicate documents; the web has most of its text in copies.

New terms

shingle
a run of n consecutive words (FineWeb: 5); a document becomes the set of its shingles
Jaccard similarity
shared shingles over all distinct shingles of two documents, |A ∩ B| / |A ∪ B|
MinHash signature
k numbers per document, each the smallest hash of its shingles under one hash function
band, candidate pair
a slice of r signature values; two documents equal on a whole band become a candidate pair
connected component
documents linked by any chain of candidate pairs; one is kept per component
suffix array
every position of a text, sorted by the text that follows it, so repeated spans sit next to each other
Bloom filter
a bit array that answers "seen before?" in fixed memory, with no misses and a few false alarms
ε (SemDeDup)
remove a document whose embedding has cosine ≥ 1 − ε to a kept one
scope
the set deduplicated together: a shard, a crawl, every crawl ("global")
rehydration
repeating kept documents in proportion to how many copies dedup removed
All six methods in one table (reference)
MethodUnit and testCatchesMissesCost at web scaleUsed by (dated)
Exact hasha 64-bit or larger hash of each URL, document, paragraph or line; equal hash = duplicatebyte-identical copies, recrawls, menu linesa copy with one changed date or footerone pass, 8 to 16 bytes per item, or a Bloom filtereveryone first: Dolma 3 exact removed 67% of its pool (2025)
MinHash + LSHsets of word n-grams; estimated Jaccard similarity above about 0.7 to 0.85near copies: templates, syndicated text, boilerplate-dominated pagesparaphrases; long shared spans inside different pagessignature of 100 to 9,000 hashes per document, a shuffle by band, union-findGPT-3 (2020), RefinedWeb (2023), FineWeb (2024), Llama 3 (2024), Dolma 3 (2025)
SimHasha 64-bit fingerprint; Hamming distance ≤ knear-identical pages (crawler use)most of what MinHash catches at 0.8 (section 5)8 bytes per document, permuted tablesGoogle's crawler (2007); some Chinese web corpora
Suffix arrayevery repeated substring of at least L tokens or bytesa disclaimer or banner inside otherwise unique pagesnear copies with small edits every few wordsRAM about 8 to 16 bytes per text byte while building; disk 5 to 8 times the textLee et al. (2021), RefinedWeb (2023), Dolma 3 (2025)
Bloom filterexact membership of hashed items (paragraphs, n-grams) in fixed memoryrepeated paragraphs, documents mostly made of seen n-grams (DCLM)anything not byte-identical at the item levelabout 10 bits per distinct item at 1% false positivesDolma (2024), DCLM-baseline (2024)
Semanticcosine similarity of document embeddings inside k-means clustersparaphrases, the same message in other wordsnothing exact; it also removes different-but-similar pagesan encoder pass over every document (GPU), k-meansSemDeDup (2023), D4 (2023), NeMo Curator (2024 on); more in synthetic and SFT data

1. Does deduplication help? Three claims, three kinds of evidence

"Dedup makes models better" merges three claims. The evidence is strong for the first, clear for the second and mixed for the third.

  1. Duplicated text is memorised, and dedup cuts that tenfold. Memorisation means a model reproducing a stretch of its training text verbatim. Lee et al. (2021) trained 1.5B-parameter models on C4 and on two deduplicated versions: unprompted, the original emitted memorised text in 1.926% of its output tokens after one epoch, against 0.189% (NearDup, MinHash) and 0.138% (ExactSubstr, suffix arrays) (Table 4). The cause is the copy count: a sequence present 10 times in training is generated about 1,000 times more often than one present once (Kandpal, Wallace and Raffel 2022, Figure 1).
  2. Skewed repetition wastes compute and can hurt. Hernandez et al. (Anthropic, 2022): an 800M-parameter model "could be degraded to that of a 2x smaller model (400M params) by repeating 0.1% of the data 100 times" (arXiv 2205.10487). Uniform repetition is not the problem: a whole dataset repeated up to about 4 epochs costs almost nothing (Muennighoff et al. 2023, see the data mixing page). The damage comes from a few heavily repeated items, exactly what MinHash's largest clusters are.
  3. Benchmark gains are small and sometimes negative. DCLM compared nine dedup recipes at 1B parameters: every one beat no dedup, by 0.3 to 2.1 Core points, and Exact+MinHash scored below either step alone, so the differences sit near the noise:

Every recipe beats none, but more removal does not mean a better model

published DCLM Table 17 (1B parameters, 1x Chinchilla tokens, a 76B-token pool processed like RefinedWeb). Removal is the share of tokens removed; none is 24.7, Bloom filter 26.8 and Exact+MinHash+SA 26.8 best, Exact+MinHash 25.0. Row values checked against the pool sizes in the same table (for example 45B of 76B left = 41% removed).

The memorisation and benchmark evidence, table by table (depth)
  • Lee et al. (2021, ACL 2022): NearDup is MinHash on space-separated 5-grams, 9,000 hashes, candidates confirmed by Jaccard > 0.8 and edit similarity > 0.8; ExactSubstr removes every repeated span of 50 or more tokens. Table 4 at two epochs: 1.571%, 0.264%, 0.168%.
  • Kandpal et al. (2022): slopes above 1 on a log-log plot of generation rate against copies. On Lee et al.'s models the deduplicated model generated 68,090 training sequences against 1,427,212 for the original, about 21 times fewer (Table 1), and two of three membership-inference attacks lost most of their power (AUROC 0.76 to 0.67 and 0.86 to 0.68; the third, 0.88 to 0.87, barely moved).
  • Carlini et al. (2022, ICLR 2023): memorisation grows log-linearly with model size, with the number of duplicates and with prompt length. On Lee's deduplicated C4 model, sequences repeated fewer than 35 times were memorised at 1.2% against 3.6% for the original; for sequences repeated more than about 100 times dedup "does not help", because the deduplication had missed them (Section 5.2).
  • Hernandez et al.: 90% unique data plus 10% made of a small subset repeated many times. The body puts the loss "nearly as high as for the 340M" model; both figures are read from a figure.
Study (scale)What was comparedResult, from the table
Lee et al. 2021 (1.5B, C4)perplexity of original vs deduplicatedonly plotted (Figure 2): dedup "does not harm, and sometimes improves"; lower perplexity on LM1B and Wiki-40B; higher perplexity on validation examples that had copies in training (it no longer memorised them)
Pythia (2023), 12 sizes, the Pile vs a MinHash-deduplicated Pile (threshold 0.87, 207B tokens vs 300B)zero-shot tasks, Tables 7 and 8"no clear benefit"; at 12B: LAMBADA 0.705 vs 0.710, WinoGrande 0.639 vs 0.660, SciQ 0.902 vs 0.929, WSC 0.548 vs 0.394, mostly within one or two standard errors; the deduplicated models ran about 1.5 epochs, so they saw repeats anyway (arXiv 2304.01373)
Muennighoff et al. 2023 (2.8B and 4.2B, 84B-token budget)unfiltered vs deduplicated (any 100-character overlap removed), Table 14 averageC4: 20.9 vs 19.1 (2.8B), 22.2 vs 20.5 (4.2B), dedup worse; OSCAR (noisier): 19.4 vs 21.2, 21.4 vs 22.8, dedup better. Their text: "deduplication does not help" (Section 7)
FineWeb 2024 (1.71B, 350B tokens)MinHash over all 96 crawls vs each crawl on its ownglobal dedup gave "little improvement"; per-crawl was better (below)
DCLM 2024 (1B, 76B-token pool)9 dedup recipes, Core score (Table 17)the chart above

Cross-crawl dedup: FineWeb's surprise

FineWeb first deduplicated all 96 crawls together, newest crawl first, so a page that appeared in a later crawl was removed from every earlier one. That removed "as much as 90%" of the oldest crawls, and models trained on the 4T tokens left improved little over no dedup. On the oldest crawl, 2013-48:

Per-crawl MinHash gave 20T tokens and matched RefinedWeb; lighter global passes on top (URL dedup, which would remove 71.5% of tokens; line dedup 77.8%; 3-line dedup 80.9%) were all worse (Appendix E.3). FineWeb still deduplicates inside each crawl: what the experiment shows is that at this scale what survives global dedup is a biased sample, not that duplicates are good.

Read the arithmetic
"10% kept, 90% removed" is rounded: 31 / (31 + 460) = 6.3% kept. The paper's text points to Figure 4 for a comparison that is in Figure 3, and the figure values are not given as numbers.
Predict: FineWeb-Edu is about 80% duplicates by a global MinHash. A team deduplicates it globally and trains a 1.8B model on 350B tokens. What happens to the scores?

Nemotron-CC took the other side: it deduplicated globally and still matched DCLM, so the FineWeb finding is an interaction with the rest of a pipeline, not a law. The working rule: dedup tells you the counts; mixing decides how often each document is seen (section 10, rehydration).

What survives global dedup is a sliver, and it trains a worse model than what was removed

2013-48 crawl (31B + 460B)460B removed
kept by global dedup
removed, deduplicated on their own171B

Bars to scale. The about 31B tokens that survived scored worse than the about 460B tokens removed, deduplicated on their own to 171B. FineWeb's hypothesis: pages that never reappear in later crawls are disproportionately low quality, so global dedup "upsamples lower-quality data"; the gain of dedup comes from removing the huge clusters, and deduplicating clusters smaller than about 100 "can harm performance" (published FineWeb Section 3.4).

How much duplication is left in the corpora people train on (depth)
  • DCLM ran FineWeb-style global MinHash on finished datasets: it would remove 85% of DCLM-baseline (built with a 100-shard Bloom filter), 45% of DCLM's own RefinedWeb reproduction, 43% of Dolma v1 (36% without its about 600M empty documents) and 0% of the official RefinedWeb release; DCLM adds these leftover duplicates "do not seem to adversely effect downstream performance" (Table 23).
  • Nemotron-CC's Table 4 is a size table, not an ablation: after global fuzzy dedup, FineWeb-Edu goes from 1.3T to 0.2T unique tokens, FineWeb-Edu-2 from 5.4T to 1.1T, DCLM from 3.8T to 1.0T, Nemotron-CC from 4.4T real to 4.4T (it was deduplicated globally). Implied duplicate shares: 85%, 80%, 74%. The text rounds these to "around 80%".
  • Zyphra (Zyda-2, 2024): "we believe we have found 80% duplicates" in DCLM, and "about 80% for both" DCLM and FineWeb-Edu in the technical report, with MinHash on character 25-grams, 128 hashes, 8 bands (about 85% Jaccard); "80%" is not defined further, and they did not deduplicate DCLM internally for the release because their first ablations showed "only a small effect".

measured Inside one FineWeb shard, and what crawl-wide dedup did to our file. The root lab ran FineWeb's own MinHash (14 × 8) over FineWeb's first CC-MAIN-2024-30 shard: 969,556 rows from 353 other WARC files, plus our 2,692 filtered documents. Inside FineWeb's output, already deduplicated across the whole crawl, it still finds 370 candidate pairs, 14 of them with true Jaccard ≥ 0.8: a MinHash setting misses some pairs by chance, and FineWeb filtered and edited text after dedup. Between our file and the shard it finds 424 candidate pairs, most between 0.5 and 0.8. Of the 214 documents our pipeline kept but FineWeb dropped, 15 have a partner at ≥ 0.8 in those 353 files alone (0.4% of the crawl's 90,000), and none of the documents FineWeb kept has one: consistent with FineWeb's crawl-wide MinHash removing them, partner by partner (root lab, src/dedup/dd_fwshard.py, about 2.5 hours on 4 processes).

Measure at the scope you will deduplicate. Duplicates are pairs: a random 1% sample keeps only 0.01% of the pairs. The running example's one WARC has 2.8% near-duplicate documents; DeepSeek LLM found 22.2% inside one dump and 89.8% across 91.

2. Exact dedup: hashes of URLs, documents, paragraphs and lines

The cheapest duplicates are byte-identical: the same page fetched twice, a mirrored file, the same "Home | About | Contact" line on every page of a site. Hash every unit to 64 or 128 bits, keep the first unit with each hash value, drop the rest. On one machine the "seen" set is a hash table; on many, items are routed by their hash (a shuffle: all items whose hash starts with the same bits go to the same worker), so no worker needs the whole set.

measured On run0's 19,241 extracted documents: 258 exact copies, 284 after normalising (lowercase, no punctuation, digits as 0); of 743,644 non-blank lines, 256,024 (34.4%) repeat an earlier line; the most repeated are "|", "-", "Home" and "Search". After the quality filters, exact document copies fall to 50 of 2,692, all inside MinHash's clusters (root lab).

The unit decides what you catch. Common Crawl already removes repeated URLs inside one crawl, so URL dedup only matters across crawls (Llama 3 keeps the most recent version of each URL across its whole dataset, Section 3.1.1). Document hashes catch mirrors and empty or error pages. Line and paragraph hashes catch boilerplate, and also strip structure (table separators, list markers, repeated headings).

How big must the hash be?

Two different items with the same hash are a collision: the second is wrongly dropped. With n items and a b-bit hash there are n2/2 pairs, each colliding with probability 2−b (the birthday problem). Predict before you change the selects: is 64 bits enough for 1012 lines?

When it matters: always, first: it is a single pass and removes the bulk at web scale. How to check it: count items per hash and read the 50 most frequent; for a line rule, sample removed lines from pages you consider good (Llama 3's own warning, below).

Collisions grow with the square of the item count: pick the bits for the largest set

derived expected colliding pairs = n(n−1)/2 · 2−b, and memory for a plain set = n × b/8 bytes (a hash table needs 1.5 to 2 times more). A 32-bit hash is unusable past a few tens of thousands of items; 64 bits is fine for documents and marginal for 1012 lines.

The code that produced these numbers, and line dedup in practice (depth)
import hashlib, re
def h(s):                       # 8 bytes of SHA-1 is plenty below ~10^9 items (see the calculator)
    return hashlib.sha1(s.encode("utf-8")).digest()[:8]
def norm(s):                    # light normalisation: case, punctuation, digits, spaces
    s = re.sub(r"\d", "0", s.lower())
    return " ".join(re.sub(r"[^\w\s]", " ", s).split())

seen_doc, seen_norm, seen_line = set(), set(), set()
dup_doc = dup_norm = lines = dup_lines = 0
for t in docs:                  # run0's 19,241 extracted documents
    k = h(t);       dup_doc += k in seen_doc;   seen_doc.add(k)
    k = h(norm(t)); dup_norm += k in seen_norm; seen_norm.add(k)
    for line in t.split("\n"):
        if line.strip():
            lines += 1; k = h(line); dup_lines += k in seen_line; seen_line.add(k)
documents 19,241: exact copies 258, after normalising 284
non-blank lines 743,644: repeats of an earlier line 256,024 (34.4%)

measured src/scripts/snippet_exact.py (the code above plus the running example's loader). The root lab's normalisation (datatrove's simplify_text) finds 288 instead of 284.

  • CCNet (used by Llama 1 and the first Dolma) hashes paragraphs within groups of shards of one crawl; in Dolma it "removed approximately 70% of paragraphs, primarily consisting of headers and navigation elements" (Dolma Section 5.1).
  • Llama 3 removes "lines that appeared more than 6 times in each bucket of 30M documents", and notes this removes "frequent high-quality text" too, yet "our empirical evaluations showed strong improvements" (Section 3.1.1). A count threshold rather than "keep the first" keeps a line that recurs a few times, such as a common quote.
  • Dolma v1, all with its Bloom filter (section 7): exact URL dedup removed 53.2% of documents, exact document dedup 14.9% of the rest, exact paragraph dedup 18.7% of paragraphs (Section 5.4). Dolma 3 (2025): exact dedup removed 67% of the pool after heuristic filtering, before MinHash.
  • C4 removed every repeated three-sentence span; datatrove's SentenceDedup implements it (the root lab measured it: 70 of 2,692 documents dropped, 24 shortened).

3. MinHash and LSH: near copies without comparing pairs

The problem. Most web duplicates are not byte-identical: a syndicated article with a different header, a product page that differs by one name, a forum page with a different visitor count. We want pairs whose text is mostly the same among 109 documents, without comparing 5×1017 pairs.

A concrete pair. Normalise two forum pages from the running example (lowercase, no punctuation, numbers normalised), split them into words, and take every run of 5 consecutive words, each kept once: their shingle sets share 43 of 73 distinct shingles, a Jaccard similarity of 43/73 = 0.589. "Near duplicate" means J above a threshold such as 0.75 or 0.8. (FineWeb uses 5-word shingles; Gopher 13; NeMo Curator 24 characters. Short shingles make unrelated documents look alike; long ones let one changed word break many shingles.) The figure follows what MinHash does with this pair, step by step:

Pair
  1. Two pages as shingle sets. Each tile is one shingle. Row A is cboard.cprogramming.com's 68, row B ubuntuforums.org's 48, lined up so the 43 they share stand in the same columns (tinted); 25 belong only to A and 5 only to B.
  2. Jaccard: shared over all. The shared columns rise: J = 43 / 73 = 0.589. Computing it exactly takes one set intersection per pair of documents: 3,622,086 pairs for the running example's 2,692 documents (only 19,675 of them share even one shingle, but you only know that after looking), about 5×1017 for a crawl of 109. MinHash never computes J.
  3. One hash function, keep the minimum. Hash 1 of 112 gives every shingle a pseudo-random number (bar height, as a fraction of its range); a shingle both pages share gets the same number in both. Each page keeps its smallest: here both minimums fall on the shared shingle "to choose the data by". They agree whenever the smallest value over the union lands on one of the 43 shared shingles, which happens with probability exactly J.
  4. Hashes 2 to 8. Seven more functions, played one after another, each sending each page's minimum to the next slot of its signature: 7 of these first 8 slots agree (blue in both signatures), the rest differ (orange).
  5. 112 minimums: the signature. FineWeb uses 112 functions, so each page becomes 112 numbers (896 bytes at 64 bits) whatever its length: 112 GB for 109 documents. 77 of 112 slots agree, an estimate of 77 / 112 = 0.688 against the true 0.589; the standard error at this J is √(J(1−J)/112) = 0.046.
  6. Cut into 14 bands of 8. Each row of a signature is one band of 8 values. A band matches only when all 8 of its values agree in both pages: here only band 8 does; every other band has at least one orange slot.
  7. An equal band lands in the same bucket. Each band's 8 values are hashed to a bucket key and sorted, so pages with an equal band end up side by side and nothing is compared pairwise: these two pages meet in band 8's bucket and become a candidate pair. At J = 0.589 the chance of that is 1−(1−J8)14 = 18.5%: this pair, below the 0.75 target, was unlucky, and run0 did remove one of the two pages.

measured shingles, hash values and signatures computed with datatrove 0.10.1's own MinhashDedupSignature (seed 1, the FineWeb default), checked equal to the signature it writes; hash values are shown as fractions of their range (261−1), the signature's as bar depth; text passed through the running example's PII formatter. Both pages of each pair are site chrome (forum software, a shop template, a network sign-up banner), not anyone's writing.

Why the minimum works

Pick a random hash function h over shingles and keep each document's smallest value, minh(A). Then

P[ min h(A) = min h(B) ] = |A ∩ B| / |A ∪ B| = J(A, B)

Proof (Broder 1997, Theorem 1): look at the smallest value over the union A ∪ B. Every shingle of the union is equally likely to own it. The two minimums are equal exactly when that shingle is in both sets, which happens for |A ∩ B| of the |A ∪ B| shingles.

With k hash functions each document becomes a signature of k minimums, and the share of positions where two signatures agree estimates J without bias. The count of agreements is binomial, so the estimate's standard deviation is √(J(1−J)/k): at J = 0.75 and FineWeb's k = 112, 0.041. Halving the noise costs four times the hashes.

The noise follows the binomial law at every signature size

measured dots: the standard deviation of the estimate for 24 real pairs, each hashed with 2,000 independent families; derived lines: √(J(1−J)/k). The binomial model holds to within a few thousandths at every k.

LSH: bands turn the estimate into a cheap yes/no

Signatures make each comparison cheap, but there are still too many pairs. Locality-sensitive hashing (LSH) avoids comparing pairs at all: cut the k = b×r values into b bands of r rows, and per band group documents by the band's r values (a sort or a hash table). Two documents equal on all r values of at least one band become a candidate pair.

P(candidate | J = s) = 1 − (1 − sr)b

A band matches with probability sr; all b bands fail with (1−sr)b. The curve is an S whose steep part sits near s ≈ (1/b)1/r. FineWeb's 14 × 8 gives 56%, 77%, 92%, 98.8% at 0.70, 0.75, 0.80, 0.85, the numbers its Appendix E.1 states (recomputed here).

Rows sharpen, bands widen. More rows per band make the S steeper and push it right (fewer false candidates, more misses); more bands push it left (higher recall, more candidates, more hashes). Predict, then move the target from 0.75 to 0.9 with 112 hashes: does the rule pick more bands or fewer?

Predict: on the running example, FineWeb's 14 × 8 meets 308 pairs with true Jaccard ≥ 0.8. How many does it miss?

Cost: signatures are documents × shingles × k multiply-adds, embarrassingly parallel; the grouping is one sort per band (a shuffle across machines); memory is k × 8 bytes per document (112 hashes: 112 GB per 109 documents of 64-bit values). How to check it: sample candidate pairs in several similarity bins and read them; compute the true Jaccard of each candidate (cheap: candidates are few); recompute the S-curve and confirm it reproduces any probabilities a paper states before copying its setting (RefinedWeb's "20 buckets of 450" does not; section 10).

Band designer: the S-curve for any (b, r), checked against real pairs

Presets
Bands and rows

The rule is datasketch's: with 128 hashes and equal weights it picks 11 × 11 for a 0.75 target and 9 × 13 for 0.8 (derived with its own code); FineWeb's 14 × 8 is not the rule's optimum for 0.75 (it sits lower, catching more). measured dots: real pairs with Jaccard ≥ 0.01 ( identical shingle sets plus with 1,024-bit equality masks from a hash family drawn with seed 2, independent of the one used to find the pairs), candidate rate per 0.05-wide bin, bands as consecutive slices; derived line and expected counts: 1−(1−sr)b summed over every pair's true Jaccard.

How the band rule chooses, and the presets' sources (depth)

datasketch's MinHashLSH (v2.0.0, lsh.py:21-48) tries every b and r with b × r ≤ the number of hashes and keeps the pair that minimises wfp · (area under the S-curve left of t) + wfn · (area above it right of t), weights 0.5 and 0.5 by default. The areas treat every similarity as equally likely, which real data is not: on the web almost all pairs sit near 0, so a false-positive area that looks small still multiplies by billions of pairs. That is why the designer reports both the measured pairs and the expected candidates over all 3,622,086 pairs of the running example, and why production pipelines add a true-Jaccard check on candidates (Dolma 3) or accept a low r because candidates are cheap to verify.

Presets: published FineWeb paper Appendix E.1 and datatrove minhash.py:51-54; Dolma 3 pool README (allenai/dolma3 @ 1a9daced); NeMo Curator 1.4.0 fuzzy/workflow.py:75-83 (character 24-grams, so not directly comparable with word 5-grams); datasketch defaults lsh.py:149-151; text-dedup's Spark script defaults (tag 2023.09.20, minhash_spark.py:365-370); RefinedWeb Appendix G.3.1 read as 450 bands of 20 (the only reading that reproduces its own probabilities).

The same pair hashed 2,000 times: estimates and candidate rates (depth)

MinHash is a random estimate: a different set of hash functions gives a different signature. We took 24 real pairs from the running example, from Jaccard 0.30 to 0.96, and hashed each with 2,000 independent families of 1,024 functions (datatrove's arithmetic, seeds 1,000 to 2,999). Each family gives one estimate (the share of equal minimums) and one yes/no for "becomes a candidate".

Setting

measured dots: share of the 2,000 hash families in which the pair became a candidate (bands are consecutive slices of the signature, as datatrove's np.split); derived line: 1−(1−sr)b. 26 × 11 is Dolma 3's web setting; 20 × 5 and 9 × 13 are two other shapes for comparison.

In practice the "random functions" are a cheap family: datatrove hashes each shingle once to 64 bits (xxhash), then computes (a·x + b) mod (261−1) for 112 random pairs (a, b) in one vectorised line (minhash.py:182). Because the product is computed in unsigned 64-bit arithmetic it wraps around before the modulus, so the family is not exactly the textbook one; the measurements above (and the root lab's estimate-vs-truth chart) show it does not matter.

Running it with the real tool (code and output)
from datatrove.pipeline.dedup.minhash import MinhashConfig, MinhashDedupSignature
from datatrove.utils.hashing import HashConfig
import numpy as np
cfg = MinhashConfig(hash_config=HashConfig(precision=64))   # FineWeb: 5-grams, 14 bands x 8 rows, seed 1
sig = MinhashDedupSignature(output_folder="/dev/null", config=cfg)
sa, sb = sig.get_shingles(a), sig.get_shingles(b)           # a, b: the two forum pages
A, B = set(sa.ravel().tolist()), set(sb.ravel().tolist())
print(f"shingles {len(A)} and {len(B)}, shared {len(A & B)}, Jaccard {len(A & B) / len(A | B):.3f}")
eq = np.concatenate(sig.get_signature(sa)) == np.concatenate(sig.get_signature(sb))
print(f"equal minimums {eq.sum()} of 112, estimate {eq.mean():.3f}")
bands = eq.reshape(14, 8).all(axis=1)
print("bands where all 8 agree:", (np.nonzero(bands)[0] + 1).tolist(), "-> candidate:", bool(bands.any()))
s = len(A & B) / len(A | B); print(f"P(candidate) at this similarity: {1 - (1 - s**8)**14:.3f}")
shingles 68 and 48, shared 43, Jaccard 0.589
equal minimums 77 of 112, estimate 0.688
bands where all 8 agree: [8] -> candidate: True
P(candidate) at this similarity: 0.185

measured src/scripts/snippet_minhash.py, datatrove 0.10.1. The estimate came out 0.10 above the truth (2.1 standard deviations), one band matched, and a pair below the 0.75 target became a candidate: an 18.5% event that happened. run0 removed one of these two pages.

4. From pairs to clusters: union-find, chaining, and which copy to keep

The problem. LSH outputs pairs, and "remove one document of every pair" is ill-defined when pairs overlap (A~B and B~C). Pipelines treat candidates as edges of a graph and keep one document per connected component (documents linked by any chain of edges).

Union-find (disjoint-set) keeps a forest: every document points to a parent, and a tree's root represents its set. find(x) follows parents to the root; union(x, y) points one root at the other. Path compression (after a find, point every node on the path straight at the root) and union by size (the smaller tree joins the larger) make each operation nearly constant time. datatrove's MinhashDedupCluster does exactly this in a Python dict (minhash.py:537-556), then removes every node that is not a root (579-583). Per band it sorts the signatures and emits only neighbouring equal pairs (minhash.py:471-480), so m identical band values give m−1 edges, not m(m−1)/2: on the running example the 14 bands wrote 810 pair records for only 94 distinct pairs; union-find gives 31 clusters and removes 75 documents. The figure replays run0's real operations on the largest cluster:

  1. 25 pages, one cookie banner. The largest of the 31 clusters: 25 pages from 25 sites whose extracted text is one cookie-consent notice, each starting as its own set. The page in the middle, www.rethinkecon.it, is the one that ends as the root.
  2. Band 1: the first ten unions. Sorting band 1's values puts equal pages side by side, and only neighbours are emitted as pairs (the orange chord). Each pair runs find on both pages and, when the roots differ, points the smaller set's root at the larger's (union by size): every new page joins the growing set (its arrow to the middle).
  3. Band 1: the rest. Nine more unions. Path compression re-points every node on a walked path straight at the root, so the forest stays one level deep and every find takes one step. After band 1, 20 of the 25 pages share one root; 5 are still alone.
  4. Bands 2 to 14 catch the stragglers. The 5 pages band 1 missed join through other bands: 2 in band 2, 2 in band 5, 1 in band 9. The other 219 pair records of bands 2 to 14 find both pages already in one set and change nothing (243 records for this cluster in all).
  5. Keep the root, remove the rest. datatrove removes every page that is not a root: 24 pages go, whatever their own similarity to the kept one. The root is whichever set won the size comparisons, not the longest, newest or best page.
  6. A cluster is a chain. Each page's height is now its true Jaccard with the kept page: from 1.00 down to 0.60 (noe.one-voice.fr), and the least similar two members are 0.49 apart. They joined because each shared a band with some other member, not with the kept page.
  7. Check against the kept page. Dolma 3's fix: remove a member only if its true Jaccard with the kept page is at least 0.8 (the glass plane). The 4 pages below it come back and 20 are removed; over all 31 clusters the check removes 65 instead of 75.

measured candidate pairs regenerated from run0's 14-band signatures the way MinhashDedupBuckets writes them, then datatrove's union-find (recursive path compression, union by size, ties to the first root) replayed operation by operation. The removed set equals run0's remove file exactly (). Only hostnames are shown. The other two large clusters behave differently: in an 8-page consent notice every member has Jaccard 0.83 with the kept page, so the check removes all 7; in the 8-page flower-shop template every member is identical, so nothing changes.

Chaining. A component can join two documents that are not similar at all, through intermediates. In the largest cluster (25 pages from 25 sites whose extracted text is one cookie-consent notice), the least similar member has Jaccard 0.60 with the kept page and the least similar two members are 0.49 apart; they joined through other banner pages and were removed. The fix: Dolma 3 computes the true Jaccard inside each cluster and removes only documents at 0.8 or more (allenai/dolma3 pool README). On the running example that check removes 65 instead of 75: the 10 that come back joined through chains. Lee et al. confirmed candidates with Jaccard and edit similarity > 0.8; RefinedWeb skipped verification to favour recall ("our main concern is improving recall", Appendix G.3.1).

Which copy survives is a choice. datatrove keeps the union-find root, whichever set won the size comparisons: on the running example the kept page is the longest member in 23 of 31 clusters and the lowest document index in 30. FineWeb describes it as "one randomly chosen document" per cluster. Llama 3 keeps the most recent version of each URL; Dolma 3 keeps the most recent copy; Zyda-2 kept the copy from the source it ranked highest (FineWeb-Edu-2, then DCLM, then Zyda-1, then Dolma-CC). A good default for web text: the most recent crawl (fresher content, working links), then the longest extraction. Keep the count: FineWeb-2 stores each kept document's cluster size, so a later step can repeat documents the web repeated (rehydration, section 10).

All 31 clusters of the running example (table)

For each cluster: size, the spread of true Jaccard similarity between any two members (over all 31, the lowest is 0.49), and how many members a 0.8 check against the kept document would still remove.

Connected components at scale (depth)
  • One machine. datatrove's clustering step must run as a single task (assert world_size == 1, minhash.py:533); its example gives that task 2 CPUs with 70 GB each, 140 GB in total, and 90 hours (examples/minhash_deduplication.py:66-84). measured the same dict structure costs about 140 bytes per document that appears in any pair (tracemalloc, 106 nodes in clusters of 4), so 140 GB holds about 109 duplicated documents. A numpy parent array costs 4 to 8 bytes per document instead: scipy's connected_components labelled 107 nodes with 5×106 random edges in about 2.5 s (rough: one core, shared machine).
  • Many machines. Union-find is sequential; distributed systems use label propagation instead. The text-dedup Spark script implements Kiveris et al.'s "large-star / small-star" alternation (each round, every node links to the smallest label in its neighbourhood; about O(log2 n) rounds; minhash_spark.py:38-134 at tag 2023.09.20). NeMo Curator 1.4.0 runs cuGraph's multi-GPU weakly connected components (fuzzy/connected_components.py:20-21, 146).
  • Giant components. A boilerplate cluster can reach a million documents (Zyphra reports a DCLM cluster "close to 1 million documents"); a chain through templates can merge unrelated sets. Inspect the largest components before removing anything.

5. SimHash: one 64-bit fingerprint per document

The idea (Charikar 2002; scaled by Manku, Jain and Das Sarma at Google, 2007). Give every shingle a 64-bit hash. For each bit position, count +1 for every shingle whose hash has that bit set and −1 otherwise; the fingerprint's bit is 1 where the count is positive. Similar documents share most shingles, so most counts keep their sign, and similarity is read as the Hamming distance (differing bits). Each bit is the sign of a random ±1 projection, so two documents disagree on a bit with probability close to θ/π, where cos θ = |A ∩ B| / √(|A| |B|): expected distance 64θ/π, 32 for unrelated documents, 0 for identical ones. Eight bytes per document against 896 for a 112-value MinHash signature.

measured On the running example's 2,692 filtered documents, with the same shingles MinHash uses: at Manku's k = 3, SimHash finds 147 of the 308 pairs with Jaccard ≥ 0.8 (48%), all near-identical; the 308 spread up to 16 bits, and it needs k = 8 to reach 91% (280), and makes its first candidate below Jaccard 0.5 at k = 13. Use it for near-identical detection with a tiny index (crawlers, recrawl detection) or as a cheap first pass; not for catching documents 75% to 90% the same, where MinHash's banding gives a sharp, tunable threshold. text-dedup's benchmark on the CORE dataset agrees (MinHash duplicate recall 0.94 against 0.73 for SimHash, README at commit 7538f3e), and in the Method comparer SimHash at k = 3 removes a single document that exact hashing had not already removed.

At Manku's k = 3 SimHash only sees near-identical pages; pairs at Jaccard 0.8 or more spread up to 16 bits

Google's scale, the permuted-table index, and how well θ/π holds (depth)

"For a repository of 8 billion pages, 64-bit simhash fingerprints and k = 3 are reasonable", with precision and recall both "near 0.75" at k = 3 on their hand-tagged sample (Manku et al., Sections 3 and 4.1). Finding all fingerprints within 3 bits without comparing pairs uses permuted tables: split the 64 bits into blocks; any two fingerprints within 3 bits agree exactly on some choice of blocks, so each table sorts the fingerprints by one choice and only fingerprints sharing it are compared (their Example 3.1: 20 tables, at most 8 fingerprints per probe; or 4 tables, up to 256K per probe). The θ/π law is exact for Gaussian projections (Charikar, Section 3).

measured The 3,602,411 pairs with no shared shingle have mean Hamming distance 31.99 and standard deviation 4.00, exactly the 32 and 4 of a coin-flip model; the closest of them is 13 bits apart. Measured Hamming distance tracks 64θ/π well at the extremes and runs above it for cosine 0.6 to 0.9 (for example 13.7 measured vs 10.7 expected at cosine 0.8 to 0.9): SimHash uses ±1 hash bits on sets of 50 to 200 shingles, where the sign of a short sum ties and flips more often (a likely reason; not tested further here). ROOTS used SimHash and saw false positives on long documents.

6. Suffix arrays: exact repeated spans inside unique pages

The problem. MinHash judges whole documents. A 600-byte disclaimer pasted into a million otherwise different pages leaves each page unique by Jaccard, yet the model reads the disclaimer a million times.

How it works. Concatenate the corpus into one string, with a unique separator after each document so no match can cross a boundary. A suffix array lists every starting position of that string, sorted by the text that follows it. Identical spans then sit next to each other in the sorted order, so one pass comparing each entry with its neighbour finds every span of length L or more that occurs at least twice anywhere, without comparing documents. The figure builds one for two tiny pages:

  1. One string, two pages. Page A, "fresh bread every day we use cookies to improve your experience", and page B, "cheap flights to rome we use cookies to improve your experience", are joined into one token stream with a unique separator after each ($A, $B), so no match can cross a page boundary.
  2. Every position starts a suffix. Each word starts a suffix: the rest of its page from there, 22 of them here (the real tool starts one at every byte or token). In page order, the two copies of the cookie sentence sit far apart.
  3. Sort the suffixes. Sorted by the text that follows, suffixes that begin with the same words land next to each other. The array stores only the sorted start positions, a few bytes each.
  4. Neighbours share a prefix. One pass compares each suffix with the one above it and counts the words they share at the start (the LCP, the numbers on the right). Four neighbouring pairs reach the threshold L = 4 words: the cookie sentence and three of its tails, each once from A and once from B.
  5. Map the matches back to the pages. Each matched start position points into a page, so the 7-word sentence is marked in both A and B, found without ever comparing A with B.
  6. Cut the span. The tool's output lists every occurrence, so deleting the ranges removes the sentence from both pages; Dolma 3 keeps one copy (A's here) and removes the rest.

illustrative two invented pages; the stage computes this suffix array in the page (Sorting the suffixes puts every copy of a span next to its twin). Suffixes start at every word to keep the stack short, and suffixes that start at a separator are left out.

Lee et al. remove every repeated span of 50 or more tokens: their plot of matches against length bends at about 10 tokens, and reading matches of 25 tokens found no false positives, so they doubled it (Appendix B). On raw text that is about 50 × 4.68 = 234 bytes on the running example (4.68 bytes per GPT-2 token, measured); RefinedWeb used 50 tokens after MinHash, Dolma 3 used 500 bytes. measured on the 2,692 filtered documents: bytes at 230 mark 2.50% of the text (146 documents touched); tokens at 50 mark 2.36% (144 documents, all among the 146).

"Remove" means every copy
The tool's self-similar output lists every occurrence of a repeated span, the first included (main.rs:900-922), so deleting the ranges deletes the text everywhere. Keeping one copy (Dolma 3: "we ensure we keep at least one copy") removes 1.08% instead of 2.50% here. Keep one if the span is content (a quote, a licence you want once); remove all if it is boilerplate. Lee et al. also ran the whole process twice, because cutting spans creates new repeats across the cut points (README line 246).

Repeated spans grow with the scope

FineWeb's output, already deduplicated per crawl, still has 0.30% of its text in repeated spans of 230 bytes within its first 4,000 rows, 0.46% within 16,000 and 0.55% within 48,000 (more WARC files, more chances for a shared disclaimer). The curated corpora sit low at equal sample size (16,000 documents): FineWeb-Edu 0.21%, DCLM-baseline 0.18%, Nemotron-CC high 0.08%, against 2.50% in the running example before MinHash. A sample this small says little about a whole corpus (DCLM-baseline is 85% duplicates by a global MinHash); it says that a random slice of these corpora carries little boilerplate.

When it matters: after MinHash, for boilerplate inside unique pages (cookie text, legal footers, shop policies); RefinedWeb, Nemotron-CC and Dolma 3 use it, FineWeb and DCLM do not. DCLM's Table 17 found suffix arrays alone the strongest single step at 1B scale (26.6 Core, 33% removed). Cost: RAM 7 to 15 bytes per text byte while building, so it runs per shard at web scale (Nemotron-CC "over eighths of snapshots", Dolma 3 on 56 shards). How to check it: read the 50 longest and the 50 most repeated spans, and count documents left with almost nothing (the tool can empty a page that was all boilerplate).

MinHash leaves span-level repetition behind, and more files means more of it

Construction (SA-IS), tokens against bytes, and measured and published costs (depth)

Sorting n suffixes naively costs O(n log n) comparisons of long strings. SA-IS (Nong, Zhang and Chan, 2009) builds the array in linear time: it classifies each position as S-type or L-type (is its suffix smaller or larger than the next one), sorts only a subset of "LMS" substrings (at most half the positions), recursively solves the smaller problem, and induces the order of every other suffix from those in two linear scans. Google's deduplicate-text-datasets (Lee et al.'s tool) vendors an SA-IS implementation with 64-bit indices (src/table.rs:52-62, 115, 391-511 at 4e9888ac). For files larger than memory allows, scripts/make_suffix_array.py builds arrays of chunks in parallel and merges them with a heap; chunks overlap by HACK = 100000 bytes (line 23), so the merge is only correct when no repeated span is longer than that, which holds for documents of normal length. The root's Dedup lab builds a small suffix array live in the browser.

Tokens or bytes. With --tokenize the tool stores GPT-2 token ids as 2 bytes each, so 50 tokens is a threshold of 100 bytes. On the running example the share cut per document by the two forms correlates at 0.997. One quirk: the tool compares bytes, so in token mode a match can start in the middle of a 2-byte token id; 18 of 216 ranges did. Use an even threshold and align ranges to token boundaries when you cut.

  • measured (rough: shared machine, one core for make, low priority): building the array for 13 MB, 54 MB and 162 MB of FineWeb text took about 7 s, 47 s and 310 s, with peak memory 15, 11 and 7 bytes per text byte, and an array file of 3 to 4 bytes per text byte (the tool stores the smallest pointer width that addresses the file: 5 bytes at about a terabyte, 6 at hundreds of terabytes).
  • published Lee et al.: one machine with 96 cores and 768 GB built C4's array (350 GB) in under 12 hours, about 1,000 CPU-hours; finding the duplicates took under an hour more; Wiki-40B (4 GB) took 2.3 minutes. They describe an "8x space overhead" and a 1.5 TB array for C4; 1.5 TB over 350 GB is 4.3 times, so the 8 times is the 8-byte in-memory index per byte, not the file on disk. The README asks for more than 600 GB of RAM and 1 TB of disk for C4.

7. Bloom filters: exact dedup in fixed memory, and DCLM's near-dup variant

The problem. Exact dedup of paragraphs or n-grams across a corpus needs a "seen" set of 1011 to 1013 items: at 8 bytes each, terabytes.

How it works. A Bloom filter is an array of m bits and k hash functions. Adding an item sets its k bits; testing checks whether all k are set. It never misses an item it has seen, but can say "seen" for a new item whose bits were all set by others, a false positive. The figure adds two lines and tests a third:

  1. An empty filter. 16 bits, all 0, and 3 hash functions. A real filter holds billions of bits.
  2. Add "Home". Its three hashes point at bits 2, 7 and 11, which are set to 1. Nothing about the line itself is stored.
  3. Add "Search". Bits 4, 7 and 13: bit 7 was already set by "Home", so the two lines share it. 5 of the 16 bits are now set.
  4. Test "Login": a false positive. A new line whose hashes point at bits 2, 4 and 13. All three were set by the other two lines, so the filter answers "seen" and the line is wrongly dropped. A filter never misses a line it has seen; it can only raise false alarms like this one.

illustrative 16 bits and 3 hash functions with made-up hash values (two lines fill the bits a third line needs: a false positive); a real filter fills to about half its bits set at the best k.

After n items the false-positive rate is about (1−e−kn/m)k. The best k is (m/n) ln 2, which gives m/n = −ln p / (ln 2)2 bits per item for a target rate p: 9.6 bits at 1%, 14.4 at 0.1%, 57.5 at 10−12 (derived). In dedup a false positive drops one unique item, which is acceptable at 1%. The root lab checked the Dolma toolkit's filter against this formula (closed block below). How to check it: run the filter on a sample where a plain Python set gives the true answer and count the difference; log the fill ratio at the end of each shard.

DCLM's BFF: near-duplicates with a Bloom filter

DCLM-baseline was deduplicated with a modified "Big Friendly Filter": cut each paragraph into 13-grams and test every 13-gram against one filter holding all 13-grams seen so far. A paragraph is removed when more than 80% of its 13-grams were seen; a document when more than 80% of all its 13-grams were (published DCLM Appendix L; false-positive rate 0.01). Unlike MinHash it compares a document with the whole corpus seen so far, in one streaming pass. Memory decides the scope: the DCLM pool was about 70 TB, so they ran 100 shards of about 700 GB each, deduplicating within each shard only, and the shard size changes the answer:

Quality was not hurt: at 7B parameters and 2x tokens, the Bloom filter and MinHash plus suffix array scored within 0.2 Core points of each other (45.3 vs 45.5, Table 19), and the Bloom filter is "vastly more efficient" than a MinHash and suffix-array pipeline.

The same filter removes more as the shard grows: most duplicates sit across shards

114B tokens29%
227B tokens35%
341B tokens40%
455B tokens43%
569B tokens46%

published DCLM Table 22: share of tokens the BFF removes against shard size (bar length = share removed, axis to 50%). Consistent with a global MinHash still removing 85% of DCLM-baseline (Table 23).

Measured false positives, memory arithmetic and Dolma 1.7's variant (depth)
  • measured The root's Dedup lab ran the Dolma toolkit's filter on the running example's 743,644 lines with filters from 64 KiB to 64 MiB: false positives matched the streaming formula within about 1% (1 MiB, 17 bits per distinct line: 11 to 14 lines wrongly dropped), and it found that --dedupe.min_words above 0 silently turns paragraph dedup off in dolma 1.2.1 (deduper.rs:339-353).
  • DCLM: a 1T-token corpus with a false-positive rate of 10−12 "would require 6.5TB of RAM" (1012 13-grams at 57.5 bits each is 7.2 TB, or 6.5 TiB: it reproduces in binary units); at 0.01, 1.2 bytes per 13-gram. Settings: min and max n-gram 13, threshold 0.8.
  • Dolma 1.7 used the same idea as "fuzzy deduplication": a paragraph's score is the share of its 13-grams repeated across Dolma CC, RefinedWeb and C4; documents with a length-weighted score above 0.3 and paragraphs above 0.8 are removed: 48% of Dolma CC tokens, 10% of C4, 12% of RefinedWeb (Ai2 blog, April 2024).

8. Semantic dedup: SemDeDup and D4

The problem. Two pages can say the same thing in different words and share no 5-word phrase: Jaccard near 0. Paraphrase-level redundancy is common in synthetic data, instruction sets and spam.

How it works. An encoder (a model that maps a text to a vector so that texts with similar meaning land close together) embeds every document. Comparing all pairs is again quadratic, so SemDeDup (Abbas et al. 2023) first clusters the vectors with k-means, then inside each cluster removes a document whose cosine similarity to a kept one is at least 1−ε. NeMo Curator 1.4.0 runs this on GPUs with embeddinggemma-300m, 100 clusters and ε = 0.01 by default, keeping the members farthest from the centroid first ("hard"; stages/text/deduplication/semantic.py:80-92). D4 (Tirumala et al. 2023) adds a second step: k-means again and drop the documents closest to their centroid, the most typical ones, until a target size.

measured Does the encoder matter? The 2,692 filtered documents embedded with three encoders on CPU (4 threads, low priority): arctic-embed-m (the FineWeb-Edu classifier's backbone, root lab), bge-small-en-v1.5 (440 s) and all-MiniLM-L6-v2 (100 s), then SemDeDup with 20 k-means clusters.

  • Similar counts, different documents. At ε = 0.05 the three encoders remove 62, 59 and 57 documents, but only 34 are removed by all three and 85 by at least one. At ε = 0.1: 72, 72 and 67; 38 by all three, 104 by any.
  • A fixed ε does not transfer between encoders. The median cosine between two unrelated documents is 0.21 for arctic, 0.49 for bge-small and 0.05 for MiniLM; the lowest cosine among pairs with Jaccard ≥ 0.8 is 0.71, 0.80 and 0.74. Calibrate ε on labelled pairs for each encoder before trusting NeMo Curator's default.
  • What D4 prunes depends on what came before. On the raw running example the most typical documents are short corporate and shop pages, so prototype pruning acts like a light quality filter. On 50,000 FineWeb-Edu rows, already selected by a quality classifier, "typical" means the classifier's favourite kind of page, and D4 removes it (details below).

Published results are modest (closed block below): no loss on LAION at 37% removed, a perplexity match for C4 with less data, small downstream gains for D4 at 6.7B, and no gain as DCLM's selection step. When it matters: synthetic and instruction data, after exact and MinHash dedup. Cost: an encoder pass over every document plus k-means. How to check it: read the removed pairs at the chosen ε, especially pairs with low Jaccard: on this file they are cookie notices from different plugins and casino spam (root lab), but at looser ε real pages start to go.

Three encoders remove similar counts but different documents

D4 on the running example and on 50,000 FineWeb-Edu rows (GPU run) (depth)

measured After SemDeDup (ε 0.05, 2,630 left), keeping 80% by D4's rule prunes the 476 most typical documents: median length 1,057 characters against 2,156 for those kept, median FineWeb-Edu score 0.62 against 1.10, and only 19 of the 159 documents scoring ≥ 2.5 (FineWeb-Edu's keep line).

measured At 50,000 documents (FineWeb-Edu, CC-MAIN-2024-30, random row groups), on the GPU. With arctic-embed-m and 100 clusters, SemDeDup removes 3 documents at ε 0.01 (NeMo Curator's default), 96 at 0.05, 302 at 0.1 and 866 at 0.15: an already deduplicated, quality-filtered set has little paraphrase redundancy until ε gets loose. Keeping 80%, the pruned documents have a slightly higher median FineWeb-Edu score than the kept ones (3.02 vs 2.91), and keeping 40% prunes 14,560 of the 21,939 documents scoring ≥ 3. Run with sh src/scripts/run_pending.sh d4-fwedu50k.

What the semantic-dedup papers report, in full (depth)
  • SemDeDup (arXiv 2303.09540): on LAION image-text pairs (k = 50,000 clusters), removing 37% caused no drop and removing 50% cost under 0.5% of zero-shot accuracy. On C4 with OPT-125M (k = 11,000), keeping 80% after SemDeDup matched the perplexity of keeping 96.1% after NearDup. The training-time saving is stated three ways: 15% (introduction), 10% to 15% (Section 5.2), 5% (Figure 8's example). Perplexity at 4% pruned (Table A12): baseline 38.95, NearDup 39.46, random 39.51, SemDeDup 39.35 on C4: pruning anything raised perplexity a little.
  • D4 (arXiv 2308.12284): SemDeDup first (keep 75%), then "SSL prototypes". At 6.7B parameters and 100B tokens: about 20% fewer steps to reach the baseline's perplexity and up to 2% better average downstream accuracy. Table 1 (1.3B, 40B tokens): D4-selected 20B tokens repeated twice beat 40B random tokens once on non-web perplexity (16.10 vs 16.27) and instruction perplexity (13.85 vs 14.19). Selection always hurt perplexity on a held-out web snapshot: it trades web typicality for diversity.
  • DCLM Table 4: SemDedup used as the selection step scored 27.1 Core against 27.5 for no model-based selection; as a quality filter on its own it did not help.

9. Dedup at scale: what has to fit in one machine

At 109 to 1010 documents every method is a distributed job, and its design is decided by which state must sit in one machine's memory. A distributed MinHash job has four stages:

  1. Signatures, embarrassingly parallel: each worker reads a shard and writes, for every band, (band hash, document id). datatrove writes one file per band per worker.
  2. Group by band value: a shuffle (all records with the same band hash go to the same worker), or, as datatrove does, each band's files sorted on disk and merged with a heap; workers split each band's hash range (minhash.py:391-399).
  3. Connected components over the candidate edges: single-machine union-find (datatrove), label propagation in Spark or Dask (text-dedup, TxT360), or cuGraph on GPUs (NeMo Curator).
  4. Filter: every worker drops the ids on its remove list as it rewrites its shard.

Predict which state outgrows a machine first at 1010 documents, then set the corpus:

The rough numbers measured here (seconds on a laptop core for megabytes) do not extrapolate linearly: at scale the cost is dominated by I/O and the shuffle, which a single machine never shows. No FineWeb, RefinedWeb or DCLM paper gives a CPU-hour figure for its MinHash step.

MinHash signatures and suffix-array builds outgrow one machine first; document Bloom filters and parent arrays stay small

derived from the formulas in each row; per-item sizes measured here where marked. Compute is not shown: MinHash signatures are documents × shingles × hashes multiply-adds and parallelise perfectly; an encoder pass is the dominant cost of semantic dedup.

Published costs, dated, vendor claims marked (reference)
JobHardware and timeSource
Suffix array of C4 (350 GB)1 VM, 96 cores, 768 GB RAM: under 12 h (about 1,000 CPU-hours); dedup under 1 h moreLee et al. 2021, App. B published
NearDup MinHash on C4Google's production system, about 41.5 kWhLee et al. 2021, App. A published
CCNet paragraph dedup (one crawl)hashes of 50 shards (3% of a crawl): 1.5B hashes in 40 GB RAM; the whole CCNet pipeline 8.5 h per crawl on 5,000 coresWenzek et al. 2019 published
SlimPajama: global MinHash over RedPajama (1.2T tokens)64 CPU cores, 1.4 TB peak memory; 49.6% of bytes removedShen et al. 2023 published
text-dedup Spark MinHash, 42M rows160 cores, 640 GB: under 40 min (the Python version: about 10 h on 80 cores, 1.8 TB)README, tag 2023.09.20 published
TxT360: 48.83B documents, 99 crawlsexact (Bloom, capacity 109, 0.1%) removed 17%; MinHash 9 × 13 on 13-grams: 20 TB of hashes, 9.2 TB of pairs, pair dedup about 5 days in parallel (25 days serial)TxT360 blog (Oct 2024) published
DCLM-baseline BFF (about 70 TB)100 shards of about 700 GB, single-node Rust tool; AWS i4i instances recommendedDCLM App. L; dclm dedup README published
NeMo Curator fuzzy dedup, RedPajama v2 subset3 H100 nodes 0.65 h vs a CPU alternative 10.7 h (about 16x); 1, 2, 4 H100 nodes: 2.05, 1.01, 0.50 h on "8 TB (1.78 trillion tokens)"; another page: "1.96 trillion tokens in 0.5 hours using 32 NVIDIA H100 GPUs"NeMo Curator 1.4.0 README and docs vendor, figures disagree with each other
NeMo Curator, RedPajama (4.5 TB), 202337 h on 20 CPU nodes (48 cores) vs 3 h on 4 DGX A100NVIDIA blog, Aug 2023 vendor
Zyda-2 (12B documents, 11.5T tokens; filtering and dedup together)about 2 days on 8 GPU nodes vs about 3 weeks on 8 CPU nodesZyphra blog, Oct 2024 vendor-adjacent (co-published with NVIDIA)

10. Recipes, rehydration and contamination

What production corpora do. Almost every recipe runs exact dedup first and MinHash second; they differ in scope, in whether candidates are verified, and in which copy survives. FineWeb runs MinHash 14 × 8 inside each crawl with no verification; Dolma 3 runs MinHash 26 × 11 over 32 shards, checks true Jaccard 0.8 inside clusters, keeps the newest copy, then a keep-one suffix array; DCLM-baseline uses only a Bloom-filter BFF within 100 shards; TxT360 and Llama 3 deduplicate globally. The full table, with sources, is below.

Two settings that do not mean what their prose says
RefinedWeb writes "20 buckets of 450 hashes", but its own probabilities (76% at 0.75, 99.4% at 0.8) only come out of 450 bands of 20 rows; read literally, 20 bands of 450 rows would match only identical shingle sets (the root lab measured 143 candidates, all with Jaccard 1). Lee et al. and D4 use the same reversed naming. Dolma 3's README says its PDF data used "the same parameters as FineWeb ... 14 bands of size 5", which is not FineWeb's 14 × 8. Recompute the S-curve before copying a setting.
Dedup recipes of 17 corpora people train on (reference table)
Corpus (date)ExactFuzzySubstring / otherScope, kept copy, removed
C4 (2019)every repeated 3-sentence spanone crawl
GPT-3 (2020)Spark MinHashLSH, 10 hasheswithin each dataset; about 10% smaller
The Pile (2020)datasketch MinHashLSH, 10 hashes, Jaccard 0.5within Pile-CC (26% duplicates) and OpenWebText2 (28%) only, "due to memory constraints"
Gopher / MassiveText (2021)documentsMinHash, 13-grams, Jaccard > 0.8, one removed at randomplus within-document repetition rules (Table A1)all subsets except Wikipedia and GitHub
Llama 1 (2023)CCNet lines; GitHub filesbooks with > 90% overlapper crawl
RefinedWeb (2023)URL across 100 partsMinHash 5-grams, 9,000 hashes, 450 bands of 20, no verificationsuffix array, spans > 50 tokenseach 1/100 of every crawl; 12% of documents removed as duplicates
SlimPajama (2023)MinHashLSH, 13-grams, Jaccard 0.8global over RedPajama; 49.6% of bytes removed
RedPajama v2 (2023)Bloom filter, 1% errorsignatures shipped for 0.7 to 1.0 (128 hashes: 14 × 9, 9 × 13, 5 × 25, 1 × 128)newest crawl first; fuzzy left to the user
DeepSeek LLM (2024)method not named; 91 dumps together removed 89.8% of documents vs 22.2% within one dump (Table 1)global
Dolma v1 (2024)URL 53.2%, document 14.9%, paragraph 18.7% (Bloom)CCNet paragraphs firstper crawl, then whole corpus
DCLM-baseline (2024)BFF: 13-grams, 0.8 of a paragraph or document seen100 shards of about 700 GB
FineWeb (2024)MinHash 5-grams, 14 × 8, no verificationeach crawl alone; one document per cluster
Llama 3 (2024)URL, newest keptglobal MinHash (parameters not given)lines seen > 6 times per 30M documentsglobal
Nemotron-CC (2024)global fuzzy, NeMo Curator (parameters not given)suffix array over eighths of crawls99 crawls, global
TxT360 (2024)Bloom, 17%MinHash 13-grams, 9 × 13, Jaccard 0.899 crawls global; duplicate counts kept for upsampling
Zyda-2 (2024)NeMo Curator, character 25-grams, 128 hashes, 8 bandsacross its 4 sources only; best-ranked source kept
FineWeb-2 (2025)MinHash as FineWeb (14 × 8), per languageglobal per language, before filtering; cluster size kept
Dolma 3 (2025)67% of the poolMinHash 5-grams, 26 × 11, true Jaccard 0.8 inside clusters, newest kept; 23%suffix array, spans ≥ 500 bytes, keep one; 14% of text32 shards for MinHash, 56 for suffix arrays

published sources: C4 (Raffel et al. 2020), GPT-3 App. A, the Pile App. D.2, Gopher App. A.1.1, Llama 1 Section 2.1, RefinedWeb Section 3.3 and App. G, SlimPajama-DC Section 2.3, RedPajama v2 (Weber et al. 2024, Section 4.1, and the RedPajama-Data README), DeepSeek LLM Section 2.1, Dolma Sections 5.1 and 5.4, DCLM App. L, FineWeb Section 3.4, Llama 3 Section 3.1.1, Nemotron-CC Section 2, TxT360 blog, Zyda-2 blog, FineWeb-2 Sections 4.3 and 4.5, allenai/dolma3 pool README (1a9daced). Empty cells: not stated by the source. Qwen2, 2.5 and 3 reports do not describe their dedup. The Pretraining corpora page has each corpus's lineage, size and licence.

Rehydration: dedup gives the counts, mixing decides

TxT360 deduplicated 99 crawls globally and kept each document's duplicate count, then upsampled heuristically: weight 3 for 2 to 5 copies, 5 for 5 to 100, 8 for 101 to 1,000, 10 above 1,000. FineWeb-2 made it data-driven: per language, measure the filtering rate of documents by cluster size (as a quality proxy), give weight 10 to the cluster size the filters remove least, weight 1 to sizes removed more often than average, and interpolate; for French the curve is U-shaped, with both unique documents and the most repeated 0.1% filtered more than average (FineWeb-2 Section 4.5). Its card warns: "If you do not upsample based on these weights, dataset performance may be lower." The data mixing page covers repetition budgets.

Dedup does not decontaminate

Contamination means benchmark items in the training data; the decontamination page owns detection and removal. Within-corpus dedup keeps one copy of every test item it finds, by design; removing benchmark text needs a dedup across two sets, the training corpus against the evaluation sets, with the same machinery (datatrove's MinHash against a prebuilt index, index_folder; Google's tool's across-similar; Dolma seeds its Bloom filter with test items). What dedup does buy: fewer copies, less memorisation of whatever leaked (Kandpal et al.: generation rate grows super-linearly with copies).

How much test text sits in standard training sets (depth)

Lee et al. found near-duplicates in the training set for 4.6% of C4's validation examples, 14.35% of RealNews', 4.92% of LM1B's and 0.72% of Wiki-40B's (Table 2). A published Transformer-XL trained on LM1B has perplexity 10.11 on LM1B validation examples that have training copies against 23.58 on the rest; GROVER-XL on RealNews, 7.68 against 9.45 (Table 5). Their policy: keep the test copy, drop the training copy. No source measures a percentage reduction in benchmark contamination from dedup alone (searched; not confirmed). The decontamination page measured the running example and whole FineWeb shards directly against seven benchmarks.

11. Interview rehearsal

Nine questions with short answers (optional)
Prove that the min-hash collision probability equals Jaccard similarity.
Under a random permutation the minimum over A ∪ B is equally likely to be any element of the union; the two minimums agree iff that element is in A ∩ B. So P = |A ∩ B| / |A ∪ B|.
How many hashes do you need to estimate J to ±0.02?
The estimate is binomial, sd = √(J(1−J)/k). At J = 0.8 and two standard deviations within 0.02: k ≥ 4 × 0.16 / 0.0004 = 1,600. For a yes/no decision with LSH you need far fewer, because the S-curve, not the estimate, decides.
Choose b and r for a 0.8 threshold with 128 hashes.
Steep point near (1/b)1/r ≈ 0.8. datasketch's rule (minimise weighted areas of false positives and negatives) gives 9 × 13; RedPajama v2 ships exactly that. More rows, sharper and fewer false positives; more bands, higher recall.
Why union-find, and what goes wrong with it?
It turns candidate pairs into groups in near-linear time (path compression, union by size). Chaining joins dissimilar documents through intermediates; giant components appear on boilerplate. Verify inside clusters and inspect the largest.
MinHash or SimHash for an LLM corpus?
MinHash: a tunable, sharp threshold at 0.7 to 0.9. SimHash at 64 bits and k = 3 finds near-identical pages with 8 bytes per document; on the running example it found 48% of pairs with Jaccard ≥ 0.8. ROOTS used SimHash and saw false positives on long documents.
When would you add a suffix-array pass?
When boilerplate spans survive inside unique documents (cookie text, disclaimers), after MinHash, per shard, at about 50 tokens (230 bytes of English) or 500 bytes, keeping one copy of content spans. Memory: the text plus 8 to 16 bytes per byte while building.
Does dedup improve benchmarks?
It cuts memorisation about tenfold (Lee et al.) and waste from skewed repetition (Hernandez et al.); benchmark gains are small and mixed (Pythia: no clear benefit; Muennighoff: worse on C4, better on OSCAR; DCLM: +0.3 to +2.1 Core at 1B). Global dedup of an already filtered set showed no gain (FineWeb, FineWeb-Edu).
System design: deduplicate 100 Common Crawl snapshots (about 1010 documents) for a pretraining run.
1. URL dedup across snapshots keeping the newest capture (a sorted join on URL). 2. Exact document hashes (or a Bloom filter at 0.1%: about 18 GB for 1010 items). 3. MinHash on word 5-grams, about 128 to 286 hashes, signatures computed per shard (10 to 23 TB at 64 bits; 32-bit values halve it), grouped per band by a shuffle on band hash; connected components by label propagation (Spark/Dask) or GPU cuGraph; verify true Jaccard ≥ 0.8 inside clusters; keep the newest copy and record cluster size. 4. Optional suffix-array pass per shard for boilerplate spans, keep-one. 5. Decontaminate against the eval suite with the same tools. 6. Decide scope by ablation: per-snapshot vs global with rehydration weights; log removals per step and read samples of each. Cost driver: the shuffle and the components step, not hashing.
Semantic dedup on a 10M-example instruction set: how?
Embed with a small encoder on GPU (minutes to hours), k-means into about √N to N/1000 clusters, SemDeDup within clusters, ε calibrated on hand-labelled pairs for that encoder, keep the best-scored example of each near-duplicate group rather than the farthest from the centroid; read removed pairs per task type before applying.

Scripts and outputs: src/scripts/ and src/data/out/ of this page, plus the root lab's src/dedup/.