liveBook · Manning

Tokenization

As explained in Build a Reasoning Model (From Scratch)

The process of rendering text into a model-ready format and splitting it into tokens/IDs for training.

Tokenization prepares text for model training by rendering prompts and answers, converting them into token IDs, and recording boundaries needed by the training loss. section 8.4 section 8.4.2

A practical tokenization pipeline:

  • Render and tokenize the prompt. section 8.4.2
  • Format and tokenize the teacher answer. section 8.4.2
  • Concatenate prompt and answer IDs, append an end-of-sequence token, and store prompt length. section 8.4.2
  • Decode a processed example to verify chat formatting, reasoning tags, and termination. section 8.4.2

Inspecting a distilled math example

A formatted sample contains a user chat prompt, an assistant answer wrapped with <think></think>, a final boxed result, and <|im_end|> termination. section 8.4.2

Figure 8.7 Bringing the loaded dataset into a format suitable for model training by understanding the tokenizer, tokenizing the examples, and filtering and splitting the dataset

Use the workflow figure to trace dataset loading, tokenizer use, tokenization, filtering, and splitting before training. section 8.4

How Build a Reasoning Model (From Scratch) covers it

How deep it goes
Explains encoding, concatenation, boundary recording, inspection, and filtering, but stops short of tokenizer internals.
Examples
Uses a decoded math problem with a reasoning trace, boxed answer, chat markers, and an end-of-sequence token.
What it assumes
Assumes a loaded tokenizer and dataset while defining tokens, token IDs, and complete training epochs.
What you can do after
Builds tokenized training examples with encoded prompts, answers, sequence IDs, prompt lengths, and validation checks.
How it connects
Connects tokens and token IDs to language models, chat templates, supervised fine-tuning, and loss masking.

Also explained in

Compare how 25 books explain tokenization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Reasoning Model (From Scratch). The section links point to the parts of the book it draws on.