Skip to content

B.5 Pass 3: Tokens and Data

A model sees only token ids, and every id comes from a tokenizer and a corpus. If a single id differs from what a published checkpoint expects, the model reads the wrong embedding row; if the corpus is not reproducible, auditable, and free of evaluation text, no later evaluation number can be trusted. This pass builds both sides carefully: tokenizers that match GPT-2 and SmolLM2 exactly in Python and in an independent Rust implementation, and a corpus pipeline that fetches, filters, deduplicates, decontaminates, scrubs, shards, licenses, and tokenizes a corpus deterministically.

Concepts from other sections (39)

This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.

With tokens and data in place, the pass ends with the first real language models beyond the bigram: a Kneser-Ney n-gram model, the strongest count-based baseline, and Bengio’s neural probabilistic language model, the first model whose embeddings and hidden layer are learned. The engine keeps serving the bigram throughout.

Learning objectives

  • Explain how byte-level BPE, WordPiece, and Unigram tokenizers train and encode, and why the GPT-2 byte map is a bijection.
  • Explain how the Rust tokenizer reproduces the Python one exactly and why batching speeds it up.
  • Explain each stage of the corpus pipeline, from fetch to packed token files, and why its output hash is independent of the worker count.
  • Explain how licensing, PII, and decontamination are recorded and enforced.
  • Explain how the n-gram and neural language models are trained and scored in bits per byte.

This pass needs Pass 2, whose autograd trains the neural language model and whose token stream reads the files this pass writes.

The pass opens with the discrete mathematics and probability the tokenizers and models need, then builds the tokenizers, the data structures and tests behind them, the corpus pipeline, and finally the language models:

  1. Injective, surjective, bijective: the GPT-2 byte map. Afterwards you can explain why the GPT-2 byte map is a bijection and how it maps bytes to printable characters.
  2. Trees and tries, longest-prefix match. Afterwards you can explain how a trie finds the longest-prefix match in one pass.
  3. Discrete math 2 problem set, part b: trees, birthday bounds, MinHash and LSH, Bloom filters, recurrences. Afterwards you can work every problem in the set and explain each answer.
  4. Perplexity, bits per byte, NLL accumulator. Afterwards you can explain how perplexity and bits per byte follow from the summed NLL and why the accumulator counts bytes, not tokens.
  5. Categorical sampling: inverse CDF, Gumbel-max, alias method. Afterwards you can explain how inverse-CDF, Gumbel-max, and the alias method each draw from a categorical distribution and what each costs.
  6. MLE, Laplace, absolute discounting. Afterwards you can explain how MLE, Laplace smoothing, and absolute discounting assign probability to unseen events.
  7. Probability problem set, part b: joint distributions, covariance, MLE. Afterwards you can work every problem in the set and explain each answer.
  8. The tokenizer protocol and the char tokenizer. Afterwards you can explain the tokenizer protocol and how the char tokenizer round-trips text.
  9. Byte-level BPE. Afterwards you can trace how byte-level BPE pre-tokenizes, trains merges, and loads a Hugging Face tokenizer to match GPT-2.
  10. WordPiece. Afterwards you can explain how WordPiece’s basic tokenizer splits text and how greedy longest match picks subwords.
  11. The Unigram language model tokenizer. Afterwards you can explain how the Unigram LM trains with EM, segments with Viterbi, and samples subwords.
  12. Tokenizer metrics. Afterwards you can explain what each tokenizer metric measures and how it is computed.
  13. A Robin Hood hash map. Afterwards you can explain how Robin Hood hashing bounds probe lengths and why backward-shift deletion needs no tombstones.
  14. A binary heap with lazy deletion. Afterwards you can explain how a binary heap with lazy deletion skips stale entries.
  15. Fast BPE in Rust. Afterwards you can explain how the Rust fast BPE applies merges, how the byte tokenizer works, and how the streaming decoder holds back incomplete UTF-8.
  16. Property-based tests with Hypothesis, proptest, rapid, and ol_prop.h. Afterwards you can explain which properties the tokenizers and data structures satisfy and how a property-based test shrinks a failing case.
  17. Data licensing and the ledger. Afterwards you can explain what the licensing ledger records for each source and why.
  18. Privacy and PII policy. Afterwards you can explain the privacy and PII policy and which data it lets the pipeline keep.
  19. A Bloom filter. Afterwards you can derive a Bloom filter’s false-positive rate and explain how the number of hashes is chosen.
  20. Python asyncio: event loop, tasks, cancellation, bounded concurrency. Afterwards you can explain how asyncio schedules tasks, how cancellation propagates, and how a semaphore bounds concurrency.
  21. Async fetch with resume, checksums, and license capture. Afterwards you can explain how the async fetcher resumes downloads, verifies checksums, and captures licenses.
  22. Extract, normalize, and quality filters. Afterwards you can trace how the generator stages extract, normalize, and quality-filter documents.
  23. Exact dedup: paragraph hashes, a Bloom screen, and a sort-merge confirm. Afterwards you can explain how paragraph hashes, a Bloom screen, and a sort-merge confirm find exact duplicates.
  24. Near-duplicate dedup: MinHash, LSH, union-find, and decontamination. Afterwards you can explain how MinHash, LSH, and union-find group near-duplicates and how decontamination removes eval overlap.
  25. PII scrub with typed placeholders and audit spans. Afterwards you can explain how the PII scrub substitutes typed placeholders and records audit spans.
  26. Parquet shards, the manifest, and the document-hash split. Afterwards you can explain how Parquet shards and the manifest are written and why the split is decided by document hash.
  27. Tokenize and pack to llm.c .bin. Afterwards you can explain how documents are tokenized and packed into llm.c .bin shards.
  28. Licensing ledger verification and the datasheet. Afterwards you can explain how the ledger is verified against the corpus and what the datasheet reports.
  29. SVD, Eckart-Young low rank, and least squares. Afterwards you can explain why truncated SVD is the best low-rank approximation (Eckart-Young) and how it solves least squares.
  30. Inner products, projections, cosine similarity, and top-k. Afterwards you can explain how projections and cosine similarity relate to inner products and how top-k is selected.
  31. Linear algebra problem set, part b: inner products, SVD and low rank, matmul accounting and the roofline. Afterwards you can work every problem in the set and explain each answer.
  32. Mutual information, PMI, and PPMI. Afterwards you can explain how mutual information, PMI, and PPMI are computed from co-occurrence counts.
  33. Information theory problem set, part b: coding and Huffman, mutual information, maximum entropy, rate-distortion. Afterwards you can work every problem in the set and explain each answer.
  34. n-gram language model with interpolated modified Kneser-Ney. Afterwards you can explain how interpolated modified Kneser-Ney uses continuation counts and three discounts.
  35. Bengio’s neural probabilistic language model. Afterwards you can explain how Bengio’s NPLM turns a context window of embeddings into a next-token distribution.
  36. word2vec skip-gram with negative sampling, and the PPMI-SVD baseline. Afterwards you can explain how skip-gram with negative sampling trains embeddings and how the PPMI-SVD baseline relates to it.
  37. What the System Does After Pass 3. Afterwards you can explain how the corpus pipeline builds a licensed, deduplicated corpus and how the tokenizers and n-gram and neural language models run on it through the CLI.

