The transformer underlies modern language models and many models for images and audio. It repeats the same block many times: in each block an attention layer lets tokens exchange information, while a feed-forward network processes each token separately.
What a block consists of
- attention: each token compares itself with the others and gathers what it needs from them; several “heads” do this in parallel and look at different relationships;
- feed-forward network (MLP): transforms each token’s vector independently of its neighbours;
- residual connections and normalisation: around each of the two parts, so that a deep network can be trained;
- positional information: attention itself does not distinguish token order, so position is added separately.
In the original paper the stack consisted of N = 6 identical layers with a vector dimension of 512. Large modern models have dozens of layers and dimensions in the thousands.
Three variants
| Variant | How it reads text | Examples |
|---|---|---|
| Encoder only | each token sees the whole text in both directions | BERT |
| Decoder only | a token sees only the preceding ones; the model predicts the next token | Llama, Gemma, Qwen |
| Encoder and decoder | the encoder reads the input, the decoder writes the output and refers back to it | the original transformer, T5 |
Most modern language models are decoder only. The architecture was proposed by Ashish Vaswani and co-authors in the paper “Attention Is All You Need” in 2017; they tested it on machine translation.
Sources
the term is written from these pagesVerified 18 Nov