BOS, EOS, PAD: why do tokenizers reserve these ids instead of using normal text?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Reserved ids prevent ambiguity: BOS, EOS, and PAD occupy positions normal tokenization never produces, so they can never collide with real content.
Imagine the tokenizer's vocabulary is mostly little pieces of words, but a few entries are not words at all. They are special markers, like invisible punctuation only the model can see: 'this is where the conversation starts', 'this is where this person stops talking', 'ignore this position, it is just padding'. These markers have their own numbered ids, but they never appear in ordinary text. The tokenizer inserts them when it knows it should, and the model learned during training that when it sees these ids, it should change behavior: stop generating, switch speaker, or skip the position. If a user accidentally types one of these marker strings as text, things can go wrong, which is why production systems sanitize input.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
5 min: define special tokens as reserved structural vocabulary entries, name the categories (sentinels, PAD, role markers, tool-use markers), explain why the model treats them as boundaries via training, cite chat-template tokens for two model families, and flag the prompt injection vector.
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Letting raw user input pass through the tokenizer with add_special_tokens=True, allowing a user to inject role markers like `<|im_start|>` and steer the model past the system prompt.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.