Simple Algorithm
Deep Learning · Emergence · 26 min

Data Quality, Filtering & Mixtures

Deduplication, quality filters, data pruning and choosing a mixture.

Hold the architecture, the compute and the number of tokens fixed, and change only which tokens the model reads: in controlled comparisons that alone moves downstream accuracy by several points. Data curation has become a research field with its own theory and experiments: heuristic filters, near-duplicate detection, learned quality classifiers, pruning metrics that can beat power-law scaling, the value of repeated data, and mixtures chosen by small proxy models.

What you’ll learn

  • Describe a web-text pipeline (extraction, language identification, heuristic filters, deduplication, quality classifiers) and what each stage removes.
  • Prove that MinHash estimates Jaccard similarity, derive the banding curve used for near-duplicate detection, and explain why aggressive global deduplication can backfire.
  • Explain how pruning with a good metric can beat power-law scaling in a teacher–student model, and when to keep easy rather than hard examples.
  • Quantify the value of repeated tokens with the data-constrained scaling law, and describe how mixtures are chosen with DoReMi and data mixing laws.

From crawl to corpus

Most pretraining text starts as Common Crawl, a public web archive running since 2007 and released as a series of snapshots (about 100 by 2024), most of which is not useful prose: menus, boilerplate, spam, keyword lists, machine-generated pages and endless duplicates. A modern pipeline is a funnel:

StageWhat it doesExamples
Text extractionturn raw HTML into textdedicated extractors beat the archive's own text dumps in controlled tests (Li et al., 2024)
Language identificationkeep documents in the target languagesC4 kept pages that langdetect labeled English with probability at least 0.99
Heuristic filtersdrop pages that fail simple rulesC4: keep lines ending in terminal punctuation, drop pages under 3 sentences or containing a curly bracket; Gopher: 50 to 100,000 words, mean word length 3 to 10, at least two of eight common English stop words
Deduplicationremove exact and near-duplicate textexact 50-token substrings; MinHash on word n-grams (next step)
Quality classifiersscore documents with a model and keep the besteducational-value regressors; fastText classifiers trained on reference text
Mixing and decontaminationset domain proportions; remove benchmark textupsample code, math or books; drop documents that overlap test sets
C4 rules from Raffel et al. (2020); Gopher's from Rae et al. (2021), who also note that blocklist filters can disproportionately remove inoffensive text associated with minority groups (Dodge et al., 2021). Every stage trades quantity and diversity for quality.
Predict before you look

A pool of 240 trillion tokens passes heuristic filters that keep 40%, deduplication that keeps 40% of the rest, and a classifier that keeps the top 10%. How many trillion tokens remain? (The rates are illustrative.)

Show the answer

3.84 T

240×0.4×0.4×0.1=3.84240\times0.4\times0.4\times0.1=3.84 trillion, 1.6% of the pool. That is close to the real outcome of DataComp-LM's pipeline, which turned a 240-trillion-token pool into the 3.8-trillion-token DCLM-Baseline (Li et al., 2024). FineWeb-Edu's classifier kept 1.3 of FineWeb's 15 trillion tokens, about 9% (Penedo et al., 2024). Quality filtering spends the web's abundance, which is why repetition and data exhaustion come up later in this lesson.

Finding near-duplicates

Deduplication works at two levels. Exact substrings: Lee et al. (2022) built a suffix array over the whole corpus, found every span of 50 or more tokens that occurs more than once, and kept a single copy; in C4 they found one 61-word English sentence repeated over 60,000 times. Near-duplicates: documents identical except for templated fields such as dates, names or prices. Comparing all pairs is quadratic in billions of documents, so pipelines use MinHash.

