An end-of-sequence token (often called an EOS token or end-of-text token) is a reserved entry in a tokenizer vocabulary that marks the boundary where a sequence ends. In language models, it serves two roles: during training it separates documents or conversational turns, and during generation it is the signal that tells the model to stop producing further tokens.
Because modern language models are autoregressive, they predict one token at a time and have no built-in sense of completion. The end-of-sequence token gives them a learnable way to decide that an answer is finished, which makes it one of the most consequential special tokens in artificial intelligence systems that generate text.
How the end-of-sequence token stops generation
The end-of-sequence token stops generation because the decoding loop checks every sampled token against a set of terminating token IDs. At each step the model produces logits over the full vocabulary, a decoding strategy selects one token, and if that token is the EOS token the loop ends and the text is returned without it.
The model learns when to emit the token from its training data. During pretraining, documents are concatenated into long streams and an EOS token is inserted between documents, so the model observes that a finished text is followed by this symbol. During instruction tuning, every assistant reply ends with an end-of-turn token, which teaches the model to close an answer at a natural stopping point rather than continue indefinitely.
The following table shows the sequence of events in a single generation step and where the EOS check occurs.
| Step | What happens | Role of the EOS token |
|---|---|---|
| Forward pass | Model computes logits for every vocabulary entry | EOS receives a probability like any other token |
| Logit processing | Penalties, biases and temperature are applied | EOS can be boosted or suppressed here |
| Sampling | A token is chosen by greedy, top-p or another method | EOS may be selected if it is likely enough |
| Termination check | Inference engine compares the token with stop IDs | Selection of EOS ends the loop |
| Detokenization | Token IDs are converted back to text | EOS is normally stripped from the output |
Common EOS token conventions across model families
There is no universal string for the end-of-sequence token; each tokenizer defines its own symbol and numeric ID. Some families use a single token for both document ends and turn ends, while chat-tuned models often add a separate end-of-turn token that a chat template places after each message.
The table below lists representative conventions. Exact IDs differ between versions, so the tokenizer configuration file is the authoritative source for any specific checkpoint.
| Model family | Typical EOS string | Notes |
|---|---|---|
| GPT-2 and GPT-3 style | <|endoftext|> | Single token separates documents |
| T5 and SentencePiece models | </s> | Paired with a separate padding token |
| BERT | [SEP] | Separates segments rather than ending generation |
| Llama 2 | </s> | Shared by documents and replies |
| Chat-tuned models | End-of-turn markers such as <|im_end|> | Several stop IDs may be active at once |
Encoder-only models such as BERT use a separator rather than a true generation stop, because they do not generate text autoregressively. The concept matters most in decoder-only and encoder-decoder architectures.
End-of-sequence token versus related stopping controls
The end-of-sequence token is one of three independent mechanisms that end generation, and practitioners often confuse them. The EOS token reflects the model’s own judgment, a stop sequence is a string chosen by the developer, and max tokens is a hard length limit imposed by the inference engine.
| Mechanism | Who decides | Typical finish reason | Main risk |
|---|---|---|---|
| End-of-sequence token | The model | Stop or end of turn | Model may never emit it |
| Stop sequence | The developer | Stop | Can cut a valid answer early |
| Max tokens | The inference engine | Length | Output truncated mid-sentence |
| Padding token | The data pipeline | Not a stop signal | Confused with EOS during training |
Most APIs report which mechanism fired through a finish reason field. A reply that ends with a length reason has not reached its natural end, which is a useful diagnostic for truncated outputs in production systems.
Configuring the EOS token in training and inference
Correct configuration requires that the tokenizer, the chat template and the inference engine agree on which token IDs end generation. A mismatch at any point produces runaway output or empty replies, and these faults are among the most frequent problems when deploying open-weight models.
- Append EOS during fine-tuning: if training examples lack the token, the model never learns to stop after its answer.
- Keep padding and EOS distinct: when the padding token shares the EOS ID and padded positions are masked from the loss, the model may never receive gradient for stopping.
- Register every end-of-turn ID: chat models often need both the document EOS and the turn marker listed as stop tokens.
- Do not suppress EOS by accident: a strong negative logit bias or minimum length setting can prevent termination.
The decision table below maps common deployment situations to the recommended configuration.
| Situation | Recommended setting | Reason |
|---|---|---|
| Base model used for completion | Rely on document EOS plus max tokens | Base models rarely end turns cleanly |
| Chat model in a custom server | Load stop IDs from the generation config | Templates define end-of-turn markers |
| Supervised fine-tuning | Append EOS and include it in the loss | Teaches the model to finish answers |
| Fixed-length benchmark | Ignore EOS and set a minimum length | Ensures comparable output lengths |
Failure modes and common misconceptions
The most visible failure is endless or repetitive generation, where the model never selects the EOS token and continues until the max tokens limit. This symptom usually points to a template or tokenizer mismatch rather than a flaw in the model weights.
The opposite failure is premature termination, in which the model emits EOS after a few words. It can result from fine-tuning data with very short replies or from a decoding strategy that favors high-probability EOS early, such as greedy decoding on an underspecified prompt.
- Misconception: the EOS token is plain text. It is a single reserved ID; typing its string into a prompt may tokenize into several ordinary tokens or be blocked as a security measure.
- Misconception: every model shares one EOS token. Each tokenizer defines its own, and chat models frequently use several.
- Misconception: EOS guarantees a complete answer. The model can stop at an incorrect point, so output validation is still required.
The short version
A language model writes one small piece of text at a time. It has no natural sense of when to stop. The end-of-sequence token is its way of saying it is finished.
Think of the word “over” in a radio conversation. It tells the listener the message is complete. The model learns this signal from millions of examples that end with it. When the model produces the signal, the software stops and shows the answer. Without it, the model would keep writing until a length limit cut it off.
Where it makes a difference
A software team deploys an open-weight chat model on its own inference server to answer internal support questions. In testing, every reply runs to the full limit of 1,024 tokens, with the model inventing new user questions and answering them itself after its first response.
An engineer compares the token IDs in the raw output with the server configuration and finds that only the document EOS ID was registered as a stop token. The chat template ends each reply with a separate end-of-turn marker, which the server treated as ordinary text. After the engineer adds the end-of-turn ID to the stop list, typical replies shrink to 150 to 300 tokens, latency falls by more than half, and the invented follow-up conversations disappear.