Why subword tokens: characters vs words
Compare character, word and subword vocabularies on vocabulary size, sequence length and handling of unseen words. Explain why subwords are the practical compromise.
Builds on: What an LLM computes, end to end
What the animation says
One choice, three costs
A model reads and predicts tokens from a fixed list, the vocabulary. So what should one token be: a single character, a whole word, or something in between? That one choice sets three things. How big the vocabulary is. How many tokens a text uses up in the context window. And what happens to a string the model has never seen, like a typo. Suppose tokens are raw bytes, just two hundred fifty-six of them. Which of these can it not write?
Characters vs words
Here's the answer: nothing is out of reach. Every string is a sequence of bytes, so bytes can write anything. The price is length: running, with its space, takes eight tokens, each nearly meaningless. Whole words flip that. Sequences are short, but the vocabulary explodes with inflections, names, typos and code. Run and running become unrelated entries, and rare words show up only a handful of times. Anything off the list collapses into one unknown token, and its spelling is gone. Tap the words in this sentence that this vocabulary would lose.
Subwords: whole or in pieces
Subwords sit in between. Common strings get their own token, like the, or model, with a leading space. Rarer words are built from reusable pieces: unhappiest might become un, happ, iest. A function name splits the same way, into get, User, By, Id. Single characters or bytes stay as a fallback, so even teh can be written, with no unknown token. Related words can share pieces, like run inside running. Typical vocabularies: thirty thousand to two hundred thousand tokens, about four characters each in English.
The cost formulas
First, length: token count is roughly characters divided by characters per token. A thousand characters: a thousand character tokens, or about two hundred fifty subword tokens. So a token window holds characters-per-token times as many characters. Then the vocabulary: the embedding table stores one row of d numbers per token. The unembedding is just as big, and costs as many multiply-adds at every position. With d of four thousand ninety-six and a million words, how big is the table?
The numbers decide it
About four billion: a million rows of four thousand ninety-six numbers. And rare words are still missed. Characters need only about one million numbers. Subwords at fifty thousand: about two hundred million. Now fill a window of about eight thousand tokens. With characters, that's about eight thousand characters, roughly fourteen hundred words. With subwords at four characters per token, about thirty-three thousand characters, roughly fifty-seven hundred words. Subwords: a moderate vocabulary, four times the text per window, and every string can be written.
Characters vs words: opposite failures
Subwords: frequent whole, rare in pieces
The cost formulas
Numbers: d = 4096, window = 8,192
Remember
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