Quality Filtering

Dive into Deep Learning · §20.2

Quality Filtering
heuristic rules · perplexity · classifiers on model labels · label noise · thresholds · audits

A Spell-Selling Page Passes Every Rule; a Hiring Guide Fails the Classifier

The problem

FineWeb-Edu keeps 7.26% of FineWeb’s 265,662,695 documents of one crawl.

page, from FineWeb’s output rules our classifier
“I NEED REVENGE DEATH SPELL … Call/WhatsApp ‹phone›”, 1,500+ characters keep lowest score among such pages
a company’s guide to hiring software engineers, after a sales pitch keep remove

Before tuning a threshold: what does the filter mean by quality, and whose pages does it remove?

By the End of This Deck You Can

Goals

  • implement the Gopher, C4 and FineWeb rules with reason codes, and check them against FineWeb’s code;
  • say what perplexity measures, and what it does not;
  • label documents with a large model’s next-token probabilities, and train a linear head on a frozen embedder;
  • bound the attainable F1 under label noise;
  • turn a threshold into retained tokens, and audit removals with site-level intervals.

Running example: our 3,288 crawl documents (c0) and 20,000 documents of FineWeb’s output for the same crawl (the audit stream).

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: c0 → rules → score → flags in the manifest (c1).
  • Skips: duplicates, mixtures, and whether the filter helps training.

Fifteen Rules, Each With a Reason Code

Heuristic rules

