Deduplication and Decontamination

Dive into Deep Learning · §20.3

Deduplication and Decontamination
exact hashes · MinHash · banding and the S-curve · substrings · embeddings · test-set leakage

One Blog Post Contains Another, and Their Hashes Share Nothing

The problem

Two posts on one music blog in FineWeb’s output: the second is the first plus one paragraph.

measure value
SHA-256 equal no
Jaccard of 5-word shingles, J 0.70
share of the shorter found in the longer, C 1.00

Exact comparison of all pairs, about 8 µs per pair:

documents time
20,000 half an hour
10^9 about 10^5 years

The method has to avoid comparing pairs, not compare them faster.

By the End of This Deck You Can

Goals

  • find exact copies and shared lines with hashes;
  • prove that a MinHash position agrees with probability J;
  • derive the banding S-curve and choose (b, r) on labelled pairs;
  • explain what suffix arrays and embeddings catch that MinHash cannot;
  • measure what n-gram and embedding decontamination miss, with planted items.

Running example: 26,000 FineWeb documents (the audit stream plus 6,000 same-host pages) and c1, our 1,032 crawl documents after the rules.

Six Steps From a Crawl Record to a Token on Disk

Where this fits

step section
get text Document Extraction from Web Crawls
choose text Quality Filtering
Deduplication and Decontamination
mix text Data Mixtures
Synthetic and Rephrased Data
cut text Tokenizers at Scale
  • Here: c1 → exact → near → decontam → c2, and the version-1 manifest.
  • Skips: how often a text should be seen.

FineWeb Has No Exact Copies, but One in Fifteen Pages Shares a Line

Exact duplicates

corpus documents exact copies documents with a shared line
FineWeb slice 26,000 0 1,742
c1, our crawl 1,032 12 73
  • Most shared: a card-payment notice (36 pages), shop review notices, “Your email address will not be published”.
  • Shared lines are a span problem: C4 kept one copy of every repeated three-sentence span.

Deduplicate before the train/validation split, or validation loss measures memory.

Resemblance and Containment of Shingle Sets

Similarity as set overlap

Shingles: runs of 5 words (NFC, lower case, \w+).

J(A,B) = \frac{|A\cap B|}{|A\cup B|}, \qquad C(A,B) = \frac{|A\cap B|}{|A|}

  • A \subseteq B: C = 1, J = |A|/|B|; a truncation to f has J \approx f.
  • Substitution rate q keeps about x = (1-q)^5 of the shingles: J = x/(2-x), so 2% gives 0.82 and 5% gives 0.63.
  • Random pages: J = 0 up to the 99th percentile; same host: 0.32.

Hash shingles with blake2b. Python’s hash is salted per process.

Check: 100 Shingles Inside a Page of 1,000. A Duplicate?

Check

Every shingle of a short page occurs in a long one. J? C? Does MinHash at \tau = 0.8 flag the pair?

Answer. J = 100/1{,}000 = 0.1, C = 1. A pair at J = 0.1 is almost never a candidate. Containment needs its own test; under J, a short copy is a different document.

One Random Order: Agreement Has Probability J

MinHash

h_\pi(A): the shingle of A that comes first in a random order \pi.

Let x^* be the first element of A \cup B, uniform over the union.

  • x^* \in A \cap B: both minima are x^*, they agree.
  • x^* \in A \setminus B: A’s minimum is x^*, B’s comes later.

\Pr[h_\pi(A) = h_\pi(B)] = \frac{|A\cap B|}{|A \cup B|} = J

k orders: \hat J = share of agreeing positions, a binomial count, \operatorname{Var}\hat J = J(1-J)/k.

128 Numbers per Document, Bit-Exact to a Specification

The signature

step choice
shingle hash blake2b, 8 bytes, little-endian, mod p = 2^{61}-1
position i \min_x (a_i x + c_i) \bmod p
(a_i, c_i) default_rng(0xD2), integers in [1, p)
product a_i x exact: 122 bits; NumPy uint64 overflows silently

