Skip to main content

Tokenization and tokenizers: a domain map

Understanding units, mechanisms, design, and evaluation

Where should you go deeper on tokenization?

The main learning path’s From text to tokens lesson establishes the minimum contract: text is converted into tokens and then into IDs compatible with the tokenizer paired with the model weights. This page does not add a mandatory step. It is a navigation map for understanding the choices behind that interface, building a tokenizer, or evaluating its consequences.

The domain connects several objects that should remain distinct: the character string, its Unicode and UTF-8 representations, the units produced by segmentation, the vocabulary and its IDs, the corpus that may be used to fit the tokenizer, and the metrics used to evaluate the result.

Two different operations: encoding and training

A tokenizer is involved in two contexts that should not be confused:

  • Encoding an input: applying an already fixed tokenizer to a prompt or text to produce an ordered sequence of IDs. This is the interface used at inference time.
  • Building or fitting a tokenizer: preparing a corpus, selecting data, and learning or adjusting a vocabulary and segmentation rules before fixing the tokenizer alongside the model.

flowchart TB
  subgraph build["Build — model construction"]
    A["Corpus"] --> B["Preparation and filtering"]
    B --> C["Tokenizer training / fitting"]
    C --> D["Fixed vocabulary and rules"]
  end
  subgraph encode["Use — model input"]
    E["Input text"] --> F["Optional preprocessing"]
    F --> G["Segmentation"]
    G --> H["Tokens"]
    H --> I["IDs"]
    I --> J["Embedding lookup"]
  end
  D -. "compatible tokenizer" .-> G

Corpus preparation and tokenizer training belong to the Build path. Encoding a prompt does not relearn the vocabulary on every request. Training a tokenizer is not training the LLM’s weights: it fits a discrete representation from a corpus and then freezes it; neural-model training subsequently uses that interface.

Map of questions

Question Page Useful prerequisites Specific contribution
How is a character string represented before segmentation? Unicode, UTF-8, and normalization None; From text to tokens provides the LLM context. Distinguish abstract characters, code points, bytes, and normalized forms.
Why can the same text produce different sequences? Tokenization strategies From text to tokens; Unicode helps with edge cases. Compare granularities, pipeline components, BPE, WordPiece, and Unigram.
How should vocabulary size and tokenizer choices be compared? Designing and evaluating a tokenizer Tokenization strategies; basic measurement and experimental evaluation. Connect length, budgets, system costs, metrics, and downstream quality.
How should data be prepared and a model’s tokenizer fitted? Corpus preparation The Build path, especially corpus and data-splitting concepts. Cover sources, filtering, deduplication, splitting, and fitting in the Build context.
How do IDs become training examples? Training examples The Build path and the text → IDs interface. Move from an ID stream to windows, shifted targets, masks, and packed sequences.

Routes by objective

These routes are suggestions, not a universal sequence. Choose according to the question and the knowledge you already have.

Practice and experiments

Exercises remain separate from lessons: use the text → IDs → embeddings trace and the tokenization-strategy exercises. They let you verify the mechanisms without bloating explanatory pages.

Return point: after a deep dive, resume the Understand path from text, then continue to embeddings.