Attention Mechanism
A way for a model to focus on the most relevant parts of its input when producing an output.
How can one position combine three others?
In a simplified attention calculation, one query assigns weights to three positions. The values below are single numbers so the combination can be checked by hand. Models ordinarily work with vectors, often in multiple attention heads.
| Position | Weight | Value | Contribution |
|---|---|---|---|
| First | 0.50 | 2 | 1.00 |
| Second | 0.30 | 6 | 1.80 |
| Third | 0.20 | 1 | 0.20 |
What leaves the attention step?
The weights sum to one and the weighted values add to 3.00. A different query can give the same positions different weights. In scaled dot-product attention, the model compares queries with keys to produce scores and normalizes the scores before combining the values.

Can you read an explanation from the largest weight?
The largest weight here belongs to the first position, yet the second contributes more because its value is larger. In a real model, multiple heads, layers and other connections contribute to an output. A single attention pattern provides evidence about one computation, not a complete causal explanation for an answer.
Follow the idea
Transformer · See how attention fits into a model architecture.
Interpretability · Examine what evidence supports an explanation of model behavior.
Source · Vaswani and colleagues’ original attention calculation
Return to Attention Mechanism in the A–Z glossary