What is a transformer model?
A transformer is the architecture behind almost every modern language model, and many image, audio and video models too. It was introduced in a 2017 research paper titled "Attention Is All You Need". The "T" in GPT stands for transformer.
Its central idea is attention. To understand one word, the model looks at all the other words in the input and weighs how relevant each is. In "the trophy did not fit in the case because it was too big", attention is what lets the model link "it" to "trophy" and not "case".
How does a transformer work?
- Tokenise. Text is split into tokens.
- Embed. Each token becomes a vector of numbers, with information about its position added.
- Attend. In each layer, every token looks at every other token and takes in information from the relevant ones. Several attention "heads" run in parallel, each tracking a different kind of relationship.
- Transform. A small feedforward network processes each token's updated vector.
- Repeat. Steps 3 and 4 are stacked many times. Deeper layers capture more abstract patterns.
- Predict. A language model outputs the probability of each possible next token.
Why did transformers replace earlier designs?
| Recurrent networks (earlier) | Transformers | |
|---|---|---|
| Reads text | One token after another | All tokens at once |
| Long-range links | Weak: early words fade | Strong: any token can attend to any other |
| Training speed | Slow, hard to parallelise | Fast on modern chips |
| Scaling | Gains flatten | Keeps improving with more data and compute |
Processing everything in parallel made it practical to train on far more text than before, and that is what made large language models possible.
What are transformers used for?
- Language: chat assistants, translation, search and summarisation.
- Code: completion and generation.
- Vision: image classification and understanding.
- Audio: speech recognition and synthesis.
- Multimodal models: text, images and audio handled together.
What are the limits?
Attention compares every token with every other, so cost climbs steeply as input gets longer. That is why models have a context window, a cap on how much they can take in at once. Transformers also learn statistical patterns, not verified facts, which is why they can produce fluent errors.