liveBook · Manning

End of text token

As explained in Learn Generative AI with PyTorch

A special end-of-sequence token used to mark completion of decoding or the end of a tokenized sequence.

An end-of-text token, written as EOS, marks the end of a tokenized sequence. During autoregressive decoding, the decoder generates tokens until it predicts EOS, then stops producing the sentence. section 10.5 section 9.1.2

A translation pipeline uses EOS in three connected steps:

  • Adds BOS at the beginning and EOS at the end of every training phrase, so the model learns the sequence boundary. section 10.1.1
  • Maps the resulting tokens to integer indexes through a vocabulary dictionary, alongside PAD and UNK entries. section 10.1.1
  • Starts decoding with BOS, feeds earlier predictions back into the decoder, and terminates when the next prediction is EOS. section 9.1.2

English-to-French translation

For “I don't speak French.”, tokenization produces subword pieces such as “fr” and “ench</w>”. Adding BOS and EOS makes the boundary explicit before integer conversion. A decoder can then generate “Je ne parle pas français.” one token at a time and stop when it predicts EOS. section 10.1.1 section 10.5

Figure 9.4 The Transformer architecture. The encoder in the Transformer (left side of the diagram), which consists of N identical encoder layers, learns the meaning of the input sequence and converts it into vectors that represent its meaning. It then passes these vectors to the decoder (right side of the diagram), which consists of N identical decoder layers. The decoder constructs the output (e.g., the French translation of an English phrase) by predicting one token at a time, based on previous tokens in the sequence and vector representations from the encoder. The generator on the top right is the head attached to the output from the decoder so that the output is the probability distribution over all tokens in the target language (e.g., the French vocabulary).

Trace EOS through the Transformer’s decoder, where the generator predicts a probability distribution over target-language tokens. section 9.1.2

How Learn Generative AI with PyTorch covers it

How deep it goes
Explains EOS insertion, integer mapping, and decoding termination, but does not detail its loss calculation.
Examples
Uses English-to-French phrases, subword pieces, vocabulary dictionaries, and generated translations as working examples.
What it assumes
Assumes familiarity with tokens and sequences while introducing tokenization, vocabulary indexes, BOS, PAD, and UNK.
What you can do after
Apply it via a Transformer decoder that stops generation when the predicted token equals EOS.
How it connects
Connects EOS with beginning-of-sequence tokens, autoregressive decoding, tokenization, and Transformer encoder-decoder architecture.

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 Learn Generative AI with PyTorch. The section links point to the parts of the book it draws on.