#05Ez a videó és a szövege angol nyelvű.
Trailing space trap: why one invisible space can weaken an AI reply
End a prompt with a space and the AI starts from a piece of text it almost never saw. Here is why that happens, and the simple habit that avoids it.
Részletesen
What the trailing space trap is
The trailing space trap is a tiny, invisible mistake: a prompt that ends with a space. You cannot even see it on the screen. Yet it can quietly make the answer worse, and nothing warns you.
To see why, you need one fact about tokens, the chunks of text a language model actually reads. In tokenizers built like the one for GPT-2, an earlier OpenAI language model, the space in front of a word travels with that word. The model does not see a gap and then "like". It sees a single piece, " like", with the space packed inside.
What the video shows
The video makes two simple points. First, the text pieces an AI works with usually carry the space that comes before a word. Second, if your prompt ends with a space, that space is left over as a lonely piece of its own. The AI rarely met a piece like that while it was learning, so its reply gets worse.
An everyday example
The course measures it with a two-word prompt. "I like" becomes two tokens: "I" and " like". Add one space at the end, "I like ", and you get three tokens. The third one is a bare space (token number 220) standing on its own.
Imagine you learned to write from millions of pages where every space was stuck to the front of the word after it. You have seen "space plus word" countless times. But a space attached to nothing, followed by a word that has to start without its usual space? You have almost never seen that. That is exactly the spot the model is put in.
The same rule shows up with a single word. Written on its own, "strawberry" is cut into three pieces. With a space in front, " strawberry" is just one piece. The form that appears in the middle of sentences earned its own token; the bare form did not.
How it happens, and how to avoid it
Before the tokenizer starts gluing letters into bigger pieces, it first cuts the text with a fixed pattern. That pattern keeps each word together with the space just before it, and no piece is ever built across those cuts. So in the text the model learned from, a space almost always arrived as the front edge of the next word.
A trailing space breaks that habit. Most word pieces the model could pick next already come with their own space attached, and your prompt has already spent it. The model has been handed an unnatural starting point, and the continuation suffers.
The fix is simple:
- Do not end prompts with a space. Let the model supply the space itself, as part of its next word.
- Check code that builds prompts. A template such as "Answer: " with a space before the closing quote is an easy place for one to slip in.
Why it matters
This is one of those tips that sounds like a superstition, right up until you inspect the actual token numbers. Then it is plain cause and effect. It is also a good reminder that a model reads numbered pieces, not letters and gaps, so tiny formatting choices can change what it sees.
Learn it step by step in Chapter 7 of our free course AI From Scratch: Build a BPE Tokenizer: Why Your Model Can't Count the R's.
Itt is
Továbbiak ebből a fejezetből
#05
#084The strawberry problem: why AI can miscount the r's in a word
#085Subword tokens: the middle ground between whole words and letters
#086Byte-level tokens: how AI can read any language, symbol or emoji
#087Byte-pair encoding: the 1994 compression trick that splits text for AI
#088Vocabulary size: how many text pieces an AI model should know
A szöveg AI-segítséggel készült az ingyenes kurzusunk 7. fejezete alapján.