Behavioral artifacts of tokenization
Predict tokenization-caused failures: counting letters, reversing strings, digit arithmetic, leading-space variants, and higher token cost for non-English text. Explain each from the fact that the model never sees characters directly.
Builds on: Byte-pair encoding tokenizers
What the animation says
Five bugs, one cause
A language model can write a sonnet, then tell you strawberry has two r's. It also garbles reversed words, slips on long addition, and stumbles when a prompt ends in a space. And the same sentence in Hindi costs more than in English. These look like five separate bugs. They share one cause. So when you type strawberry, what does the model actually receive?
The model reads ids
Here is what arrives. In one real tokenizer, strawberry becomes three chunks, and each chunk becomes one number. The tokenizer keeps the table of which text each id stands for. The model never sees that table. It is like reading a book where every chunk is replaced by a codebook number. You learn meaning from context. You know a chunk's spelling only if you memorized it as a separate fact. So to count r's, the model must recall each chunk's spelling, then add. Tap every chunk that contains an r.
Reversing and digits
Reversing a word is harder still. The model must recall every spelling, then move letters across chunk borders. Watch the last letter of berry jump all the way to the front. Numbers have the same problem. Tokenizers chunk digit strings by how often they appear, not by place value. Here, four eight two one splits after three digits, while three nine oh seven splits after two. To add, the ones digits must line up. Tap the two chunks that hold the ones digits.
The trailing space
Next, whitespace. A space usually rides on the following word, so space-Paris is a single token. Space-Paris and plain Paris are different ids. Now end a prompt with a trailing space: the capital of France is, then a space. That space becomes a lone token of its own. So what must the model produce next?
Bytes per word
Answer: after a lone space, it needs a space-less Paris. That pairing is rare in text, so output gets shakier. Last failure: cost. Tokenizers start from UTF-8 bytes and merge frequent byte runs. This loop prints code points and bytes for one greeting in four scripts. English: five and five. Russian: six and twelve. Hindi: six and eighteen. Japanese: five and fifteen. An English-heavy tokenizer has few merges for Devanagari, so text stays near raw bytes. That means more tokens, higher cost, and less fits in context.
One cause
One cause sits behind all five. The model sees opaque ids, never characters. Tasks that need letters or digit positions force it to recall hidden spellings, so expect errors there. Exact whitespace can create rare splits. And scripts rare in the merge data split into more tokens, so they cost more and less of them fits. When a model fails oddly, ask: did this task need what the ids hide?
The model reads ids, not letters
Five predictable failure types
Tracing the failures by hand
Bytes per word: worst-case token count
words = ["hello", "привет", "नमस्ते", "こんにちは"]
for w in words:
b = w.encode("utf-8")
print(f"{w}: {len(w)} code points, {len(b)} bytes")
# hello: 5 code points, 5 bytes
# привет: 6 code points, 12 bytes
# नमस्ते: 6 code points, 18 bytes
# こんにちは: 5 code points, 15 bytes
Remember this
On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.
Bytewise
All courses