4.3.4 · D3Pretraining & Fine-Tuning LLMs

Worked examples — Pretraining data curation and cleaning

3,706 words17 min readBack to topic

The scenario matrix

Before working examples, let's map out every cell a curation problem can land in. Each row is a "situation class"; every example below is tagged with the cell it fills.

Cell Stage Situation class What makes it tricky
A Quality Clean prose, well under threshold Baseline "keep"
B Quality Symbol spam, over threshold Baseline "drop"
C Quality Degenerate: zero words () Division by zero!
D Quality Repetition penalty, boilerplate Second heuristic
E Dedup MinHash estimator, mid-similarity Probability = similarity
F Dedup Limiting case: identical (), disjoint (), boundary (), empty shingle set Every extreme
G LSH Tuning so the wall sits at S-curve crossover
H LSH Exam twist: wrong rule-of-thumb vs exact crossover Catch the trap
I Mixing Upsample a scarce domain safely
J Mixing Real-world word problem: full token budget across 3 domains Weights must sum to 1

Every symbol used below is defined in the parent note; we re-anchor each as it appears.


Quality-filter examples (cells A–D)

Recall the symbol-to-word ratio. A document has words (space-separated chunks of letters) and symbol characters (things like #, , @). We defined which measures "how many weird characters per word." Prose keeps this tiny; junk inflates it. Rule from the parent (with our convention): drop iff ; keep if .

Figure — Pretraining data curation and cleaning
The symbol-ratio number line: one wall at splits keep from drop. The teal keep-zone sits at or left of the wall; the orange drop-zone is strictly right. Doc A (, teal) keeps; Doc B (, orange) drops. Doc C is the empty page: its ratio is off the chart to the right — we draw a plum arrow running past the right edge with the label "" to show it is not a real point but a runaway limit, always landing deep in the drop-zone.


Deduplication examples (cells E–F)

We represent a document as its set of -shingles (overlapping -word windows). Two docs' overlap is the Jaccard similarity "shared shingles over total distinct shingles." Now the MinHash machinery. A hash function is a rule that maps each shingle to a random-looking number; is the smallest such number over set . The subscript just names which random hash we used — we will use different independent ones, . MinHash's magic fact: so counting matches across random hashes estimates without comparing full documents. Our dedup threshold is : flag as near-duplicate iff .

Figure — Pretraining data curation and cleaning
Two shingle sets drawn as overlapping circles: the teal crescent is -only, the orange crescent is -only, and the plum lens in the middle is . The Jaccard similarity is the plum lens measured as a fraction of the whole two-circle union. The picture makes the "magic fact" visible: throw one random hash, look at whichever shingle wins the minimum over the union — it is equally likely to be any shingle, so the chance it lands inside the plum lens (making the two minhashes agree) is exactly that lens-fraction .


LSH tuning examples (cells G–H)

To dodge the all-pairs comparison, split hashes into bands of rows. Docs matching a whole band become candidate pairs. Let's build the S-curve from scratch, one probability at a time, before quoting it.

Figure — Pretraining data curation and cleaning
The LSH S-curve for , drawn in orange. It starts almost flat near zero, then rises steeply through a "wall" and saturates near one — that flatness-then-cliff shape is exactly what makes LSH cheap. The dotted ink line marks ; the plum dashed vertical marks the exact wall from the derivation. The teal dash-dot line is our target , where the curve is already at (true duplicates are almost surely caught). The ink dot at shows (dissimilar pairs almost never become candidates, saving compute).


Domain-mixing examples (cells I–J)

Given domains with token counts and target weights (with ), over a training budget of tokens each domain is seen for Keep modest: by our convention, memorization-safe iff . See Data Mixture and Domain Weighting for the reweighting theory.


Recall

Recall Empty document (

) in the symbol filter — keep or drop, and why? Drop. is undefined; as the ratio , so the limiting decision is "drop" — a text-free page carries no learning signal.

Recall A doc has

exactly. Keep or drop under our convention? Keep. The symbol rule drops iff , so the wall belongs to the keep side (benefit of the doubt for quality filters).

Recall A pair has

exactly. Duplicate or not, and why is this the opposite convention to the quality filters? Duplicate — dedup flags iff , so the wall sits on the drop side. Letting borderline leaks through is the costlier error, so we err toward removing.

Recall A doc is too short to form any

-shingle. What is with another doc, and what do we do? makes undefined ( if both empty). We patch it to (never a duplicate) and drop the too-short doc at the earlier quality stage.

Recall Why is a whole-band match probability

and the candidate probability ? A band is a candidate only if all rows match (AND ⇒ multiply ⇒ ). The pair is a candidate if at least one of bands matches (OR ⇒ minus "all fail" ⇒ ).

Recall For

, is the exact LSH crossover closer to or ? About — the exact . The rule-of-thumb overestimates.

Recall With

hashes and , what is ? , so standard error .

Recall In Cell J, which domain crosses the

guardrail, and at what value? Books, at epochs — a scarce pool (B) paired with a high weight ().

Parent: 4.3.4 curation & cleaning. Related: MinHash and LSH, Deduplication and Memorization, Data Mixture and Domain Weighting, Benchmark Contamination, Scaling Laws for LLMs.