The first step of the transformer pipeline, and the one with the most surprising downstream effects. Models don’t read text, they read integer IDs. Tokenization is the step that converts your prompt into a sequence of those integers.

How It Works

A tokenizer maps a string to a sequence of integers, each pointing to an entry in a fixed vocabulary (modern vocabularies run from tens of thousands to a few hundred thousand entries). The model only ever receives IDs from that list, and works with the number, not the written word.

Tokens are usually subword pieces, not whole words:

  • “tokenization” → [“token”, “ization”]
  • “running” → [“run”, “ning”]

This is a deliberate middle ground:

  • Whole-word vocabularies are too big and can’t handle new words.
  • Character-level vocabularies are too small and force the model to learn even simple patterns from scratch.
  • Subword sits between: common pieces become single tokens, rare or novel words get composed from smaller pieces.

Different families use different tokenizers: GPT models use Byte Pair Encoding (BPE) variants; LLaMA-style models commonly use SentencePiece. The choice affects compute (fewer tokens = less work) and multilingual coverage, but the shape is always the same: text in, integers out.

Why It Causes Weird Failures

The "strawberry" problem

Ask an LLM how many R’s are in “strawberry” and older models got it wrong. That’s not a counting failure — it’s that the model never operates on letters. It sees token IDs that happen to spell a word a human would split letter by letter. Many “the model can’t do basic X” complaints trace back to tokenization, not reasoning.

Why It Matters Beyond the Trivia

Tokenization is the unit of everything downstream:

  • Context cost. Context windows and pricing are measured in tokens, not words or characters. Fewer tokens per idea means more fits in context and cheaper inference. This is the substrate under Context Window Management Strategies and Context Engineering.
  • Quadratic attention. Since attention cost grows with the square of the token count, token efficiency directly affects how expensive a long prompt is.
  • Multilingual fairness. Languages that tokenize into more pieces cost more tokens for the same meaning, so the tokenizer quietly shapes which languages are cheap to use.