Lesson 05 · Attention gathers context
Unfinished prompt
The animal did not cross the street because it was too …
01 · Smallest useful mechanism
Attention lets a token position gather information from other positions. A useful mental model is: the current position asks a question, earlier positions advertise what they contain, and the best matches contribute information to the current state. In a text-generating model, a causal mask prevents reading future tokens. Multiple heads perform different learned searches in parallel. The resulting weights control a mixture of information; they are not a database lookup or a complete human-readable explanation. High attention to a token says that one head routed information from that position in this computation. It does not prove that the token caused the final answer or that the model understood it in a human sense.
Each position gathers a weighted mixture of information from allowed positions.
02 · Experiment
Calculate by hand · exact teaching head
The 2D head is an exact small calculation. A future model trace would require explicit tensor provenance.
03 · Production-minded practice
Commit to a written claim and evidence plan. The Lab stores the draft locally and never sends it to a server.
Your learning artifact
Stored only in this browser. No account required; course reset does not delete it.
04 · Check your understanding
Next: The attention output is not the final answer. It is added to the shared residual stream, followed by more block updates.
Exact teaching calculation—not captured Bonsai internals
Every displayed value comes from the small matrices below. Ollama does not expose Bonsai’s internal attention activations, so the lab never invents a live model trace.
Inspectable head preset
The final query aligns most strongly with the earlier subject representation.
Select the output position that is gathering context
Token signal + position signal
token E
[1.30, 0.00]
position P
[0.00, 0.00]
representation X
[1.30, 0.00]
token E
[0.20, 0.40]
position P
[0.10, 0.00]
representation X
[0.30, 0.40]
token E
[0.00, 1.30]
position P
[0.10, -0.10]
representation X
[0.10, 1.20]
token E
[0.50, 1.20]
position P
[0.30, -0.20]
representation X
[0.80, 1.00]
Full attention pattern
rows = outputs · columns = available context
Theory bridge
One head can emphasize one relationship. Real layers run many heads in parallel and combine their outputs.
Attention mixes information across positions; an MLP transforms each position. Transformer blocks alternate both operations.
A real block adds its update back to the existing residual stream, allowing information to accumulate across layers.
A bright cell shows a strong weight. It does not, by itself, prove a human-readable reasoning process.
All values are recomputed from the displayed matrices. Display rounding never feeds back into the calculation.