The stages are also in this pass’s manifest, path.tsv. Pass 4 adds models that carry state across a whole sequence.

Generated from path.tsv.

StageReadDone when
1Injective, surjective, bijective; the GPT-2 byte map
11.2 Injective, surjective, bijective: the GPT-2 byte map
You can explain why the GPT-2 byte map is a bijection and how it maps bytes to printable characters (M05.2).
2Trees and tries, longest-prefix match
12.2 Trees and tries, longest-prefix match
You can explain how a trie finds the longest-prefix match in one pass (M06.2).
3Solve set: trees, birthday bounds, Jaccard/MinHash/LSH S-curve, Bloom FP rate, recurrences
12.5 Discrete math 2 problem set, part b: trees, birthday bounds, MinHash and LSH, Bloom filters, recurrences
You can work every S-M06b problem and explain each answer.
4Perplexity, bits per byte, NLL accumulator
17.2 Perplexity, bits per byte, NLL accumulator
You can explain how perplexity and bits per byte follow from the summed NLL and why the accumulator counts bytes, not tokens (M11.2).
5Categorical sampling: inverse CDF, Gumbel-max, alias method
13.2 Categorical sampling: inverse CDF, Gumbel-max, alias method
You can explain how inverse-CDF, Gumbel-max, and the alias method each draw from a categorical distribution and what each costs (M07.1).
6MLE, Laplace, absolute discounting
13.3 MLE, Laplace, absolute discounting
You can explain how MLE, Laplace smoothing, and absolute discounting assign probability to unseen events (M07.2).
7Solve set: joint and covariance, MLE
13.10 Probability problem set, part b: joint distributions, covariance, MLE
You can work every S-M07b problem and explain each answer.
8Tokenizer protocol, char tokenizer
7.1 The tokenizer protocol and the char tokenizer
You can explain the tokenizer protocol and how the char tokenizer round-trips text (L1.1).
9Byte-level BPE (GPT-2 compatible): pre-tokenizer, trainer, HF loader
7.2 Byte-level BPE
You can trace how byte-level BPE pre-tokenizes, trains merges, and loads a Hugging Face tokenizer to match GPT-2 (L1.2).
10WordPiece (BERT basic tokenizer + greedy longest match)
7.3 WordPiece
You can explain how WordPiece’s basic tokenizer splits text and how greedy longest match picks subwords (L1.3).
11Unigram LM tokenizer (EM, Viterbi, subword sampling)
7.4 The Unigram language model tokenizer
You can explain how the Unigram LM trains with EM, segments with Viterbi, and samples subwords (L1.4).
12Tokenizer metrics
7.6 Tokenizer metrics
You can explain what each tokenizer metric measures and how it is computed (L1.6).
13Robin Hood hash map with backward-shift deletion
15.5 A Robin Hood hash map
You can explain how Robin Hood hashing bounds probe lengths and why backward-shift deletion needs no tombstones (ds.05).
14Binary heap with lazy deletion
15.6 A binary heap with lazy deletion
You can explain how a binary heap with lazy deletion skips stale entries (ds.06).
15Rust fast BPE (tl-tok), byte tokenizer, streaming decoder
7.5 Fast BPE in Rust
You can explain how the Rust fast BPE applies merges, how the byte tokenizer works, and how the streaming decoder holds back incomplete UTF-8 (L1.5).
16Property-based tests (R4) with Hypothesis, proptest, rapid, and ol_prop.h
3.2 Property-based tests with Hypothesis, proptest, rapid, and ol_prop.h
You can explain which properties the tokenizers and data structures satisfy and how a property-based test shrinks a failing case (craft.04).
17Data licensing and the ledger
33.1 Data licensing and the ledger
You can explain what the licensing ledger records for each source and why (ethics.01).
18Privacy and PII policy
34.1 Privacy and PII policy
You can explain the privacy and PII policy and which data it lets the pipeline keep (ethics.02).
19Bloom filter
15.8 A Bloom filter
You can derive a Bloom filter’s false-positive rate and explain how the number of hashes is chosen (ds.08).
20Python asyncio: event loop, tasks, cancellation, bounded concurrency
1.8 Python asyncio: event loop, tasks, cancellation, bounded concurrency
You can explain how asyncio schedules tasks, how cancellation propagates, and how a semaphore bounds concurrency (lang.08).
21Async fetch with resume, checksums, license capture
5.1 Async fetch with resume, checksums, and license capture
You can explain how the async fetcher resumes downloads, verifies checksums, and captures licenses (data.01).
22Extract, normalize, quality filters (generator stages)
5.2 Extract, normalize, and quality filters
You can trace how the generator stages extract, normalize, and quality-filter documents (data.02).
23Exact dedup: paragraph hashes, Bloom screen, sort-merge confirm
5.3 Exact dedup: paragraph hashes, a Bloom screen, and a sort-merge confirm
You can explain how paragraph hashes, a Bloom screen, and a sort-merge confirm find exact duplicates (data.03).
24Near-duplicate dedup: MinHash, LSH, union-find, and decontamination
5.4 Near-duplicate dedup: MinHash, LSH, union-find, and decontamination
You can explain how MinHash, LSH, and union-find group near-duplicates and how decontamination removes eval overlap (data.04).
25PII scrub with typed placeholders and audit spans
5.5 PII scrub with typed placeholders and audit spans
You can explain how the PII scrub substitutes typed placeholders and records audit spans (data.05).
26Parquet shards, manifest, and the document-hash split
5.6 Parquet shards, the manifest, and the document-hash split
You can explain how Parquet shards and the manifest are written and why the split is decided by document hash (data.06).
27Tokenize and pack to llm.c .bin
5.7 Tokenize and pack to llm.c .bin
You can explain how documents are tokenized and packed into llm.c .bin shards (data.07).
28Licensing ledger verification and the datasheet
5.8 Licensing ledger verification and the datasheet
You can explain how the ledger is verified against the corpus and what the datasheet reports (data.08).
29SVD, Eckart-Young low rank, and least squares
9.5 SVD, Eckart-Young low rank, and least squares
You can explain why truncated SVD is the best low-rank approximation (Eckart-Young) and how it solves least squares (M03.5).
30Inner products, projections, cosine similarity, and top-k
9.6 Inner products, projections, cosine similarity, and top-k
You can explain how projections and cosine similarity relate to inner products and how top-k is selected (M03.6).
31Linear algebra problem set, part b: inner products, SVD and low rank, matmul accounting and the roofline
9.8 Linear algebra problem set, part b: inner products, SVD and low rank, matmul accounting and the roofline
You can work every S-M03b problem and explain each answer.
32Mutual information, PMI, and PPMI
17.3 Mutual information, PMI, and PPMI
You can explain how mutual information, PMI, and PPMI are computed from co-occurrence counts (M11.4).
33Information theory problem set, part b: coding and Huffman, mutual information, maximum entropy, rate-distortion
17.5 Information theory problem set, part b: coding and Huffman, mutual information, maximum entropy, rate-distortion
You can work every S-M11b problem and explain each answer.
34n-gram language model with interpolated modified Kneser-Ney
8.1 n-gram language model with interpolated modified Kneser-Ney
You can explain how interpolated modified Kneser-Ney uses continuation counts and three discounts (L2.1).
35Bengio’s neural probabilistic language model
8.2 Bengio’s neural probabilistic language model
You can explain how Bengio’s NPLM turns a context window of embeddings into a next-token distribution (L2.2).
36word2vec skip-gram with negative sampling, and the PPMI-SVD baseline
8.3 word2vec skip-gram with negative sampling, and the PPMI-SVD baseline
You can explain how skip-gram with negative sampling trains embeddings and how the PPMI-SVD baseline relates to it (L2.3).
37What the system does after Pass 3
B.5.1 What the System Does After Pass 3
You can explain how the corpus pipeline builds a licensed, deduplicated corpus and how the tokenizers and n-gram and neural language models run on it through the CLI.