All courses

Building a pretraining corpus

Describe the pipeline: web crawl → text extraction → language ID → heuristic and model-based quality filters → deduplication → domain mixture weights. Explain how each step shapes the distribution the model learns to imitate.

Builds on: The next-token cross-entropy objective

▶ Watch this lesson Start the whole course

What the animation says

The model imitates its data

Training minimizes the loss, and that is maximum likelihood. It pulls the model toward whatever text you feed it. A raw web crawl is full of menus, spam, and copies of the same page. And a few languages dominate it. So choosing what text, in what proportions, is not housekeeping. It defines what the model learns to predict.

The pipeline

The crawl sets what can be learned at all. Extraction turns HTML into main text. Leftover boilerplate becomes text the model learns to write. Language ID keeps pages it's confident about, in chosen languages. Unsure ones drop out. Heuristic rules cut pages that are too short, too symbol-heavy, or full of repeated lines. A quality classifier keeps pages resembling trusted text, like encyclopedias and textbooks. Then deduplication, then mixture weights. Your model keeps writing 'Accept all cookies'. Tap the step that let it in.

Every step reweights

Each step is a reweighting of the crawl. Filtering multiplies each page's frequency by keep, which is one or zero. Survivors keep their raw proportions. The rest vanish. But a page copied fifty times counts fifty times. Deduplication collapses it. After that, how much does it weigh compared to a page seen once?

Mixture weights

Equal. One copy, one vote. Now mixing. Each training token comes from a domain with probability equal to its weight. So the loss splits into a sum over domains: weight times that domain's mean loss. The weights add to one. The loss is lowest when the model matches this reweighted data. After filtering: web has 900 billion unique tokens, code 80, books 20. We train on 1000 billion tokens, weighted 70, 20, and 10 percent. How often is each book token seen?

Weights vs. repeats

Ten percent of a thousand billion is one hundred billion book tokens. Divided by twenty billion unique, that's five passes. Code: two hundred over eighty is two and a half passes. Web: seven hundred of nine hundred, about zero point seven eight passes. Some web text is never seen. Books now drive ten percent of the loss instead of two. But repeats teach less each time. Every step picks the distribution your model will imitate.

Who decides what your model imitates?

Minimizing $\mathcal L$ is maximum likelihood. It pushes the model toward the distribution of its training text, whatever that text is. A raw web crawl is full of navigation menus, spam and near-copies of the same page, and it is dominated by a few languages. So choosing *what text, in what proportions* is not housekeeping. It **defines** what the model learns to predict. How is that text chosen, and what does each choice tilt?

The pipeline, step by step

- **Web crawl**: raw pages. Sets what can be learned at all. - **Text extraction**: HTML → main text. Leftover boilerplate becomes text the model learns to write. - **Language ID**: a classifier guesses each page's language with a confidence score. Pages above a threshold in the chosen languages are kept. Pages it is unsure about (mixed-language, code-heavy, very short) drop out too. - **Heuristic filters**: rules such as too short, too many symbols or repeated lines. - **Model-based quality filters**: a classifier keeps pages resembling a reference set of trusted text, e.g. encyclopedia articles and textbooks. - **Deduplication**: exact and near-duplicate pages collapse to one copy. - **Mixture weights**: set each domain's share.

Every step is a reweighting

Let $p_{\text{raw}}(\text{doc})$ be how often a document appears in the crawl. **Filtering** keeps $p(\text{doc}) \propto p_{\text{raw}}(\text{doc})\cdot\text{keep}(\text{doc})$, with $\text{keep}\in\{0,1\}$. **Copies**: a page copied $m$ times counts $m$ times until deduplication sets it to 1. **Mixing**: each training token comes from domain $k$ with probability $w_k$, so the loss splits as $$\mathcal L=\sum_k w_k\,\mathcal L_k,\quad \textstyle\sum_k w_k=1$$ Here $\mathcal L_k$ is the mean loss on domain $k$'s tokens. Cross-entropy is lowest when the model matches this reweighted data (KL $=0$).

Mixture weights override natural sizes

After filtering, unique tokens (billions): web 900, code 80, books 20. Natural shares are 90/8/2%. Plan: train on 1000 billion tokens with $w$ = 70/20/10%. - Web: 700 of 900 → ≈0.78 passes, so some web text is never seen. - Code: 200/80 = 2.5 passes. - Books: 100/20 = 5 passes. Books now drive 10% of $\mathcal L$ instead of 2%. But each book is repeated 5×, and repeats teach less each time.

Remember

The model imitates the corpus, so every pipeline step is a choice of target distribution. Extraction decides what counts as text. Language ID and filters decide which text survives. Deduplication stops copies from multiplying a document's weight. Mixture weights $w_k$ set how much each domain counts in $\mathcal L$, traded against how often small domains repeat.

On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.