Home▸AI & Machine Learning▸Transformer Self-Attention: Query/Key/Value Heatmap (2D)

Transformer Self-Attention: Query/Key/Value Heatmap (2D)

2D self-attention lab: real query/key/value matrix projections, scaled dot-product scores and a live softmax heatmap over a token sequence — click a token to see exactly what it attends to.

AI & Machine Learning2DAdvanced60 FPS📱 Mobile-adapted⇄ 3D version
2d-transformer-attention-mechanism-explained-lab ↗ Open standalone

This 2D companion runs the exact scaled-dot-product self-attention computation behind the 3D scene on a plain canvas built for reading the math rather than orbiting a scene: fixed token embeddings are projected through real query, key and value weight matrices, attention scores are computed as Q·Kᵀ divided by √d_k, and a genuine softmax turns them into a token-by-token attention-weight heatmap — click any token to make it the active query and see precisely which other tokens it attends to, with every row's weights verified to sum to 1.0 regardless of the temperature setting.

⚙ Under the hood

2D self-attention lab with real query/key/value matrix projections, scaled dot-product scores and a live softmax heatmap over an adjustable-length token sequence, recomputed on every parameter change.

self-attentiontransformerquery key valuesoftmaxscaled dot-product attentionattention heatmap

2D · HTML5 Canvas 2D · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)