Answers · How models work
Why is 'hello' a different token from ' hello' with a space in front?
In shortA space is a byte that gets merged onto the front of the next word, so the tokenizer stores ' hello' and 'hello' as separate symbols with no shared structure.
The space is not padding. It is a byte, and the tokenizer merges it onto the front of the following word, so ' hello' and 'hello' are different symbols with no structural link between them.
The merge algorithm has no idea what a word is. It counts adjacent byte pairs in a corpus. A space sits immediately before almost every word, so the pair of a space and a common first letter is one of the commonest pairs anywhere. That pair merges in the first few rounds, and later merges extend it until the whole word, space included, is one entry. The tokenizer is not deciding that the space belongs to the word. It is following the count.
Why the leading pair wins
The competing pair is the final letter plus the space before the next word. English words begin with a smaller set of letters than they end with, so the leading pair is more predictable and wins the count. Many tokenizers also pre-split on word boundaries with the space kept at the front of each word, which makes the same outcome explicit. Either way, the normal form of a word in running text is the space-prefixed form. The bare form is the special case: start of a document, after a line break, after an opening bracket or quotation mark, after a hyphen.
| form of 'hello' | relative frequency (commonest = 100) | times rarer than the space-prefixed form |
|---|---|---|
| with a leading space | 100 | 1 (reference) |
| bare, at the start of a line | 0.78 | 128 |
| capitalised | 0.71 | 141 |
| in capital letters | 0.3 | 333 |
One word, several entries
Nothing in the model connects these entries. There is no shared stem and no mechanism saying that the bare 'hello' and the space-prefixed ' hello' are the same word. Everything the model knows about one form it learned separately from the contexts that form appeared in. In practice the vectors are pulled together because the forms turn up in similar contexts, but that costs data and capacity. The space-prefixed form appears constantly; the bare form far less; the capitalised form less still; the all-capitals form rarely enough that it may be assembled from fragments.
The natural guess is that whitespace is invisible padding and should be ignored. It is not ignored, because the tokenizer does not remove it before counting. If you strip the leading space from your input, you do not get the same token with the space deleted; you get a different vocabulary entry. The model has to learn the relation between the two entries from data, and one of them has much less data behind it.
What the duplication costs
Take a 50,257-entry vocabulary split roughly as 17,400 space-prefixed words, 13,900 bare forms, 6,100 capitalised forms, 2,600 all-capitals or other variants, and 10,257 fragments, punctuation, digits and byte fallbacks. The first four figures add to 17,400 + 13,900 + 6,100 + 2,600 = 40,000 entries. The duplicate forms alone, the bare, capitalised and all-capitals entries, are 13,900 + 6,100 + 2,600 = 22,600, which is 22,600 ÷ 50,257 ≈ 0.45, or about 45 entries in every 100. That is not pure waste, since each form needs a representation, but the usable distinct vocabulary is smaller than the headline number, and the rarer forms are under-trained.
The same structure explains two familiar complaints. Asking how many times a letter appears in a word is hard because the word is one opaque symbol whose spelling the model never sees. A word at the start of a line behaving differently from the same word mid-sentence is not superstition: the two are genuinely different inputs, and the start-of-line form had less training behind it. Neither is a reasoning failure in the usual sense. Both follow from what the vocabulary made cheap and what it made rare.
This is a property of the tokenizer and its pre-splitting rule, not of language. If a tokenizer strips leading whitespace, or marks word boundaries with a sentinel such as ▁ instead of a raw space byte, the same word may still be split from its bare form, but the mechanism and the symbols differ. At the very start of a document the bare form is the normal one, because there is no preceding space to attach. The diagnostic that matters is the other end of the input: a prompt that ends in a space leaves the model continuing a token rather than starting a word. That split almost never occurs in natural text, so the model is predicting a rare bare-form entry after a stranded space. The output degrades, and the cause is invisible on screen. Delete the space and the prompt asks for the ordinary space-prefixed form again.
Worth keeping
- The leading space is part of the token, not padding, because the tokenizer counts adjacent bytes and the space is a byte.
- A prompt ending in a space asks the model to continue a token rather than start a word, which is a common cause of degraded output.
- The same word in bare, capitalised and all-capitals forms gets separate entries, so the model must learn their relation from data.
Where this goes next
This question is one step of Cutting Text Into Pieces, a course that works through its subject from the beginning. The page that teaches this part of it is The Space Before the Word, and it reads the whole way through whether or not you have an account.
What an account changes is the practice: problems standing under every idea, marked with a reason rather than a tick, in a copy of the course that is yours.
Read that pageThe whole courseOther questions people ask about this
- Why does the same request cost more tokens in some languages than in others?A token is learned from a corpus, so a language that was rare in the training text is split into many more pieces for the same meaning, and the price multiplier follows.
- Why do tokenizers work on bytes instead of on characters?Tokenizers use bytes because 256 byte values can represent any text, while Unicode has too many characters to include safely.
- Why can't a language model just treat each whole word as one token?Because a fixed list of words cannot contain a word nobody has written yet, and enlarging the list never catches up, while the model still has to put a number to every input it is given.
- Why can't you just add new tokens to a tokenizer after training?Because each token id is tied to weights the model has already trained, so changing the vocabulary makes old numbers name different pieces while the model keeps the old meanings.
- Why does the model get stuck repeating the same sentence over and over?The model is not stuck in a memory loop: once it has written a phrase, that phrase is in its context and makes writing it again more likely, so a decoder that always picks the top word cannot leave.
- Why does diffusion add Gaussian noise instead of any random corruption?Diffusion adds Gaussian noise because Gaussian errors combine exactly: each step keeps the spread fixed and gives a closed-form noisy picture at any later step, which makes the reverse step learnable.