Guided project
Who Looks at Whom
Draw the attention map of your own school sentence from a real small language model, write the attention maths yourself in Python until it matches the model's, and test whether the word it looks at most is the one that matters.
About 1.5 h ·
4 stages · 12 steps
What you'll make
In 15 minutes: An attention map of your own school sentence from a real model, where you tap a word and see which words it looks at.
What you'll find out about AI: The word the model looks at most is not always the one that matters most.
Make it yours: Pick a new school sentence that stops mid-way, run your swap log again on it, and see if the most-looked-at token still moves the next word the least.
When you share: Tap a word and see where a real AI model looks.
Step by step
Stage 1
See who looks at whom (minutes 0-20)
A real model's attention on your own sentence: tap a word, see which words it looks at.
- Your sentence on the map — The lab shows where each token of a school sentence you wrote looks.
- Heads have habits — You found three heads with three different habits in your own sentence.
- Where does your word look? — You checked the reading lesson's " mine" result yourself, then asked the same of a word in your sentence.
Stage 2
Write attention yourself (minutes 20-45)
Your own attention for every head, from the model's own queries and keys, matching its weights.
- Write scores — Your `scores` gives every query-key score for the head on screen, and it matches torch.
- Softmax, and our mask — Your `softmax_rows` with our `causal_mask` gives the model's own weights, in every one of its 72 heads.
- Break it on purpose — You know whether the checks catch a mistake in your attention, and you added one that does.
Stage 3
The first token soaks it up (minutes 45-70)
How much weight lands on the first token, counted two ways, and a test of what that weight does.
- Measure the sink — You read our `first_token_share`, counted the heads that put more than half on the first token, and saw how one choice changes the count.
- Move the sink — You tested whether the weight goes to the first word or to the first place.
- Show it your way — One new feature on your page that shows what the first token's weight does, or doesn't do.
Stage 4
Does the most-looked-at word matter most? (minutes 70-90)
Your own finding, with evidence: whether the token with the most attention is the one that moves the next word.
- The swap test — Your `change_size` measures how far the model's next-word chances move when you swap one word.
- The swap log — A log of at least 5 swaps on your own sentence, and your decision: does the most-looked-at token matter most?
- Someone else tries it — Someone used your lab without help, and you changed one thing because of what they did.
Guardrails
- Your sentences are about school life and in English (the model only learned English). No real names and no personal details in them.
- A big attention weight shows where the model collected information from, not what it thinks matters. Test it before you claim it.
- You write the attention code; the agent explains and reviews. Ask it to write a line only after you tried, and it will say when it did.
- Nothing is downloaded or installed. One model, distilgpt2, is already in your workspace.