All courses

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

▶ Watch this lesson Start the whole course

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.

What should one token be?

The model reads and predicts tokens from a fixed list, the vocabulary. Should a token be a single character, a whole word, or something in between? This one choice fixes three things: - the vocabulary size $V$ - how many tokens $T$ a given text uses up in the context window - what happens to a string the model has never seen, such as a typo, a new name or a function name in code

Characters vs words: opposite failures

**Characters:** $V$ is tiny. It is a few hundred for most text, and exactly 256 if you use raw bytes, which can encode any string, so nothing is ever unseen. But an English word takes 5–6 tokens (its letters plus a space), and each token carries almost no meaning on its own. **Words:** sequences are short, but $V$ explodes with inflections, names, typos and code. Rare words appear only a handful of times in the data. Anything outside the list becomes one **unknown token**, so its spelling is lost. "run" and "running" are also unrelated entries.

Subwords: frequent whole, rare in pieces

A **subword** vocabulary gives common strings their own token (" the", " model"). Rarer words are built from reusable pieces. For example, " unhappiest" might become " un" + "happ" + "iest". Single characters, or raw bytes, stay in the vocabulary as a fallback. So *any* string can be written, and no unknown token is ever needed. Related words share pieces. Typical $V$: 30k–200k. English averages about 4 characters per token.

The cost formulas

Take a text of $n$ characters and let $c$ be the average number of characters per token: $$T \approx n/c$$ So a window of $T$ tokens covers about $c\cdot T$ characters. The embedding table $W_E$ holds $V\times d$ numbers. At every position, the unembedding $W_U$ (also $V\cdot d$ numbers) turns $d$ numbers into $V$ logits, about $V\cdot d$ multiply-adds. Both costs grow in proportion to $V$. | | $c$ | $V$ | unseen strings | |---|---|---|---| | char/byte | 1 | ~256 | fine | | word | ~5.7 | ≥10⁶ | unknown | | subword | ~4 | ~50k | fine |

Numbers: d = 4096, window = 8,192

Embedding table size is $V\times 4096$. The unembedding is the same size: - char, $V=256$: about 1.05M numbers - word, $V=10^6$: about 4.1B numbers, and rare words are still missed - subword, $V=50{,}000$: about 205M numbers Text that fits in the window: - char: 8,192 characters, about 1,400 words - subword: $8{,}192\times4\approx$ 32,800 characters, about 5,700 words Subwords give 4× more text per window than characters, at a moderate table size.

Remember

Characters keep $V$ small but make sequences long and each token nearly meaningless. Words make sequences short but blow up $V$ and turn anything new into an unknown token. Subwords keep common strings whole, split rare ones into pieces, and fall back to characters or bytes. The result is a moderate $V$, about 4 characters per token, and every string can be written without an unknown token.

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.