sagelearnai

Tokens: How Models Read Text

A language model never sees characters or words. It sees a sequence of integers — token IDs — drawn from a fixed vocabulary, typically 32k–200k entries. Everything about cost, context length, multilingual quality and even some famous failure modes ("how many r's in strawberry?") traces back to this step.

Raw text"unhappiness!" Pre-tokenizesplit on regex / spaces Apply BPE merges"un" "happiness" "!" Token IDs[403, 71, 0] The IDs index rows of the embedding matrix, the model's real input. (IDs are illustrative.)
The tokenization pipeline.

In this lesson

  • Why not characters or words?
  • Byte-Pair Encoding (BPE)
  • Pre-tokenization
  • Consequences that matter in practice
  • Hands-on: count tokens

This lesson is part of AI Engineering. Unlock the full course to read it, take the quiz and track your progress.

See plans →

Last reviewed 2026-11-05.