DerivationProof, and the banding curve
  1. Pr⁡[min⁡h(A)=min⁡h(B)]=∣A∩B∣∣A∪B∣=J(A,B)\Pr\big[\min h(A)=\min h(B)\big]=\frac{\abs{A\cap B}}{\abs{A\cup B}}=J(A,B)

    Under a uniformly random ordering, the element of A∪BA\cup B with the smallest hash is equally likely to be any of its ∣A∪B∣\abs{A\cup B} elements. If it lies in A∩BA\cap B, it is the minimum of both sets; if it lies in only one of them, the other set's minimum is a different element, with a different hash. Hence:

  2. Pr⁡[candidate∣J=s]=1−(1−sb)r\Pr[\text{candidate}\mid J=s]=1-\big(1-s^{b}\big)^{r}

    Each of kk independent hashes gives a Bernoulli(JJ) indicator, so their mean has mean JJ and variance J(1−J)/kJ(1-J)/k. To avoid comparing all pairs, split the k=b rk=b\,r hashes into rr bands of bb and call two documents candidates if all bb minima agree in at least one band:

  3. b=20, r=450:Pr⁡[candidate]≈{0.0004s=0.50.30s=0.70.99s=0.8b=20,\ r=450:\qquad\Pr[\text{candidate}]\approx\begin{cases}0.0004 & s=0.5\\0.30 & s=0.7\\0.99 & s=0.8\end{cases}

    Bucketing each band's bb values finds candidates in near-linear time. The probability is an S-curve whose steep rise sits near s≈(1/r)1/bs\approx(1/r)^{1/b}. Lee et al. used 5-grams, b=20b=20 and r=450r=450 (9,000 hashes), putting the rise near 0.740.74, then confirmed candidates by edit similarity above 0.80.8.

What deduplication buys. Lee et al. found that models trained on deduplicated data emitted memorized text about ten times less often and reached the same or better accuracy in fewer steps, and that train–test overlap affected over 4% of the validation sets of standard datasets. When it backfires. FineWeb's builders first deduplicated all 96 Common Crawl snapshots against each other; in the oldest snapshots this removed up to 90% of the data, and in one of them the 10% kept turned out to be worse than the 90% removed (more ads, keyword lists and badly formatted text). Deduplicating each snapshot separately worked better. The authors' hypothesis: the gains come from removing huge clusters of duplicates, while stripping small clusters, of fewer than about 100 copies, throws away good content (Penedo et al., 2024). Muennighoff et al. (2023) likewise saw no downstream gain from deduplication on their benchmarks, though it may still curb memorization.

Semantic duplicates are pairs with the same content in different words. SemDeDup clusters pretrained embeddings and drops near neighbors within each cluster; on a subset of the LAION image–text data it removed half the data with little loss (Abbas et al., 2023), though as a quality filter for web text it did not beat a strong baseline in DataComp-LM's comparison (Li et al., 2024).

Predict before you look

With b=5b=5 hashes per band and r=20r=20 bands, what is the probability that two documents with Jaccard similarity 0.50.5 become candidates? Answer in percent.

Show the answer

47 %

0.55=1/320.5^5=1/32, so one band matches with probability 0.031250.03125, and 1−(1−0.03125)20=1−0.968820≈1−0.53=0.471-(1-0.03125)^{20}=1-0.9688^{20}\approx1-0.53=0.47. The rise sits near (1/20)1/5≈0.55(1/20)^{1/5}\approx0.55, so short bands catch moderately similar pairs too; production settings use long bands (b=20b=20) to flag only very similar documents.

Learned quality filters

Heuristics remove obvious junk; ranking the rest needs a model. Three published recipes:

  • Perplexity filtering: keep documents that a small language model trained on a reference corpus such as Wikipedia finds likely.
  • LLM-annotated educational value (FineWeb-Edu): a large instruction-tuned model rated 460,000 web pages from 0 to 5 for educational value at grade-school to middle-school level; a small regressor trained on those ratings scored all 15 trillion tokens of FineWeb, and keeping scores of at least 3 left 1.3 trillion tokens. Models trained on it did markedly better on knowledge- and reasoning-heavy benchmarks.
  • A fastText classifier (DataComp-LM): a linear bag-of-n-grams classifier trained to tell instruction-style text (OpenHermes 2.5 and highly rated r/ExplainLikeImFive posts) from ordinary filtered web text, keeping the top 10%. In a controlled comparison at fixed compute it beat PageRank, semantic deduplication, an embedding classifier, asking an LLM, perplexity filtering and a top-kk-logit score.

Pruning past the power law

Power-law data scaling means each new random example carries less new information than the last. Sorscher et al. (2022) asked whether a smart choice of examples could do better, and answered first in a solvable model.

The predictions held qualitatively for ResNets on SVHN, CIFAR-10 and ImageNet. Benchmarking ten pruning metrics on ImageNet, the authors found most scaled poorly, and proposed a cheap self-supervised one: cluster self-supervised embeddings with kk-means and call an example hard if it is far from its nearest centroid. For language-model pretraining, where a corpus is seen about once and the "label" is the text itself, how far exponential gains carry over is an open question.

Check your understanding

You can afford to train on only 10% of a dataset. When is keeping the easiest examples better than keeping the hardest, according to the teacher–student theory?

  1. Never: hard examples always carry more information
  2. When the original dataset is small, so the model must first learn the coarse structure
  3. When the original dataset is huge
  4. Only when the pruning metric is perfect
Show the answer

B. When the original dataset is small, so the model must first learn the coarse structure

With little data, hard examples are near the boundary, often atypical, and a model that has not yet captured the coarse structure overfits them; easy examples teach that structure first. With abundant data the easy ones are redundant, and the hard ones pin down the boundary. The same crossover appeared with ResNet-18 on CIFAR-10.

Repetition, scarcity and mixtures

A good corpus is small next to the appetite of compute-optimal training, so data get repeated. Muennighoff et al. (2023) trained some 400 models, up to 9 billion parameters and 900 billion tokens, and fitted the value of repetition. With UDU_D unique tokens seen 1+RD1+R_D times, the effective data is

D′=UD+UDRD∗(1−e−RD/RD∗),RD∗≈15.4,D′→RD→∞UD (1+RD∗)D'=U_D+U_DR_D^*\Big(1-e^{-R_D/R_D^*}\Big),\qquad R_D^*\approx15.4,\qquad D'\xrightarrow{R_D\to\infty}U_D\,(1+R_D^*)
For RD≪RD∗R_D\ll R_D^*, D′≈UD(1+RD)D'\approx U_D(1+R_D): early repeats count almost like fresh tokens. Four epochs are worth about 3.7 epochs of fresh data, sixteen about 10.6, and no amount of repetition is worth more than about 16.4. Mixing in Python code for up to half the tokens did not hurt natural-language performance in their tests.

The supply is finite: Villalobos et al. (2024) estimated the stock of public human-written text at a few hundred trillion tokens and projected that, on trend, training sets would match it between 2026 and 2032, earlier for overtrained models.

Choosing a mixture. Corpora combine domains (web, code, books, papers, encyclopedias) in proportions that matter. DoReMi (Xie et al., 2023) trains a small reference model on a default mixture, then a small proxy that minimizes the worst-case excess loss over the kk domains,

min⁡θ max⁡α∈Δk ∑i=1kαi 1∣Di∣∑x∈Di[ℓθ(x)−ℓref(x)],\min_{\boldsymbol\theta}\ \max_{\boldsymbol\alpha\in\Delta_k}\ \sum_{i=1}^k\alpha_i\,\frac{1}{\abs{D_i}}\sum_{x\in D_i}\big[\ell_{\boldsymbol\theta}(x)-\ell_{\text{ref}}(x)\big],

with ∣Di∣\abs{D_i} the token count of domain ii, updating the weights α\boldsymbol\alpha by exponentiated gradient ascent toward domains where the proxy lags most. The averaged weights, found with a 280-million-parameter proxy, trained an 8-billion-parameter model that reached the baseline's downstream accuracy in 2.6 times fewer steps on The Pile. Data mixing laws (Ye et al., 2025) instead fit each domain's validation loss as Li(r)=ci+kiexp⁡(∑jtijrj)L_i(\mathbf r)=c_i+k_i\exp\big(\sum_jt_{ij}r_j\big) in the proportions r\mathbf r, nest it with scaling laws in steps and model size, and optimize the mixture before any large run.

Key takeaways

  • Web pipelines funnel Common Crawl through extraction, language identification, heuristic rules, deduplication and learned quality classifiers, often keeping a few percent: DataComp-LM kept 3.8 of 240 trillion tokens.
  • MinHash agreement equals Jaccard similarity, and banding turns k=brk=br hashes into an S-curve 1−(1−sb)r1-(1-s^b)^r for finding near-duplicates. Deduplication reduces memorization and train–test overlap, but deduplicating globally across snapshots can leave lower-quality text behind.
  • In the teacher–student perceptron, pruning by a perfect metric beats the α−1\alpha^{-1} power law (at least exponentially), keep-easy beats keep-hard when data are scarce, and an imperfect metric returns the curve to a power law.
  • Repeated data is nearly as good as fresh for about four epochs and saturates near 1+RD∗≈161+R_D^*\approx16 epochs' worth. Mixtures can be set by small proxies (DoReMi) or fitted mixing laws.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

Why does the probability that two documents share the same MinHash value equal their Jaccard similarity?

  1. Because hash functions preserve the distance between documents
  2. Because longer documents have smaller minimum hashes
  3. Because MinHash counts the shared nn-grams exactly
  4. Because the smallest-hashed element of A∪BA\cup B is uniform over A∪BA\cup B, and the minima agree exactly when it lies in A∩BA\cap B
Show the answer

D. Because the smallest-hashed element of A∪BA\cup B is uniform over A∪BA\cup B, and the minima agree exactly when it lies in A∩BA\cap B

A random ordering makes every element of the union equally likely to come first; agreement requires that element to be shared. So Pr⁡=∣A∩B∣/∣A∪B∣\Pr=\abs{A\cap B}/\abs{A\cup B}, and averaging kk hashes estimates it with variance J(1−J)/kJ(1-J)/k.

Question 2

FineWeb's builders deduplicated 96 Common Crawl snapshots globally, then compared it with deduplicating each snapshot separately. What did they find?

  1. Global deduplication was better, since it removed the most duplicates
  2. Per-snapshot deduplication was better: in an old snapshot, what global deduplication kept was worse than what it removed
  3. Neither mattered, because the quality classifier removed all duplicates anyway
  4. Deduplication of any kind made the models memorize more
Show the answer

B. Per-snapshot deduplication was better: in an old snapshot, what global deduplication kept was worse than what it removed

Deduplicating an old snapshot against all later ones removed up to 90% of it, and the part that survived was of lower quality than the part removed. Per-snapshot deduplication still removed the huge duplicate clusters, which seem to be where the benefit lies, while keeping content duplicated only a few times.

Question 3

Under Muennighoff et al.'s fit with RD∗≈15.4R_D^*\approx15.4, how much is a corpus worth if you repeat it indefinitely, measured in epochs of fresh data?

  1. At most about 16.4 epochs' worth
  2. Exactly 1 epoch, since repeats teach nothing
  3. As many epochs as you train for
  4. About 4 epochs' worth
Show the answer

A. At most about 16.4 epochs' worth

D′→UD(1+RD∗)≈16.4 UDD'\to U_D(1+R_D^*)\approx16.4\,U_D as RD→∞R_D\to\infty. Four epochs are worth about 3.7, nearly fresh, but returns fall off past about 16 epochs.

Question 4

What does DoReMi optimize to choose domain weights?

  1. Downstream benchmark accuracy of the large model
  2. The average loss over all tokens, weighted by domain size
  3. The worst-case excess loss over domains of a small proxy model, relative to a reference model, via Group DRO
  4. The perplexity of each domain under the large model
Show the answer

C. The worst-case excess loss over domains of a small proxy model, relative to a reference model, via Group DRO

A minimax over domain weights upweights domains where the proxy lags the reference most, that is, where there is learnable headroom; the averaged weights then define the large model's mixture, with no downstream tasks involved.

Further reading

  • K. Lee, D. Ippolito, A. Nystrom, C. Zhang, D. Eck, C. Callison-Burch & N. Carlini, "Deduplicating training data makes language models better," ACL (2022).
  • G. Penedo et al., "The FineWeb datasets: Decanting the web for the finest text data at scale," NeurIPS Datasets and Benchmarks (2024).
  • J. Li et al., "DataComp-LM: In search of the next generation of training sets for language models," NeurIPS Datasets and Benchmarks (2024).
  • B. Sorscher, R. Geirhos, S. Shekhar, S. Ganguli & A. S. Morcos, "Beyond neural scaling laws: Beating power law scaling via data pruning," NeurIPS (2022).
  • N. Muennighoff et al., "Scaling data-constrained language models," NeurIPS (2023).
  • S. M. Xie et al., "DoReMi: Optimizing data mixtures speeds up language model pretraining," NeurIPS (2023).