Charts · 33
How text becomes tokens
A language model never sees letters. Before your words reach it, a tokeniser cuts them into pieces from a fixed vocabulary and swaps each piece for a number, and the numbers are all the model gets. Common words are one piece, rare ones are several, and a character can be split across pieces. Here are the same sentences through four tokenisers in real use, every chip one token exactly as each returned it, and the reason the strawberry question trips models up.
How many r's are in strawberry? 31 characters · 31 bytes
The question is eight or nine tokens and ' strawberry', with its space, is one of them. The model is asked about letters inside a token it receives as a single number.
- How
- many
- r
- 's
- are
- in
- strawberry
- ?
- How
- many
- r
- 's
- are
- in
- strawberry
- ?
- How
- many
- r
- 's
- are
- in
- strawberry
- ?
- How
- many
- r
- '
- s
- are
- in
- strawberry
- ?
Hover a chip for its id. · is a space, ↵ a newline; a chip in hex is a token that is only part of a character.
What GPT-4o actually receives[5299, 1991, 428, 885, 553, 306, 101830, 30]
Why it cannot count the r’s in strawberry
To GPT-4o, strawberry is [302, 1618, 19772]: “st”, “raw”, “berry”. None of those is the letter r. Gemma 3 has the whole word as one piece, which hides the letters completely. Whatever a model knows about how its pieces are spelt, it had to learn as a fact about numbers: it cannot look. Spell the word out with spaces and every letter becomes its own token, and the count is suddenly easy.
| Input | cl100k_base | o200k_base | Llama 3 | Gemma 3 |
|---|---|---|---|---|
strawberry |
|
|
|
|
strawberry |
|
|
|
|
Strawberry |
|
|
|
|
STRAWBERRY |
|
|
|
|
strawberries |
|
|
|
|
strawberry |
|
|
|
|