What it is
An encoder reads a whole input at once, and a decoder writes one token at a time
The original transformer (Vaswani et al., 2017) was built for translation and had both halves. An encoder turned the French sentence into vectors, and a decoder wrote the English sentence one token at a time while reading them. Everything since is built from one half of it, or from both.

The three shapes differ in what they hand back.
- An encoder returns one vector per input token. Those vectors are a representation of the text, and on their own they answer nothing. Something has to turn them into an answer, usually a head, which is a small output layer trained on your task that turns the vectors into a label or a score.
- A decoder returns a probability for every token that could come next, at every position. Read that distribution at the last position and you have a one-step answer. Feed the chosen token back in and you have generation.
- An encoder-decoder runs an encoder over the input and a decoder over the output, joined by cross-attention, which lets every decoder position read the encoder's finished vectors. The input gets read in both directions, and the output still gets written one token at a time.
Keep reading
The rest of this article is free with an account
Create a free account to read the remaining 5 sections. It takes about twenty seconds and there's nothing to pay. The same account opens the slide decks and CV reviews.
- 02Which models are which shape
- 03The mask decides the shape, and the pretraining objective follows from it
- 04Fine-tuning changes with the shape
- 05Choosing a shape
- 06What the shape does not fix
