Thomas Piacentini
← Workshop

09 / 15 · 60–90 min

Compute attention.

How does a query select information?

Choose a laboratory
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.

xyR · 76.8 %B · 18.7 %O · 4.5 %
R: red; B: blue; O: obstacle. Circle radii represent weights. The solid point is the weighted sum.

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 %
Compare A and B →

Read values as a table
ObjectK₁K₂ScoreWeightVxVy
R1.000.000.710.773.001.00
B0.001.000.000.19-2.002.00
O-1.00-1.00-0.710.050.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 @ V

The 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.

Open my notebook →

atomsh / lab