A token is the unit of text a model reads and writes: usually a common word or a word piece. Models have a fixed vocabulary of tokens.
import tiktoken
enc = tiktoken.get_encoding("o200k_base") # OpenAI GPT-4o-family encoding
ids = enc.encode("tokenization is unavoidable")
[enc.decode([i]) for i in ids]
# illustrative split: ['token', 'ization', ' is', ' unavoid', 'able'] -> 5 tokens, 3 words
Whole words fail because new words keep appearing, and any fixed word list would mark them unknown. Characters work, but sequences get much longer, so attention cost grows fast.
Tokens sit in between. A vocabulary of roughly 100k tokens covers any input, because rare words split into known pieces, down to single bytes if needed.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
The diagram below the answer is the concept . Jump to it ↓