09 / 15 · 60–90 min
Compute attention.
How does a query select information?
Check my intuition
01 · Predict
Before changing the settings.
Two attention scores are both 0. After softmax, what weight does the first item receive?
A hint
exp(0) is 1 and the weights sum to 1.
02 · Experiment and compare
Put the model to the test.
Move the query from red to blue. Compare temperatures 0.1 and 2. Then move the objects: keys stay fixed but values and their weighted sum change.
Weighted sum of values: (1.93 ; 1.05). Q/K/V are hand-chosen. A weighted sum is not a validated movement.
- Red weight
- 76.79 %
- Blue weight
- 18.67 %
- Obstacle weight
- 4.54 %
Read values as a table
| Object | K₁ | K₂ | Score | Weight | Vx | Vy |
|---|---|---|---|---|---|---|
| R | 1.00 | 0.00 | 0.71 | 0.77 | 3.00 | 1.00 |
| B | 0.00 | 1.00 | 0.00 | 0.19 | -2.00 | 2.00 |
| O | -1.00 | -1.00 | -0.71 | 0.05 | 0.00 | -2.00 |
Understand the calculations
03 · Connect the diagram to calculations
The numbers behind motion.
Objects become three toy tokens. Their keys describe hand-chosen associations; their values contain positions. The query is compared with keys by dot product. Softmax produces positive weights summing to 1; masking sets the obstacle weight to zero. These weights are not a causal explanation. This calculation isolates one attention head and does not train a Transformer.
scoreⱼ = Q · Kⱼ / √2
aⱼ = exp(scoreⱼ/τ) / Σₖ exp(scoreₖ/τ)
output = Σⱼ aⱼ VⱼA few lines to reconstruct
scores = Q @ K.T / sqrt(d)
weights = softmax(scores / temperature)
output = weights @ VThe notebook provides one function per laboratory, hand-calculated examples and tests. Exercises isolate components; these pages run the complete simulations.
Keep an observation
04 · Record
What changed?
Compare two settings. Record the effect, your explanation and a case where the model might fail. Saving keeps the current settings and seed, not a certification of competence.
atomsh / lab