How it works · 17 of 37 Foundation
How do transformers and attention work?
Which words matter here?
Transformers & attention: For each word, the model weighs which other words matter most to its meaning: attention. The transformer is the design built on it.
Loading the animation…
Say it like this Attention lets each word look at every other word and decide which ones matter for its meaning; a transformer stacks many layers of this.
Under the hood — for builders
- How one beam is worked out
- Three steps for "it" in the card's sentence. Each word carries a label and a meaning:
- Many spotlights at once
- The original transformer's base model, drawn to count: 6 layers, each with 8 spotlights (“heads”):
- Google's own example
- "It" means the animal, or the street, by context; attention picked the right noun (Google, 2017).
- Real impact
- English-to-German translation in 2017: better scores, for less training work than the models it beat:
- Longer text, much more work
- Every word looks at every other, so the looks grow with the square of the length:
- Watch out
- Beams on this card are illustrative; real heads each light up differently.
- Sources
- Vaswani, Shazeer, Parmar, Uszkoreit, Jones, Gomez, Kaiser & Polosukhin, Attention Is All You Need (arXiv 1706.03762v7) · Uszkoreit, Transformer: A Novel Neural Network Architecture for Language Understanding (Google Research blog, 31 Aug 2017).
What happens in the transformers & attention animation, step by step?
- "The cat sat on the mat because it was tired." You know at once what "it" means. A model has to work it out.
- Your turn: tap "it" to switch on its spotlight.
- Attention: "it" looks at every word and decides how much each one matters. The brightest beam lands on "cat": tired things are cats.
- Your turn: tap "tired" to change it to "dirty".
- Change one word and the focus moves. Dirty things are mats, so now the brightest beam lands on "mat".
- Every word does this for every other word, all at once. That is one layer of a transformer, the T in GPT; big models stack dozens.
What everyday example explains transformers & attention?
Reading "it" in a sentence and glancing back to find what "it" refers to.
Why should a team care about transformers & attention?
The "T" in GPT.