Why not words, and why not characters
A vocabulary of whole words cannot be finished. New words, names, typos and inflections arrive forever, and every one of them becomes an unknown token the model cannot read.
Characters solve that completely and make the sequences several times longer, which costs quadratic attention time for no gain in meaning.
Subword tokenisation is the compromise: common words stay whole, rare words break into pieces, and nothing is ever unknown.
Byte pair encoding, the algorithm
- Start with the vocabulary as the set of single bytes.
- Count every adjacent pair in the training corpus.
- Merge the most frequent pair into one new token.
- Record that merge in an ordered list.
- Repeat until the vocabulary reaches the target size.
The merge list is the tokeniser. Encoding a new string means applying the same merges in the same order, which is deterministic and fast.
Starting from bytes rather than characters is what guarantees no unknown token: any input, in any language or encoding, is some sequence of 256 possible bytes.
What a token costs
That ratio is the one to remember for cost and context estimates, and it holds only for English.
Hindi, Thai and Tamil take 2 to 4 times more tokens per word.
A tokeniser trained mostly on English spends more tokens per word on everything else, so the same sentence costs several times as much to process in another script.
That is a fairness and a pricing problem at once, and recent tokenisers with larger vocabularies exist largely to reduce it.
The parts that leak into model behaviour
The leading space is part of the token, which is why a prompt ending in a space produces noticeably worse continuations: it forces the model onto the rarer no-space variants.
Numbers are split by whatever the merge list happened to learn, so 1234 may be one token or four, and arithmetic errors often trace back to that rather than to reasoning.
Ask a model to count the letters in "strawberry".
A model sees three tokens, not ten letters, so character-level questions are hard for a structural reason and not because the model is careless.
The variants in use
BPE merges the most frequent pair. WordPiece merges the pair that most increases the corpus likelihood, which is a slightly different criterion and a similar result.
Unigram works backwards: start with a large vocabulary and delete the tokens whose removal costs the least likelihood, which allows several valid segmentations of the same string.
SentencePiece treats the raw text as a stream including spaces, so it needs no language-specific pre-tokenisation and works on scripts that do not put spaces between words.