Checks on 200 pairs per J and on the fixture:

  • bias within 2 standard errors in every bin; variance 0.88 to 1.16 × formula;
  • 5 of 5 fixture signatures equal to a Python-integer reference.

95% half-width at J = 0.8: 1.96\sqrt{0.16/128} = 0.069.

Bands Turn the Signature Into Hash-Table Lookups

Banding

k = br positions as b bands of r; a shared band bucket makes a candidate.

P(s) = 1 - (1 - s^r)^b, \qquad s^* = \Bigl(\frac{r-1}{br-1}\Bigr)^{1/r} \approx \Bigl(\frac{1}{b}\Bigr)^{1/r}

(b, r) P(0.5) P(0.8) P(0.9) steepest
(2, 2) 0.44 0.96 0.58
(14, 8), FineWeb 0.053 0.92 0.71
(9, 13) 0.40 0.84

FineWeb’s paper: 0.56, 0.77, 0.92, 0.988 at 0.7 to 0.85. Reproduced.

Measured Candidate Rates Follow the Curve

The S-curve, measured

12,000 labelled pairs: 6,000 edited copies, 6,000 negatives; label J \geq 0.8.

13 settings × 3 hash seeds × 0.05-wide bins of J; expected count \sum_i P(J_i), exact Poisson-binomial 95% interval.

value
cells with n \geq 30 780
outside their interval 19 (2.4%)
bound at the 0.999 level 59
(9,13), bin 0.80 to 0.85 expected 445 [418, 473]; seeds 431, 438, 429

A flawed hash would leave many cells outside.

Choosing (b, r) Like a Hyperparameter

Tuning

E(b,r) = w_{\textrm{fp}}\!\int_0^\tau\! P\,ds + w_{\textrm{fn}}\!\int_\tau^1\!(1-P)\,ds \;\Rightarrow\; (9, 13) \textrm{ at } k = 128,\ \tau = 0.8

test pairs precision recall F1
(11, 11), chosen on train, w_{\textrm{fn}} = 1 0.86 0.89 0.87
(9, 13), minimum of E, datasketch 0.90 0.77 0.83
(14, 8), FineWeb, 112 positions 0.72 0.99 0.83

(11, 11) - (9, 13): F1 +0.04 [+0.03, +0.05]. w_{\textrm{fn}} = 5 chooses (14, 9): fewer rows, as predicted.

Check: Why Do the Pairs Choose (11, 11), Not (9, 13)?

Check

The hashes follow the S-curve. So why does the measured optimum differ from the minimum of E?

Answer. E weighs every s \in [0,1] equally; the copies crowd near \tau and most negatives sit at 0. With the pairs’ own J in place of the uniform weight, the expected error is least at (11, 11) and, for w_{\textrm{fn}} = 5, at (14, 9). Right about the curve, wrong about the data.

The Dissimilar Bulk Decides the Cost

At scale

