Thomas Piacentini
← Workshop

Guided lesson 09 / 10

Compute attention.

Follow QKᵀ → softmax → weighted values and distinguish attention from text generation.

01 · Understand and consult

The idea before the settings.

A query Q is compared with keys K through dot products. Softmax converts scores into positive weights summing to 1. These weights combine values V.

Here temperature acts on attention scores. In a text generator, output temperature acts on next-token probabilities. These are different locations in the computation. A mask excludes some contributions.

A worked example.

Two equal scores give weights 0.5 and 0.5 at any positive temperature. Values (2, 0) and (0, 2) then average to (1, 1).

Read these passages from the authors.

Transformer Explainer · Reading links open a new tab.

  1. Embedding ↗

    Follow tokenization, token vectors and positions. Distinguish a discrete identifier from a numerical vector.

  2. Multi-Head Self-Attention → Query, Key, Value ↗

    Locate Q, K and V matrices and softmax. Then find output temperature and distinguish its role.

If a resource fails to load, local explanations and trials remain available. You can continue and leave reading pending.

02 · Predict

Write before running.

At least 20 characters to document your hypothesis. A wrong prediction is useful: keep it and later explain what surprised you.

03 · Experiment and compare

Two trials, one question.

Each link loads prepared laboratory settings. Seeds match for randomized models. Record results and use “Keep this experiment” for each trial, then return here.

Trial A

Starting comparison.

Observe a red query at temperature 2 without a mask. Record all three weights and the weighted position.

Open trial A →

No notebook record yet.

Trial B

Change an assumption.

Lower only temperature to 0.1. Compare weights and average, then test masking the red target.

Open trial B →

No notebook record yet.

Opening a trial replaces this laboratory’s current settings. Saved experiments remain in the notebook. For a controlled comparison, record A and B as given before exploring freely.

04 · Solve

Calculate for yourself.

The laboratory’s numerical challenge checks a small calculation component. Use the hint after trying; this guide helps reconstruct the reasoning.

Solve the laboratory challenge →

Challenge pending.

Continue with the Python notebook ↗

05 · Explain and check

What my trials taught me.

At least 40 characters; cite measurements and one model limitation. Your text is kept in this browser and the notebook JSON export.

My success criteria · self-assessment

Lab vectors are hand-chosen. Attention weights do not establish a causal explanation of a model.

atomsh / lab