๐Ÿงญ Roadmap โ€บ 03 ยท Process Context Efficiently โ€บ Self-Attention
๐Ÿ“ My Notes
03 ยท Process Context Efficiently

Self-Attention

Every token attending to every other token simultaneously

๐Ÿ”ด MUST
๐Ÿง  Understand๐Ÿ‘๏ธ Visualizeโœ๏ธ Calculate๐Ÿ’ป Code๐Ÿ”ฌ Experimentโš–๏ธ Compare๐Ÿ—ฃ๏ธ Explain๐Ÿ”จ Build
โšก Interactive Visualizer Real-Time Matrix Math

Live Self-Attention Heatmap & QKV Explorer

Select a token row below to inspect how its Query ($\mathbf{q}$) computes dot products against all token Keys ($\mathbf{k}$), scales by $1/\sqrt{d_k}$, normalizes through Softmax, and produces a weighted mixture of Values ($\mathbf{v}$).

Active Sequence Tokens (Click to Focus Query):
Attention Weight Matrix $A = \text{Softmax}(QK^T/\sqrt{d})$ Head 1: Syntactic
0.00 (No Attention)
1.00 (Max Focus)
Focused Token Analysis: "it" Dim $d_k = 4$
Key insight: Attention is dynamic context routing! Deep-dive Softmax Weights โ†’
๐Ÿ” Behind-the-Scenes: The Mathematical Matrix Formulation

For input sequence $X \in \mathbb{R}^{N \times d_{\text{model}}}$, projection matrices $W_Q, W_K, W_V \in \mathbb{R}^{d_{\text{model}} \times d_k}$ generate:

Q = X W_Q, \quad K = X W_K, \quad V = X W_V
\text{Scores} = \frac{Q K^T}{\sqrt{d_k}} \in \mathbb{R}^{N \times N}
\text{Attention Matrix } A = \text{Softmax}(\text{Scores})
\text{Context Output } Z = A V \in \mathbb{R}^{N \times d_k}

The scaling term $\frac{1}{\sqrt{d_k}}$ prevents dot products from growing excessively large in high dimensions, which would otherwise push the softmax function into regions with tiny gradients (gradient vanishing).

6 subtopics โ€” click to study
Tokens Interacting ๐Ÿ”ด Token-to-Token Relationships ๐Ÿ”ด Attention Scores ๐Ÿ”ด Scaling ๐Ÿ”ด Softmax Weights ๐Ÿ”ด Context-Aware Representation ๐Ÿ”ด Word Connections โ€” Every Word Attends to Every Word ๐Ÿ”ด
๐Ÿงช
RASL Pull ยท Sprint S-04 โ€” Parallel Learning
You're reading this because RASL is blocked on: how do tokens interact โ€” why does state history matter more than individual action outcomes?
Token-to-token relationships are the conceptual model for how execution steps relate to each other in the state tracker. Each past action is like a token โ€” some are more relevant to the current recovery decision. Return to reliable-agent-lab/agent/state_tracker.py and continue building. Read only what unblocks you.
๐Ÿ”จ Lab: M-05 โ†’ MultiHeadAttention module ๐Ÿ” Self-attention pattern โ†’ state history design ๐Ÿ“‹ View full parallel plan โ†’
โ† Back to Roadmap
โ–ถ LIVE DEMO Self-Attention ยท Live โ†’
This page 0:00
This session 0:00
Total (all pages) 0:00
Today 0:00
โ–ถ Running
๐Ÿ“Š View all study stats โ†’
0:00 studying