4.3.4 · D1Pretraining & Fine-Tuning LLMs

Foundations — Pretraining data curation and cleaning

3,422 words16 min readBack to topic

This page assumes nothing. We build every letter, slash, and squiggle the parent note (Pretraining Data Curation and Cleaning) throws at you, in an order where each idea leans on the one before it.


0. The picture behind everything: a pile of documents

Imagine a giant bag of scraps of text — web pages, comment threads, menus, articles. Curation is the act of sorting this bag: throw out the junk, throw out the copies, keep the good stuff. Two questions repeat everywhere:

  • How junky is this one scrap? → answered with ratios.
  • Are these two scraps secretly the same? → answered with sets and probabilities.

Hold that bag in mind; every symbol below is a tool for one of those two questions. Figure 1 draws this bag and the two questions it splits into.

Figure — Pretraining data curation and cleaning

Figure 1 — The corpus as a bag of coloured scraps. The magenta arrow leads to Q1 ("how junky?", answered by ratios); the violet arrow leads to Q2 ("are two the same?", answered by sets and probability).


1. Counts: , , , ,

Why does the topic need counts? Because the only cheap thing you can do to a trillion tokens is tally features of them. You never "understand" a page; you count its ingredients and judge by the recipe.


2. Ratios: turning two counts into a fair judgment

Two of the parent's ratios use only counts you already have (§1), so we can read them now:

  • ("symbols per word"): small for prose (), large for symbol-spam.
  • ("fraction of lines that are repeats"): a number between and .

A third ratio, ("effective epochs"), also has this bad-count-over-total shape, but its pieces (, , ) aren't built yet — we assemble it in §7. The subscript (the little text below, like the "sym" in ) is just a name tag so you know which ratio; it changes nothing about the maths. Figure 2 shows why the ratio, not the raw count, is the fair judge.

Figure — Pretraining data curation and cleaning

Figure 2 — A short doc and a long doc with different raw symbol counts land on the same value because dividing by word count cancels length. The violet wall at then judges both fairly.


3. Thresholds and the symbols , , , , , ,

Two Greek letters name thresholds throughout the topic:

  • (tau) — the language-keep wall (a probability threshold we meet properly in §4), with a typical value .
  • (theta) — the near-duplicate wall, e.g. call docs duplicates if with .

4. Probability: the symbol and

A probability is itself a ratio: (favourable outcomes) / (all outcomes). So it fits the §2 mental model perfectly — it's a fraction that always lands in .

Now the language rule from the pipeline reads cleanly: keep a doc if . In words — keep it if the classifier's confidence that the doc is English clears the language wall (from §3).


5. Sets, and the symbols , , ,

A -shingle is how we fill the circles. First, what is ? It is just a whole number you pick, at least (an integer ) — it sets how long each chunk is. To shingle a document: chop it into every overlapping run of consecutive words. With , the text "the cat sat on" becomes the set . Small (like ) makes almost everything overlap (too loose); large (like ) demands long identical runs (too strict) — typical near-dedup uses around to words. Two docs sharing many shingles overlap a lot. Figure 3 draws the two circles and names each region.

Figure — Pretraining data curation and cleaning

Figure 3 — Two document sets and as overlapping circles. The central lens is (shared shingles); the whole blob is ; Jaccard is the lens divided by the blob.


6. Functions and the "min", "hash", "argmax" tools


7. Putting the last ratio together: , , , , and

Now that counts and ratios are solid, the mixture formula reads cleanly.


8. Big-O: the symbols and


The prerequisite map — how these foundations feed the topic

The diagram below is a teaching aid, not decoration: read it top-down as a dependency chain. Counts (top) are the raw material; they branch into ratios (the left path, feeding quality filtering) and into sets → Jaccard → probability → minhash (the right path, feeding deduplication). Big-O joins in to explain why dedup must be clever. All three coloured paths converge on the parent's curation pipeline at the bottom — so nothing on the parent page floats free of these roots.

Counts W S L D N

Ratios divide count by count

Thresholds tau theta and compare signs

Quality filtering stage

Sets intersection union size

Jaccard similarity J

Probability p and Pr

MinHash equals Jaccard

Deduplication stage

Big-O work grows with N

Effective epochs e_d

Domain mixing stage

Curation pipeline

Ready to go deeper into the moving parts? See Tokenization (how words become the shingles and tokens we count), MinHash and LSH (the dedup engine), Deduplication and Memorization, Benchmark Contamination, Data Mixture and Domain Weighting, and Scaling Laws for LLMs (why token budgets are fixed).


Equipment checklist

Read the item as a question, then reveal to check yourself.

What does the fraction bar in mean and why use a ratio here?
It means " divided by "; we use a ratio to cancel document length so the same threshold judges a tweet and a novel fairly.
What does tell you to do?
Drop the document — symbol density this high signals SEO/menu spam, not prose.
What should happen when or before computing a ratio?
The ratio is undefined (division by zero); drop the empty document as a special case instead of evaluating the fraction.
How do and differ?
is the number of whole documents in the entire corpus; is the token count available in one domain — same letter, unrelated quantities, flagged by the subscript.
What does the subscript in or change about the maths?
Nothing — it's just a name tag identifying which domain / which ratio.
What is the difference between and ?
is "greater than or equal to", is "smaller than or equal to" — mirror images deciding which side the wall itself belongs to.
Read in plain words.
Keep the doc if the classifier's confidence it is English exceeds the language-keep wall .
What do curly braces denote?
The set containing exactly the listed items — order does not matter and repeats are collapsed.
What is in a -shingle and how is it chosen?
is a whole number setting the chunk length; small is too loose, large too strict, typically words.
Draw the picture for and .
Two overlapping circles: is the lens where they cross; is the whole blob covered by either.
What is a -shingle?
A set of every overlapping run of consecutive words in a document.
State Jaccard and say what vs mean.
; identical sets, no shared chunk.
What happens to when both sets are empty?
makes it , undefined; define it by convention (usually ) or drop empty docs first.
What is ?
Stamp every shingle in with hash , take the smallest resulting value.
Why does make dedup fast?
It lets a cheap probability of matching hashes estimate the expensive set-overlap, avoiding all-pairs comparison.
What does enforce?
The domain weights are shares of a whole, so they add up to one like pie slices.
What must you do with a domain where before using ?
Exclude it first (it would divide by zero) and renormalise the remaining weights to sum to 1.
Interpret .
You pass through domain 's data one and a half times during training.
Contrast and , and say what counts here.
is the number of documents; work doubles when docs double, quadruples — comparing every pair, infeasible at a billion docs.