\mathbb{E}[\#\textrm{candidates}] = \sum_{i<j} P(s_{ij})

(11, 11) (14, 8)
P(0.3) 2 \times 10^{-5} 9 \times 10^{-4}
P(0.5) 0.005 0.053
10^6 documents, 0.1% of pairs at 0.5 3 \times 10^6 3 \times 10^7
  • Templated pages fill single buckets: m members give m(m-1)/2 pairs; max_bucket caps and reports them.
  • Our slice, already deduplicated: 0 candidates at both; 104 at (32, 4).

Pairs Become Clusters; Each Cluster Keeps One Page

From pairs to a corpus

  • Union-find over candidate pairs: A~B and B~C join A and C.
  • Keep the lowest index: independent of pair order and of any draw.
  • FineWeb deduplicates each dump on its own: globally deduplicated old dumps trained no better.
c1 at (11, 11)
kept 1,014 of 1,032
clusters of two or more 13 (31 documents)
largest one page, 4 copies on 3 hosts
near_dedup default (9, 13) 1,015 kept

Suffix Arrays Find Spans That MinHash Cannot See

Substring duplicates

A 60-word footer on thousands of different pages: J \approx 0.1, never a candidate, read thousands of times.

  • Sort all suffixes (prefix doubling, O(n \log^2 n)); repeats become long common prefixes of neighbours (Kasai, O(n)).
  • Lee et al.: one 61-word sentence over 60,000 times in C4.

2 MiB of FineWeb, about 450,000 tokens: 3 repeats of 50+ tokens.

repeat tokens
a blog’s “read more recent posts” footer 74
the Fourth Amendment 66
a function signature from a manual 50

Keeping one copy of every span also deletes quotations from the pages that need them.

Embeddings Find Rewordings, Then Pages on the Same Topic

Semantic duplicates

SemDeDup: k-means (64 clusters), remove a page whose cosine to an earlier member exceeds 1 - \varepsilon. 20,000 stream pages.

\varepsilon removed what goes
0.05 0
0.1 1 a template page, cosine 0.94, J = 0.17
0.15 to 0.2 6 to 27 gambling, essay mills, frozen pipes (J \approx 0)
0.3 181 (0.9%) FAQs, estate planning

Cosine to the nearest earlier member: median 0.46, largest 0.94.

\varepsilon belongs to one embedder; at large \varepsilon this is topic balancing, a mixture decision.

A 13-Gram Index Finds Copies and Nothing Else

Decontamination

16,533 test items, 633,848 hashed 13-grams. 100 items per benchmark planted in three forms into 900 FineWeb pages; 1,000 controls.

found by 13-grams GSM8K ARC MMLU
verbatim 100 100 100
reformatted (case, punctuation, options reversed) 100 100 100
paraphrased by Qwen3.5-4B 2 0 6
  • Reformatted: found by construction, since the index ignores these very changes.
  • One control flagged: it quotes the Declaration of Independence, as MMLU item 3828 does. Look at the span.

Embeddings Find Paraphrases Nearly as Often as Copies

A second detector

128-word windows every 64 words; threshold at the controls’ 99th percentile; held-out controls above it: 7 of 1,000.

recall all plants long plants (about 20) short plants (about 280)
verbatim 0.49 0.95 0.46
reformatted 0.54 0.95 0.51
paraphrased 0.42 [0.37, 0.48] 1.00 0.38

Short plants have a median under 50 words.

Check: Paraphrase Recall 0.42, Verbatim 0.49. What Limits the Detector?

Check

The detector finds long plants almost always and short plants about half the time, whatever their form.

Answer. Dilution, not paraphrase. A 50-word plant shares its 128-word window with about 80 words of the host page, and the window’s vector is about the host as much as about the item. Smaller windows help and add false positives.

What Every Detector Here Misses

Limits

leak 13-gram index embeddings
paraphrase misses about 2 in 5
numbers written as words (“two dozen”) breaks nearby 13-grams
item under 13 words (ARC 102, MMLU 1,589) cannot match
translation misses
famous quotation false positive
  • Overlap is evidence of leakage, not of memorization.
  • Memorization grows with model size, copies and prompt length (Carlini et al.); deduplication cuts memorized output about tenfold (Lee et al.).

The Version-1 Manifest: Nine Stages, One Hash

In the pipeline

stage out tokens
extract, of 9,731 records 9,286
lang_id, nfc, pii (c0) 3,288 2,850,469
heuristics, edu_score (c1) 1,032 923,725
exact_dedup 1,020 920,541
minhash_dedup at (11, 11) 1,014 918,627
decontam (c2) 1,014 918,627
  • Manifest SHA-256 identical with 1 and 4 workers.
  • lm-c2-docs-v1: keep, stage, reason and kept copy per c0 id, no text.

Recap

Recap

  • Exact hashes: no copies in FineWeb’s output, 12 in our crawl; shared lines are spans.
  • MinHash: \Pr[\textrm{agree}] = J, variance J(1-J)/k; bit-exact checks.
  • Banding: 1 - (1-s^r)^b; measured rates follow it (19 of 780 cells out).
  • Tune (b, r) on the pairs’ own similarities: (11, 11), F1 0.87.
  • Suffix arrays: shared spans; embeddings: rewordings, then topics.
  • 13-grams find copies only; embeddings about 2 in 5, limited by dilution.

Next: how much of each kind of text a model should see.