Exercises — Pretraining data curation and cleaning
Before we start, two symbols we will reuse everywhere. A ratio like just means "how many of one thing per one of another" — dividing makes it length-independent, so a tweet and an essay are judged on the same scale. A probability is a number between and telling you how often something happens if you repeated the experiment forever ( = never, = always). Keep those two pictures in your head.
The whole page follows one climb. The picture below is the map — glance at it now, and we will return to it as we move up each rung.

Read it left to right: the dots are the five levels, and the arrows call out what changes about your job at each rung — L2 is "plug into a formula," L3 is "reason about trade-offs," L5 is "handle the broken inputs nobody tested." Every exercise below is one dot on that line.
Level 1 — Recognition
Goal: read a document's stats and fire the correct filter rule. No cleverness, just "which rule and does it trip?" — the leftmost blue dot on the ladder figure above.
Recall Solution 1.1
WHAT we do: divide symbols by words. WHY divide, not just count 40: a raw count of 40 would flag every long article. The ratio asks "per word, how symbol-heavy is this?" — length-invariant. Decision: , so the rule does not trip → KEEP. This looks like ordinary prose.
Recall Solution 1.2
WHAT the symbol means: is just "duplicate lines over total lines " — a ratio, so it is length-invariant exactly like . WHY this rule exists: repeated lines ("Add to cart / Add to cart / …") are the fingerprint of a templated junk page, not human writing. → DROP.
Recall Solution 1.3
WHAT means: the classifier's confidence, between and , that the document is English. → DROP (below threshold). WHY a threshold, not argmax: even if English is the top guess, a low-confidence doc is often code-switched or too short to be clean prose. The threshold trades recall for precision.
Level 2 — Application
Goal: plug numbers into the pipeline formulas — MinHash, LSH, mixture epochs — and get a number out. This is the green dot on the ladder figure: the job is mechanical substitution.
Recall Solution 2.1
Key fact (from parent): for each hash, . So matches follow "flip a -biased coin times." WHY expected matches (linearity of expectation): write the total matches as a sum , where if hash matches and if not. The expected value of any sum equals the sum of expected values — this is true even if the terms were dependent, and it needs no independence at all. Each is a coin that is with probability , so . Adding of them: . Expected matches Estimator: — unbiased, recovering the truth. WHY MinHash and not compute directly? Direct over all pairs is ; MinHash turns a set-overlap question into cheap coin-flip counting.
Recall Solution 2.2
Step 1 — one band matches: a band of rows matches only if all 4 hashes agree, probability . Step 2 — one band fails: . Step 3 — all bands fail: . Step 4 — at least one band matches (that's what we want): WHY this shape (an S-curve): "share any whole band" makes catching easy for high and hard for low — exactly the wall we want. You will see this curve plotted in the Level 3 figure.
Recall Solution 2.3
WHY watch : repeating a scarce domain more than ~4 times (memorization risk) starts overfitting. Here sits right on the caution line — acceptable but do not push higher.
Level 3 — Analysis
Goal: reason about trade-offs — where does the wall sit, what does a threshold cost you? The yellow dot on the ladder.
The figure below plots the LSH S-curve for three configurations. The x-axis is true similarity ; the y-axis is the probability the pair becomes a candidate. The dashed horizontal line is , and each dot marks that config's wall — the similarity where the curve crosses . Notice how adding rows (green vs blue) slides the wall to the right. The yellow dotted vertical line is our near-dup target ; we want the wall to sit below it so real duplicates land in the flat near- top.

Recall Solution 3.1
Step 1: , so . Step 2: . Interpretation (read it off the figure): the S-curve crosses 50% at , left of the yellow line. Since , by the time similarity reaches your target the curve is already near 1 — true dups are safely captured. WHY the exact form beats the rule-of-thumb : the approximation gives , close but slightly off. When you're tuning a wall precisely against , use the exact .
Recall Solution 3.2
- (a) Precision ↑ — a stricter bar means the docs you do keep are more surely English (fewer false English).
- (b) Recall ↓ — genuine but short/code-switched English docs scoring – are now wrongly dropped (false negatives rise).
- (c) Total tokens ↓ — you discard more, shrinking the corpus. WHY this matters for training: fewer tokens can hurt an LLM that is token-starved (scaling laws say more good tokens help). Threshold choice is a precision–recall–budget triangle, not a "higher is better" knob.
Recall Solution 3.3
But this is good content! WHY it mis-fires: the heuristic assumes symbols signal SEO spam, an assumption that fails for math/code where symbols are the content. Fix in practice: route symbol-heavy docs through a model-based quality classifier, or set domain-specific thresholds — a single global rule is too blunt for code/math domains.
Level 4 — Synthesis
Goal: combine multiple stages / design a config to hit a spec. The red dot on the ladder — no single formula hands you the answer.
Recall Solution 4.1
Use :
- : ; .
- : ; .
- : ; . Distances to : , , . Winner: , wall at — closest to target. WHY the pattern: more rows per band (larger ) = each band is stricter = wall moves right (toward high similarity). Fewer, longer bands catch only very-similar pairs.
Recall Solution 4.2
Multiply survival fractions in sequence: WHY multiply (not add) the losses: each stage acts on the survivors of the previous stage, so fractions compound. 79% of the raw crawl was junk — a realistic figure.
Recall Solution 4.3
Invert : Check: ✓, and so memorization risk stays low. See Data Mixture and Domain Weighting for how the remaining splits across other domains.
Level 5 — Mastery
Goal: edge cases, degenerate inputs, and why-it-breaks reasoning. The white dot at the top of the ladder — the scenarios nobody tested until production.
Recall Solution 5.1
(a) : match probability → expected matches . Disjoint docs never collide (before hashing collisions, ignored). (b) : probability → all minhashes match; exactly. WHY: identical shingle sets have , so the two minima always land on the same element — every hash agrees. (c) Each hash is a Bernoulli() trial; is their mean, so WHY variance shrinks with : averaging more independent coin flips squeezes the estimate toward the truth — the is the whole reason we use many hashes.
Recall Solution 5.2
(a) : , so . A totally dissimilar pair is never a candidate — the curve starts pinned at the floor. (b) : , so . An identical pair is always a candidate — the curve ends pinned at the ceiling. (c) So the whole S-curve is trapped between the two endpoints and you just computed; every real config only bends the curve between those anchors. This mirrors the MinHash endpoints 0 matches and all matches from Exercise 5.1 — the two tools agree at the extremes, as they must. WHY it matters: if a config ever gave or you would know the formula was mis-coded — these endpoints are a free correctness check.
Recall Solution 5.3
is division by zero — undefined. A naive implementation crashes or yields . Correct handling: treat (or below a minimum-length floor, e.g. 50 words) as an automatic DROP before computing any ratio. Empty/near-empty docs carry no language-modeling signal anyway. WHY guard first: every ratio filter has a hidden precondition (denominator ). Covering the zero case is not optional — a real crawl has millions of empty scrapes.
Recall Solution 5.4
First, fix the unit: here an -gram means consecutive words, not characters. A 3-word gram like "in the morning" is a short common phrase; a 13-word gram is a specific 13-word string. A 3-word gram appears in millions of innocent docs — a match flags tons of clean text (huge false-positive rate). A 13-word gram is so specific that the chance two unrelated documents share it by accident is astronomically small. The trade-off: longer → fewer false alarms but risks missing paraphrased leakage; shorter → catches more but drowns in coincidences. is the empirical sweet spot: long enough that a match almost certainly means real overlap. See Benchmark Contamination. WHY it matters: skipping decontamination inflates eval scores fraudulently — the model "knew the answers."
Recall Solution 5.5
Lesson: independent strict filters compound multiplicatively, so "one more safe-looking filter" can quietly destroy your token budget. Beyond a point you starve the model of data (Scaling Laws for LLMs) and narrow its style. Curation is budget allocation, not maximal deletion — the parent note's core message.
Recall Self-test checklist
Ratio filters need a non-zero denominator ::: True — guard empty docs upstream LSH candidate prob for similarity , bands , rows ::: LSH endpoints ::: , — every curve is anchored there Exact 50% crossover ::: Effective epochs on a domain ::: , keep Pipeline survival across stages ::: multiply survival fractions, never add losses MinHash estimator variance ::: , shrinks with more hashes