liveBook · Manning

End of text token

As explained in Build a Reasoning Model (From Scratch)

A special token used to mark the end of a document or generated sequence and stop generation.

An end-of-text token marks a document boundary during training and lets inference stop when generation reaches that boundary. In the demonstrated Qwen3 workflow, <|endoftext|> has token ID 151643 and is exposed as tokenizer.eos_token_id. section 2.7

Use the token in the generation loop:

  • Pass tokenizer.eos_token_id as eos_token_id. section 2.7

Stopping a streamed response

Without an end-token check, a response to “Explain large language models in a single sentence” continues beyond <|endoftext|> into unrelated text. Supplying tokenizer.eos_token_id stops the stream after the intended sentence.

How Build a Reasoning Model (From Scratch) covers it

How deep it goes
Implements token-ID lookup, loop comparison, and early termination, without detailing token-training mechanics.
Examples
Uses <|endoftext|>, ID 151643, tokenizer.eos_token_id, and a one-sentence language-model prompt.
What it assumes
Assumes a pretrained model, tokenizer, token IDs, and a basic autoregressive generation loop.
What you can do after
Operate/configure a streamed generator to stop cleanly at the tokenizer’s end-of-sequence ID.
How it connects
Connects tokenization, autoregressive text generation, streaming output, and inference.

Also explained in

Compare how 5 books explain end of text token →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Reasoning Model (From Scratch). The section links point to the parts of the book it draws on.