Subsection 2.3 Input Encoding
The initial input to a decoder is not just raw token embeddings. Alone, they would not tell the model where each token occurs in a sequence. That order matters: the same words in a different order can mean something very different. (Compare “He ate dinner with his friends” and “With his dinner he ate friends”!)
So, the token embedding is combined with a positional encoding that indicates the token’s position in the sequence. This way,
ate at position 2 will have a different representation than ate at position 5.

The embedding and positional encoding are both learned components of GPT-2. Part of the training process involves learning not just embeddings for each token, but also appropriate positional encodings for each position in a sequence. While the number of token embeddings depends on the vocabulary size of the model, the number of position encodings is determined by the maximum context length. GPT-2 medium can consider context windows of up to 1024 tokens, so it will need to learn 1024 different positional encodings.


Future diagrams will simplify the representation and show tokens passing directly into the first decoder block. You should assume that the position embedding has already been added to each token.