Labs / Transformer LabX: token embeddings + positions[6, 4]
W_Q (learned in real models)[4, 2]
Self-attention
Step through Q, K, V, QKᵀ, scaling, the causal mask, softmax, and the weighted sum, with shapes.
Theory and worked examples: Self-attention
Self-attention lab
Toy embeddings (d_model = 4) and random projections (d_k = 2), fixed seeds. Real models learn these.
| d1 | d2 | d3 | d4 | |
|---|---|---|---|---|
| 1:the | -0.89 | 0.72 | -0.78 | 1.54 |
| 2:cat | 1.13 | 0.20 | 0.19 | 1.73 |
| 3:sat | -1.53 | -1.35 | -0.09 | 0.71 |
| 4:on | -0.76 | -1.10 | 1.51 | 1.46 |
| 5:the | -1.65 | -0.93 | -0.74 | 1.54 |
| 6:mat | -1.02 | 2.53 | -0.90 | 1.71 |
| k1 | k2 | |
|---|---|---|
| d1 | 0.04 | -0.54 |
| d2 | -0.24 | 0.91 |
| d3 | 0.45 | 0.19 |
| d4 | 0.49 | 0.61 |