02 / Inside the model · Start here

Attention: a computed weighted mixture

Queries and keys determine weights; those weights combine values from permitted positions.

6 min read
In this lesson
THE IDEA TO HOLD ON TO

Attention is a numerical routing operation. Its weights are not a complete account of why a model answered.

Queries, keys, and values

For each position, learned projections produce query, key, and value vectors. A query is compared with eligible keys to produce scores. Those scores become normalized weights, which mix the value vectors. The names are helpful roles, not separate stores of facts or human questions. The documented scaled dot-product operation makes each step explicit.

Imagine three index cards, each carrying a key vector and a value vector. A query chooses a weighted combination of their values. No card must be selected exclusively. A weight of 0.6 means sixty percent of this particular weighted mixture, not sixty percent confidence that a sentence is true.

From scores to weights

In scaled dot-product attention, a score is q·k divided by the square root of the key dimension. A mask excludes disallowed positions before softmax. The surviving weights sum to one for each query, then the output is the sum of weight × value across eligible positions.

Take invented scalar values [2, 10] and weights [0.75, 0.25]. Their weighted output is 0.75 × 2 + 0.25 × 10 = 4. The output is neither an index nor the most-attended value. This small calculation is the core of attention’s mixing behavior, even when the real vectors have many dimensions.

SEE THE IDEA

Attention makes a weighted mixture.

Value A · 75%[2, 0] × 0.75
Value B · 25%[0, 4] × 0.25
Weighted mixture[1.5, 1.0]
Show the vector calculation

First coordinate: 0.75 × 2 + 0.25 × 0 = 1.5. Second coordinate: 0.75 × 0 + 0.25 × 4 = 1.0. The two attention weights add to 1.

The weights below are supplied for illustration. Attention normally computes them from query–key scores. This is a mixture of value vectors, not a measure of whether an answer is true.

The diagram is a calculation

The attention demo derives its matrix from stated small inputs. Changing a query or a mask must change the scores and normalized weights coherently. A triangular masked region means those entries contribute zero; it is not an artistic pattern or a sample from a production model.

Inspect a single row first. Which positions are eligible? Which key matches the query most strongly under the stated dot product? Do the visible probabilities sum to one within rounding? Then inspect the weighted output. This sequence connects the heatmap to the arithmetic behind it.

What weights cannot tell you alone

A large weight does not by itself establish the causal importance of a token to the final answer. Values, output projections, other heads, later layers, and residual paths all matter. Research has challenged treating attention distributions as self-sufficient explanations. Jain and Wallace, 2019.

For example, a heavily weighted value could be nearly zero, while a smaller weight multiplies a large informative vector. Even that comparison omits later transformations. Use attention plots to study one operation, and use additional experiments when making claims about the model’s reasoning or the influence of an input.

A CONCRETE EXAMPLE

Weighted values, not weighted words

With two scalar values 2 and 10 and weights 0.75 and 0.25, attention returns 4. If both values become zero, it returns zero even though the attention weights have not changed. The weights alone therefore do not determine the information carried.

A COMMON MIX-UP

The brightest attention cell explains the model’s reasoning.

It shows one mixing coefficient within a much larger computation. A complete explanation requires more evidence.

Take it with you

  • Queries and keys produce scores; values supply what is mixed.
  • Masks remove positions before normalization.
  • Attention weights are not truth scores or complete explanations.
YOUR TURN · ABOUT 30 SECONDS

Check your understanding.

Choose an answer, then see the explanation. You can try again.

Practice only. Your answer is not stored or sent anywhere.

Optional · saved only on this browser
UP NEXT

Causal masking: no peeking at the answer

Continue when you’re ready. Marking this lesson as read is optional.

Next lesson →

Sources & further reading

Primary references for this lesson. The explanation and examples above are original.

  1. Scaled dot-product attention — PyTorch 2.15 documentation ↗PyTorch contributors · Version 2.15; accessed 2026-11-13 · checked 13 Nov 2026
  2. Attention is not Explanation ↗Sarthak Jain, Byron C. Wallace · 2019-05-08 (v3) · checked 13 Nov 2026