Please verify you are human to use the visualiser.
The query is what a position is looking for, the key is what it advertises, and the value is what gets passed on. Scores compare queries to keys; outputs average values.
Every query meets every key, so the cost grows with the square of the sequence length. That single fact drives most of the work on long-context and efficient attention.
Setting the upper triangle to negative infinity stops a position reading its own answer. Encoders leave it off, which is the structural difference between GPT and BERT.
Each head learns its own routing. Averaging them, which is what a single published heatmap often amounts to, hides most of what they are individually doing.
Start on the previous-token head with the causal mask on. Every row puts almost all its weight one column to the left of the diagonal, which is what a positional head looks like when it works. Switch to the attention sink and the whole matrix collapses onto the first column. That pattern is not an artefact; trained models really do dedicate heads to a near-constant position, and the leading explanation is that softmax has to put its weight somewhere even when a token has nothing useful to read.
The same-word head is the one to try on a sentence with a repeat. Under a causal mask a token always sees itself, so a row that splits evenly between two columns is telling you the word appeared earlier. That is the seed of an induction head, the mechanism behind a lot of in-context learning. Then switch to All heads averaged and watch the structure wash out, which is the honest caveat on every attention heatmap you have seen published.
The score matrix is quadratic in sequence length, and that cost is the reason for most of the architecture work of the last few years. Our KV cache calculator sizes the memory that caching those keys and values actually takes, and KV cache memory in LLM inference works through the arithmetic. For the ways the cache is shrunk, see MQA, GQA and multi-head latent attention, and for replacing the quadratic term altogether, linear attention and state space models. For attention applied to image patches rather than words, see vision transformers from scratch. On whether a head that looks interpretable is doing what it appears to, one neuron, two features runs three probes over the same network and shows them disagreeing.
Understanding the mechanism is a long way from running one in production, where the questions become which model to serve, what context length the task genuinely needs, and what the token bill looks like at real volume. That is our LLM implementation consulting work.
Size the KV cache for Llama, Mistral, Qwen and Gemma. Context length, batch size and quantisation against A100, H100 and 4090 memory.
Try itCompare live 2026 pricing across 300+ LLM APIs. Estimate monthly costs for GPT-4o, Claude, Gemini, Llama, and more.
Try itStack convolution and pooling layers to see output shape, receptive field and parameter counts update live, then step through max and average pooling window by window.
Try itStep-by-step convolution animation with heatmap grids. Watch a kernel slide across input, see element-wise multiplication, and adjust stride, padding, and dilation.
Try itGet notified when new tutorials and deep-dives are published. No spam, unsubscribe anytime.
Common questions about query, key and value, the causal mask, softmax and multi-head attention