What is an end-of-sequence token?
An end-of-sequence token, often called an EOS token, is a special token used to mark that a sequence has ended.
For generative LLMs, producing an EOS token can also signal that the model should stop generating more text.
What does an EOS token look like?
The exact representation depends on the model and tokenizer.
Conceptually, it may look like:
<EOS>A sequence might therefore be represented as:
The answer is complete. <EOS>Internally, the EOS token is represented by a reserved token ID.
How does an LLM use it during generation?
During autoregressive generation, the model predicts one token at a time.
At each step, the EOS token is one of the possible next tokens.
Conceptually:
prompt
↓
token
↓
token
↓
<EOS>
↓
stopIf the EOS token is selected, the generation system can stop producing additional tokens.
Is EOS the only way generation can stop?
No.
Generation can also stop because of:
- A maximum output-token limit
- A configured stop sequence
- Application-specific stopping logic
- Other model-specific control tokens
So EOS is an important stopping mechanism, but it is not the only one.
Is an EOS token always visible?
Usually not.
Applications normally remove special control tokens before displaying the final response to the user.
You typically see only the generated text, not the internal EOS marker.
How is EOS used during training?
Training examples may include an EOS token at the end of a sequence.
This allows the model to learn that after a complete passage, conversation turn, or document, predicting the end-of-sequence token can be appropriate.
EOS vs. BOS
The two tokens represent opposite sequence boundaries:
- BOS marks the beginning of a sequence.
- EOS marks the end of a sequence.
For the starting boundary, see “What is a beginning-of-sequence token?”
In short: an end-of-sequence token is a reserved special token that marks the end of a sequence and can tell a generative LLM when it is appropriate to stop generating.
Learning Sequence
Large Language Models Curriculum
Explore Related Questions
Deepen your understanding across related Large Language Models topics.