family catches codes
Gopher repetition repeated lines, paragraphs, n-grams 3
Gopher quality 50 to 100,000 words; mean length 3 to 10; 80% of words with a letter; 2 of 8 stop words (the, of, with, …) 7
C4 fewer than 5 sentences, “lorem ipsum”, { 1
FineWeb lines without terminal punctuation, short lines, duplicated characters, line breaks per word 4

A document is charged to the first rule that fires. Thresholds: datatrove 0.10.1, the code that built FineWeb.

The Rules Remove Two Thirds of Our Crawl and 1.6% of FineWeb’s Output

The rules at work

corpus in removed
c0, our crawl documents 3,288 2,256 (69%)
audit stream, FineWeb’s output 20,000 317 (1.6%)
  • c0, first rule charged: duplicated text 571, alphabetic words 403, word count 322.
  • Line punctuation fires on 1,150 c0 documents but comes late in the order.
  • Against datatrove on 2,000 c0 documents: same decision on 96% to 99.9%; the gap is word and sentence splitting.

On the stream, FineWeb’s own four rules never fire.

English Rules Remove Every Chinese, Japanese and Thai Page; Our Word Pattern Every Hindi Page

Other languages

FineWeb-2, 500 pages each removed first rule
German 96% stop words
Swahili 93% stop words
Hindi 100% mean word length (our \w)
Chinese, Thai 100% alphabetic words
Japanese 100% word count
  • Chinese, Japanese, Thai: no spaces, so one “word” per run between punctuation marks.
  • Hindi has spaces, but our \w skips Devanagari vowel signs and words shatter; datatrove’s tokenizer keeps them. An artifact of our code.

Every page had passed FineWeb-2’s rules for its language.

Check: Drop the Stop-Word Rule. How Much German Is Left?

Check

The rule asks for 2 of the, be, to, of, and, that, have, with. With it, German loses 96%.

Answer. Without it German loses 28%, Swahili 16% instead of 93%. Chinese, Japanese, Thai and Hindi still lose 100%: their losses come from the word rules (for Hindi, from our word pattern), not from English vocabulary.

The Most Predictable Pages Read as Machine-Written

Perplexity

Mean NLL per token, first 512 tokens, Qwen3-0.6B-Base, 3,000 stream pages: median 2.9 nats.

lowest NLL highest NLL
“Please be mindful of our community standards” “As have a peek at these guys you can see regarding the …”
“In today’s digital age, a strong online presence is crucial …” spun text about pokies, loans, Discord
“Greetings, readers! I am excited to delve into …” a garden-blog comment, a railway photo site

Low perplexity means resemblance to the model’s training text, not quality.

A Large Model Labels a Sample; a Small Model Labels the Web

The recipe

  1. A rubric: “useful … for teaching from primary school to grade school”.
  2. A large model scores a sample, 0 to 5 points, one criterion per point.
  3. A small model learns the score; a threshold selects.
corpus labeller small model rule
FineWeb-Edu Llama-3-70B, 450k pages frozen 109M encoder + regression rounded score ≥ 3
DCLM instruction data and explanations vs web fastText top 10%
Nemotron-CC several classifiers ensemble quality buckets

Read the Score From Six Next-Token Probabilities

Labelling

Answer prefix Educational score:; one forward pass:

p(d) \;+\; p(\textrm{space})\,p(d \mid \textrm{space}), \qquad d = 0, \ldots, 5

  • Label: \arg\max_d. Expected score: \sum_d d\,p(d) / \sum_d p(d).
  • The second-space path holds about 15% of the probability.
  • Qwen3.8-27B, 4-bit weights, one copy per 24 GB GPU; 22,000 pages in about an hour on four.

Batching changes the arithmetic, and near ties flip. One request at a time: identical bits on any server.

Qwen Is About a Point Stricter Than Llama, but Ranks Pages Alike

Two labellers

share of 22,000 pages score ≥ 1 ≥ 2 ≥ 3 ≥ 4
Llama-3-70B (2024) 0.88 0.31 0.091 0.018
Qwen3.8-27B 0.82 0.064 0.014 0.0001
  • Spearman, Qwen’s expected score vs Llama’s score: 0.76.
  • Kappa at ≥ 3: 0.24; with Qwen cut at Llama’s share: 0.65.

Agreement with one labeller cannot show which labels are better; training runs decide.

A Linear Head Matches the Released Classifier on Qwen’s Labels

Classifiers

2,000 test rows, 36 positives (Qwen ≥ 3); t^* from 2,000 validation rows.

classifier trained parameters F1 [95% interval] AUC
regression head, frozen 0.6B embedder 1,025 0.44 [0.32, 0.55] 0.98
logistic head, same embedder 1,025 0.56 [0.41, 0.68] 0.98
hashed bag (fastText), CPU 67M 0.26 [0.17, 0.34] 0.90
released, trained on Llama head only 0.47 [0.35, 0.57] 0.98

Paired: regression head − released F1 = −0.02 [−0.14, +0.09].

Check: The Regression Head’s Best Threshold Is 1.6. Why Not 3?

Check

The label is “score ≥ 3”; the head fits the score by squared error.

Answer. A linear head on a frozen vector cannot tell every page apart; under squared error it predicts the mean score of the pages it confuses. Only 1.4% of labels reach 3, so such a group hardly ever has a mean near 3: the predictions bunch between 0 and 2. A cut at 2.5 keeps nothing.

F1 Depends on the Threshold Only Through Recall and Retention

An identity

\pi: share of positive labels; TPR: recall; \rho: share of documents kept.

\textrm{precision} = \frac{\pi\,\textrm{TPR}}{\rho} \quad\Rightarrow\quad \textrm{F1} = \frac{2PR}{P+R} = \frac{2\pi\,\textrm{TPR}}{\pi + \rho}

  • Best case: keep exactly the positives, \rho = \pi, TPR = 1.
  • At fixed recall, keeping more lowers F1.
  • Checked at 50 thresholds: largest gap 6 \times 10^{-17}.

Qwen Reproduces Its Own Labels at an F1 of About 0.67

Label noise

If labels flip the true label y^* with probability \eta either way, a perfect classifier of y^* scores

P = 1 - \eta, \qquad R = \frac{\pi^*(1-\eta)}{\pi^*(1-\eta) + (1-\pi^*)\eta}

  • Two Qwen protocols disagree on 19 of 2,000 rows: \eta \approx 0.005, ceiling 0.80 [0.68, 0.89], if the noise is symmetric.
  • It is not: 1.80% against 1.05% positive; 17 of the 19 go one way.
  • No model needed: one protocol against the other, 36 and 21 positives, 19 shared: F1 = 2 \cdot 19/(36+21) \approx 0.67.
  • Classifiers 0.26 to 0.56: below both (the logistic head’s interval reaches 0.68).

Cutting at the Label’s Own 3 Keeps Nothing

The threshold

Regression head, stream shares and test precision and recall (Qwen ≥ 3):

cut documents tokens precision recall
1.5 5.1% 8.0% 0.27 0.92
t^* = 1.61 2.9% 4.8% 0.33 0.67
2.0 0.3% 0.5% 0.64 0.19
2.5, 3.0 0 0 — 0
  • FineWeb-Edu’s rule on the same stream keeps 7.1% of documents, 9.9% of tokens.
  • Data-limited runs cut lower; compute-limited runs cut higher.

Resample Sites, Not Pages, and Demand the Same Sign in Both Halves

The audit

  • Groups: country-code domain (a weak proxy for English variety), host class by name rules, six languages (rules only).
  • Intervals: bootstrap over registered domains; 3,000 pages of one site are not 3,000 samples.
  • Too few: under 100 documents or 10 domains.
  • Halves split by domain; a finding needs one sign in both.

A filter keyed on a classifier’s score is a covariate shift toward what the classifier prefers.

The Classifier Keeps .au Pages at a Third of the .com Rate

Audit results

group arm removal − reference 95% interval
.au vs .com classifier +1.9 points [+0.9, +2.7]
shop vs other classifier +2.6 points [+1.9, +3.1]
news vs other rules −1.4 points [−1.7, −0.9]
.uk, .ca, .in, .nz, .za classifier intervals include 0

The classifier removes 97.2% of the stream: it keeps about 3% of .com pages and about 1% of .au pages (6 of 544), so the third is rough.

Check: Removal Rates of 97.0% and 98.9%. A Small Difference?

Check

A filter removes 97.0% of group A and 98.9% of group B.

Answer. No. The corpus receives what is kept: 3.0% of A and 1.1% of B, so B enters at about a third of A’s rate. When a filter keeps little, compare retention, not removal.

Near Its Threshold the Classifier Mostly Removes Pages Worth Keeping

Reading removals

Judge: Qwen3.8-27B, reasoning on and uncapped, rubric “would a reader want this page in a general-purpose corpus?”

100 removed pages each judged “drop” 95% interval
classifier only, score within 0.3 of t^* 0.11 [0.06, 0.19]
rules 0.70 [0.60, 0.78]
  • Rules removed, judged keep: an entry on a figure of Greek mythology.
  • The judge also wrote the labels: not independent.

The classifier follows its rubric; the gap is between two definitions of quality.

The Manifest Stores the Score; the Threshold Is a Parameter

In the pipeline

stage in out recorded
heuristics 3,288 1,032 drops by first reason code
edu_score 1,032 1,032 threshold 1.611, head SHA-256, embedder revision
  • Flags per c0 id: reason codes and score, no text.
  • 20 of the 1,032 score at or above t^*, about 2%.
  • Score bands can become mixture sources without relabelling.

Recap

Recap

  • Rules: c0 loses 69%, FineWeb’s output 1.6%; 96% agreement with datatrove; 100% loss on unspaced scripts, and on Hindi through our word pattern.
  • Lowest perplexity: boilerplate and machine-written prose.
  • Qwen: 1.4% at ≥ 3 against Llama’s 9%; Spearman 0.76.
  • Head F1 0.44, released 0.47: no difference; Qwen against itself 0.67.
  • t^* keeps about 3% of documents, 5% of tokens.
  • Audit: .au and shops removed more; near t^* the judge keeps 89 in 100.

Next: the same page, or nearly the same, appears many times.