20  Data for Language Models

By now you can download a pretrained model and measure what it does (Chapter 18). The text it learned from was prepared by someone else and, for many released models, never published; yet preparing it is a large part of the work of training a language model. It starts from billions of web pages, and every decision made before the first batch changes what the model can ever learn: what to extract from a page, what to throw away, what to read twice, and how to cut the rest into tokens.

For a long time such decisions were made by rules of thumb and seldom published. The open corpora of the last few years publish the pipeline together with the experiments behind it, so that others can check a choice about data. This chapter builds one that a single machine can hold, from a record of a web crawl to a token in a file on disk. It measures what each step changes and writes every decision into a manifest, so that the corpus can be rebuilt from hashes, audited, and corrected when a page has to be removed.

The chapter moves in three steps. The first decides which documents exist: it extracts text from pages (Section 20.1), filters the text and audits whose pages the filters remove (Section 20.2), and takes out near-copies and leaked test items (Section 20.3). These steps are measured on the documents of a quarter of one Common Crawl archive file, each set beside the text that FineWeb, a released corpus, kept from the same record. The second step decides how often a model reads each kind of text, and there the measure is a model: small proxy runs choose the domain weights (Section 20.4) and test whether text rewritten by a model can stretch a source that has run short (Section 20.5). The third cuts the text into tokens and writes the files on which Chapter 21 trains the book’s reference model (Section 20.6). The second and third steps start from FineWeb-Edu as released, which holds far more text.

Streaming the token files into training batches belongs to the next chapter, and the data that teach a model to follow instructions and preferences belong to Chapter 24 and Chapter 25. We assume you know byte-level BPE (Section 8.2), why bits per byte can compare models with different tokenizers (Section 18.4.3), how a paired comparison puts an error bar on a difference (Section 18.5), and what a text embedding is (Section 19.3).

The long computations, labelling pages with a model of 27 billion parameters and training dozens of small language models, ran once on four 24 GB GPUs, and their results ship with the book. Each notebook downloads them, checks them against its configuration and repeats a small part; without a GPU it skips what needs one and says so. Common Crawl grants no licence for the pages it archives, so the book publishes only byte ranges and hashes, from which the notebooks rebuild the documents. No notebook calls a paid service.

Resources and Further Reading

The resources below accompany the sections of this chapter, and each names the section it goes with. All are freely accessible online. If you read only three, read the FineWeb blog post, the data chapters of the Smol Training Playbook and the pipeline guide of the tokenizers library: between them they cover how a filter is tested by training on its output, how a mixture is planned, and how a tokenizer is assembled. The chapter has no notebook of further reading.

Courses

Building a web corpus

Mixtures and generated text

  • The Smol Training Playbook plans the data of a small model from start to finish, with chapters on mixtures, annealing and synthetic data that accompany Section 20.4 and Section 20.5.
  • The reference implementations of RegMix and DoReMi are the full-scale versions of the two methods that Section 20.4 builds in miniature, and the Dolma 3 pool card lists the sources behind the released mixture that the section reads as a case study.
  • The cards of Nemotron-CC-v2 and Cosmopedia describe a rephrased crawl and a corpus generated from seeds, with their generators, prompts and licences, the two kinds of synthetic data of Section 20.5.

Tokenizers

  • The pipeline guide of the tokenizers library explains the normalizer, pre-tokenizer, model and decoder from which Section 20.6 assembles the reference tokenizer.
  • SentencePiece trains the unigram and BPE models that Section 20.6 compares, and its documentation states the normalization defaults that the section turns off.
  • minbpe writes byte-level BPE in a few hundred lines, a second implementation to read beside the tokenizer of Section 8.2.