The central operation
Each query produces its own distribution over keys. That distribution mixes values into a new representation for the querying position.
Attention is dynamic information routing.Select a query token, switch attention heads, change softmax temperature, and apply a causal mask. The weighted 3D routes are computed from deterministic teaching projections, not extracted from a production model.
A transformer does not assign a single global importance score to every word. At each layer and attention head, every token position creates a query. That query is compared with keys from candidate positions, converted into normalized weights, and used to mix their value vectors.
The distinction between query, key, and value is operational. A query describes what the current position is looking for under one learned projection. A key describes how another position can be addressed. A value carries the information that will be routed if that address receives weight. They are separate linear projections of hidden states, not three copies with human-readable labels.
In the sandbox, select the token it in the package example. The reference head gives the package token a strong structural match. The syntax head prefers nearby grammatical context. The recency head decays with distance. Aggregate averages the normalized distributions to illustrate how multiple heads can contribute different routing patterns.
These are deterministic teaching projections with explicit biases, not a trained language model. Real heads learn distributed features, may combine several behaviors, and change across layers and prompts. The purpose of the lab is to make the mechanics inspectable without pretending that a colorful route is a faithful interpretation of a deployed model.
Each query produces its own distribution over keys. That distribution mixes values into a new representation for the querying position.
Attention is dynamic information routing.Softmax converts a row of logits into weights that sum to one. Raising one candidate's logit reduces the share available to others.
Different learned Q, K, and V matrices let heads attend through different representational subspaces.
A causal mask gives future positions effectively negative-infinite logits before softmax, preventing forward information leakage.
Head outputs are concatenated, projected, and combined with the residual stream before later transformations.
The layer input at every position is multiplied by learned matrices to create query, key, and value vectors for each head. The same token can therefore expose different features to different heads.
For one query position, dot products compare its query vector with every allowed key. Larger positive values indicate stronger alignment in that head's learned coordinate system.
Dividing by the square root of key dimensionality keeps logits from growing too large as dimensions increase. Masks then remove illegal routes before normalization.
Exponentiation and row normalization produce nonnegative weights that sum to one. Softmax is sensitive to relative logit differences, which is why scale and numerical stability matter.
The output is a weighted sum of value vectors. High attention to a position routes more of its projected value content into the query position's new representation.
A head can learn features useful for linking a pronoun or dependent phrase to another position. The behavior is contextual and need not align perfectly with a linguistic relation.
Some heads exhibit positional or grammatical patterns, such as attending to a preceding token, separator, or dependency-related location. No single head has to encode a whole parse tree.
Distance-sensitive behavior can prioritize nearby context. Relative-position mechanisms, rotary embeddings, masks, and learned content all influence practical routing.
Useful computation usually spans heads and layers. A later head can read features written by earlier components, so inspecting one matrix is only a slice of the circuit.
The current representation at each token position carries embeddings plus changes written by earlier layers.
Shared streamLayer normalization and learned matrices create head-specific queries, keys, and values.
Head subspacesMasked scaled dot products and softmax determine how every query mixes candidate values.
Dynamic weightsHead outputs are concatenated and projected back into the model dimension.
Output projectionThe attention result is added to the stream so later attention and feed-forward blocks can use it.
Layer stateA large attention weight shows routing under one head and layer. It does not by itself prove that changing that source token would change the final prediction proportionally.
Two positions can receive similar weights while contributing very different value directions. Looking only at weights ignores what is actually routed.
The residual stream accumulates many attention and feed-forward updates. A pattern visible early can be amplified, transformed, or canceled later.
Head averaging, token aggregation, thresholding, and color scales can hide uncertainty or invent apparent structure. Preserve the underlying numbers and method.
A personal agent may receive instructions, prior messages, retrieved documents, tool schemas, and browser observations in one context. Attention is one mechanism that lets each generated position route information from those inputs, but it does not guarantee that the right evidence is present, authorized, fresh, or followed.
For a text-message AI assistant, pronouns and terse follow-ups depend on context. A message such as "send it after it is verified" contains multiple references. The application should preserve structured task identity and verification state instead of hoping attention resolves every ambiguity from prose.
A computer-use cache can place relevant prior observations into context, but retrieval quality determines which keys and values are even available. Attention cannot route evidence that was omitted, and it can still emphasize stale evidence if metadata and freshness are not enforced.
When an AI website-building agent reads files, deployment logs, screenshots, and requirements, clear serialization and section boundaries make relationships easier to represent. Exact paths, current errors, and explicit postconditions reduce reliance on long-range inference.
Super combines messaging and computer-use workflows where model context must stay connected to structured permissions, tools, receipts, and real-world verification beyond the attention computation itself.
No. The sandbox computes real softmax distributions from deterministic teaching projections and visible structural biases. It never claims to reproduce a particular model, layer, or learned head.
Without scaling, dot-product variance grows with dimensionality, which can push softmax toward saturated distributions and small gradients. The transformer scales logits by the square root of key dimension.
The teaching control divides logits by an extra temperature. Lower temperature sharpens the largest differences; higher temperature flattens the distribution. Standard attention uses its architecture's defined scale rather than an arbitrary inference temperature knob.
For a decoder self-attention layer, it prevents a position from reading later token positions. Earlier positions can still influence later ones, and other architectures use bidirectional or cross-attention masks.
Not reliably. Some heads show recurring patterns, but behaviors can be distributed, polysemantic, prompt-dependent, redundant, or only meaningful when composed with other components.
During autoregressive generation, past key and value vectors can be cached so each new query reuses them instead of recomputing earlier projections. Cache memory grows with layers, sequence length, heads, and key/value dimensions.
Attention becomes useful to understand when queries, keys, values, masks, weights, and downstream effects remain distinct and inspectable.
Explore Super