What are BOS, EOS, PAD, and role marker special tokens, and what happens when each is missing or duplicated?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
BOS starts generation, EOS stops it (infinite loop if missing), PAD aligns batches and must be attention-masked, and role markers fence off who speaks in a chat.
Imagine a stage play where the script has stage directions that nobody reads aloud. BOS is the 'curtain up, scene starts here' note. EOS is the 'curtain down, stop here' note, and without it the actor keeps improvising forever. PAD is blank filler added so every actor's script has the same number of pages, and the director has to remember not to read the blank pages out loud. Role markers are the name tags pinned on each speaker so the audience knows when the host, the guest, or the announcer is talking. Lose a name tag and the audience can no longer tell who said what.
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.
2 min: BOS start state + EOS as learned stop + PAD attention masking + role markers as trust boundaries + apply_chat_template as the safe path.
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.
Saying PAD tokens are ignored automatically. They are not. You must pass an explicit attention mask, or the softmax spends weight on empty positions.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.