Subsection 2.2 Transformers at a Glance
Transformers build context-sensitive representations of words that they process. Given a token (word) “dog”, the transformer begins by taking its embedding and applying a series of transformations to it that capture the word’s context within the preceding text. It then uses this context-sensitive representation to make predictions. Given the text “the dog sat” it effectively considers the word “the” is the first word, the word “dog” which is known to come after “the” and be the second word, and the word “sat” which is known to be the third word and come after “the” and “dog”. This much more nuanced representation of the existing context allows the model to produce predictions that are both novel and more contextually appropriate.
There are various forms of transformers, and many kinds of transformer-based language models. As a particular example, we will focus on Generative Pre-trained Transformer 2 (GPT-2). GPT-2 is an early version of the GPT series that led to the popular ChatGPT. (The earliest version of ChatGPT, launched in 2022, was based on the GPT-3.5 model.)
The transformers used by GPT-2 are referred to as decoder transformers. GPT-2 uses a stack of these to process each token in a sequence and produce as a final output a prediction of the next token.
Consider the context “a robot must obey the orders given it”. Each token enters the decoder stack at its own position. The representation at the final position can draw on all the earlier tokens when predicting what comes next:

The selected next token then can be added to the context and used to help predict the subsequent tokens.