Apply a stopping token in a short decode
Watch the spaces around tokens and probability values. · 156 words
A stopping token, often written <END> or EOS, is a special token that tells the decoder that the generated sequence is complete. It is learned during training as the end of a target. For example, suppose the prompt is "Weather:" and the model's next-token probabilities are sunny 0.45, cloudy 0.20, rain 0.10, and <END> 0.25. With greedy decoding, which always chooses the highest-probability token, it chooses sunny.
At the next step, after "Weather: sunny", suppose the probabilities are today 0.40, tomorrow 0.20, evening 0.05, and <END> 0.35, so it chooses today. After "Weather: sunny today", let <END> have probability 0.60, ahead of morning 0.20 and afternoon 0.20. The decoder now emits <END> and stops. The visible answer is "Weather: sunny today". The special token usually is not shown, but it prevents extra text from being generated. A sampler might choose a different non-stopping token, but it must still check every chosen token for the stopping marker.
Check your recall
If <END> is the highest-probability token after "Weather: sunny today", what should the decoder do?
Check your answer
It should emit <END>, stop generating, and return the visible text "Weather: sunny today" without the special token.
Sources and credits
Original KeyTouch lesson. Background reading · Hugging Face · LLM Course.