An LLM never sees raw text. So what does it process?
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Of all the words in the LLM vocabulary, 'token' is the one most worth getting precisely right. Pricing pages, context window specifications, latency benchmarks, and most prompt engineering folklore all live in token units. Reasoning about an LLM workload in characters or words quietly produces wrong answers.
The byte-level definition
A token is an integer id between 0 and vocab_size minus 1, drawn from a fixed vocabulary defined by a specific tokenizer. The id points to a particular byte sequence. For byte-level BPE tokenizers (tiktoken's cl100k_base and o200k_base, the Llama 3+ tokenizer, newer Mistral, DeepSeek V4) the byte sequence is a chunk of UTF-8 bytes. It usually represents a sub-word fragment of text, but sometimes a whole short word or a piece of whitespace.
The id is the only thing the model ever sees. The embedding matrix is indexed by token id: each row is a learned vector for the token at that index. The output projection (lm_head) produces a logit per token id at every position. The model has no separate concept of characters; it works entirely in this discrete vocabulary.
The split between text and ids is strict. On the input side, the tokenizer converts the text string into a list of ids. On the output side, the tokenizer converts the model's emitted ids back into bytes and decodes them as UTF-8 to recover text. The model itself is blind to bytes.