Internals · 6 min read
Tokens: the unit your model actually sees
Every prompt you send is converted into a sequence of integer IDs before the model reads a word of it. Many of the strange failures you hit in production start at that step.
How text becomes tokens
Most modern tokenizers use byte-pair encoding. Training starts from raw bytes and repeatedly merges the most frequent adjacent pair into a new token, until the vocabulary reaches a target size, often somewhere between 50,000 and 200,000 entries.
Frequent words end up as a single token, usually with the leading space attached, so “ the” and “the” are different IDs. Rare words, typos and long numbers are split into several pieces, and where those splits fall is not always intuitive.
What this explains
Character-level tasks are hard because the model never sees characters. Counting letters or reversing a string means reasoning about pieces it cannot look inside, and arithmetic on long numbers suffers when digits are grouped unevenly.
Whitespace matters too. A stray trailing space at the end of a prompt can shift the output, because it changes which token the model expects to come next.
Tip: before debugging a strange output, run the prompt through the model's own tokenizer and look at the actual pieces.