Human–Machine Convergence

Attention from first principles

Rajesh Ranjan Mahapatra

A first-principles explanation of query, key and value attention, why square-root scaling matters, how temperature controls routing, and how to test the mechanism yourself.

© 2026 Rajesh Ranjan Mahapatra. 29 min read

Transformer anatomy

Attention from first principles

Scaled dot-product attention works because learned query-key geometry selects addresses, values carry the retrieved content, square-root scaling cancels dimension-driven logit growth, and temperature sets the sharpness of the route.

TLDR

  • Queries ask, keys advertise, and values supply.
  • Dot products score compatibility; softmax converts scores into a route.
  • Square-root scaling stops dimension alone from sharpening that route.
  • Temperature controls competition: lower is sharper, higher is broader.
  • Attention weights record routing, not an automatic causal explanation.

Imagine a night operator facing three sealed drawers. Each drawer has a label outside and a packet inside. The operator receives a request card: find the current emergency contact. Drawer A is labelled “people”, drawer B “billing”, and drawer C “incidents”. The operator compares the request with the labels, assigns 80 per cent of the search effort to A, 15 per cent to C, and 5 per cent to B, then blends what is found according to those weights.

Now swap the packets inside A and B without changing their labels. The operator follows exactly the same route, yet returns different information. Swap the labels but leave the packets in place, and the route changes before any packet is opened. The address and the message are different causal objects. Scaled dot-product attention is the differentiable version of that distinction.

The Transformer paper compressed the mechanism into one line: compare queries with keys, normalise the scores, and use the resulting weights to sum values.[5] The line is simple enough to memorise and easy enough to misunderstand. “Attention” sounds like a unit deciding what matters. The equation actually describes a content-addressed router. It does not, by itself, supply meaning, awareness, intention or even a guarantee that the selected information causes the model’s final answer.

This paper rebuilds the router from the puzzle above. The aim is not to survey every attention variant. It is to make one mechanism visible: the route is produced by query-key compatibility, while the payload travels through values. Once that split is clear, scaling and temperature stop looking like arbitrary tricks. They become controls over the statistical regime in which routing occurs.

The address is not the message

Early neural sequence models often compressed an entire input into one fixed-length vector. Bahdanau, Cho and Bengio identified this bottleneck and let a decoder softly search over a sequence of source annotations instead.[1] Luong, Pham and Manning later explored global and local forms of the same basic idea.[2] Related memory systems used content similarity to address stored locations.[3][4] The common move was decisive: do not force every future computation to use one undifferentiated summary. Let the current computation ask for a task-dependent mixture.

The Transformer made this move parallel. For each position, learned linear projections produce three vectors. A query represents what that position is looking for. A key represents how each candidate position should be matched. A value represents what each candidate position can contribute if selected. In self-attention, all three are generated from the same incoming token states, but they are not the same representation and need not encode the same distinctions.

Why three projections are necessary

Suppose one vector had to serve as query, key and value. Any feature that made a token easy to find would also be forced into the content it supplied, and any feature useful in the supplied content would alter how the token was found. The model could still learn, but routing and payload would be entangled. Separate learned projections let one incoming state expose different interfaces to the same head.

Consider the word bank in “the bank approved the loan”. A key projection may emphasise that this token is a candidate organisation or grammatical subject. A value projection may carry number, entity and event features needed by another position. A query at it may emphasise the relation “find an earlier singular organisation”. Nothing requires these vectors to resemble a dictionary definition of bank. Training only requires their interaction to reduce the task loss.

This separation also explains why attention can copy, combine and transform rather than merely point. The weighted sum is taken over value vectors, not over token identities. A value can be a learned transform of the token state, and several values can contribute simultaneously. The head therefore returns a new representation in the value space. Calling the operation “selection” is helpful when one weight dominates, but the general operation is conditional mixture.

There is a hidden boundary here. The projections do not create information absent from the incoming states. If two candidate states are identical in every feature visible to the key projection, the router cannot distinguish them. If the value projection discards a distinction, correct routing cannot recover it. Attention reallocates available information; it does not manufacture missing state.

Query compasses bend value currents. The query does not fetch a value directly. It scores keys, the scores become weights, and those weights determine how much of each value reaches the output. The geometry is specific to routing, while the content travels on a separate path.
Illustrative conceptual figure.

The distinction is easiest to see by asking which intervention changes which quantity. Change a value while holding its key fixed. The attention weights do not move, but the output changes. Change a key while holding its value fixed. The output changes because the route changes. Change the query. Every candidate is rescored. The three vectors may originate from one token representation, yet they occupy different causal roles.

The anatomy separates address from payload. Query and key projections decide where information comes from. Value projections decide what arrives. Confusing the two hides both useful interventions and common failure modes.
Practitioner synthesis from the standard attention equation.
Mechanism

A key is not a database key

A database key names a record exactly. An attention key is a learned vector that participates in a graded comparison. It may represent syntax, position, topic, entity relation, or a mixture that has no simple verbal label. The query does not need to equal a key. It only needs to produce a useful score under the learned compatibility function.

Attention is therefore closer to content-addressed routing than exact lookup. It can interpolate among several candidates, and that interpolation is both its power and a source of ambiguity.

The argument in one pass
Chart · flow
flowchart TD
  A["The address is not the message"] --> B["How geometry becomes a route"]
  B --> C["The two controls that keep<br/>routing honest"]
  C --> D["Build it, break it, and know<br/>what it proves"]
  D -. "re-test" .-> A
  classDef first fill:#0a1424,stroke:#B96D00,stroke-width:2px,color:#e6f3ff
  classDef step fill:#0a1424,stroke:#3f7da0,stroke-width:1px,color:#e6f3ff
  class A first
  class B,C,D step
A structural route through Attention from first principles: from The address is not the message to Separate address, payload and regime…. Reading use: follow the relation, then return to the surrounding argument for evidence and limits.

How geometry becomes a route

Take one query vector q and one key vector k. Their dot product is the sum of coordinate-wise products. Geometrically, it can also be written as the product of their lengths and the cosine of the angle between them. A large positive score can therefore arise because the vectors point in similar directions, because one or both have large norms, or both.

q · k = ‖q‖ ‖k‖ cos(θ) θ is the angle between the query and key. The equation is valid in an ordinary Euclidean representation space. It shows why “similarity” is shorthand: raw dot-product compatibility includes vector magnitude as well as direction.

This matters because the model learns the query and key projections. A key can become attractive by aligning with a query direction, increasing its norm, or changing the upstream representation that produces both. The dot product is not a hand-authored semantic metric. It is a trainable interface through which the loss shapes routing.

With several keys, the model produces one score per candidate. These scores are often called logits because they are unnormalised. They can be negative, do not sum to one, and have no standalone probabilistic meaning. Softmax converts their relative differences into positive weights that sum to one. Adding the same constant to every logit changes nothing, because only differences matter.

Attention(Q, K, V; τ) = softmax((QKᵀ + M) / (√dk · τ)) V Q contains queries, K keys, V values, dk is key dimension, M is an optional mask with zero for legal routes and a very negative number for forbidden routes, and τ is temperature. The standard Transformer corresponds to τ = 1.

Softmax makes a relative claim

Take logits [2, 1, 0]. At temperature 1, softmax produces approximately [0.665, 0.245, 0.090]. The first key receives most of the route, but the other two still contribute. Add 100 to every logit and the weights remain identical. Multiply every logit by ten and the distribution becomes almost one-hot. The first transformation changes no relative evidence; the second changes the expressed margin.

This gives a useful mental model. The logits form a local contest among the candidates available to one query. Softmax does not compare a score with a universal threshold. A score of 2 can be dominant against [1, 0] and weak against [8, 7]. An attention weight therefore cannot be interpreted without the competing keys, the mask and the temperature. Routing confidence is contextual to the candidate set.

The weighted sum adds another dependency. A route weight of 0.6 on a value with norm 0.1 contributes less vector magnitude than a weight of 0.2 on a value with norm 10. Direction matters too: two large contributions can cancel. For this reason, a more complete local diagnostic inspects both the scalar weight and the vector contribution wᵢvᵢ. Even that remains local to the layer because later computation can amplify, rotate or erase the result.

Smallest useful diagnostic

Record four objects, not one heatmap

For a selected query, capture the raw logits, the post-mask and post-scale logits, the softmax weights, and the weighted value contributions. The four views answer different questions: what geometry proposed, what policy and scale permitted, how competition resolved, and what vector actually arrived. A heatmap of weights collapses these stages into one picture.

The derivative reveals the saturation problem

For softmax weight wᵢ and logit zⱼ, the derivative is (1/τ)wᵢ(δᵢⱼ − wⱼ). The symbols say something concrete. If a route is already near zero or one, the product contains a near-zero term, so small logit changes produce little weight change. Lower temperature adds a 1/τ factor but also makes extreme probabilities more likely. The net training behaviour depends on the whole distribution.

The original square-root argument targets this regime. If dimension makes raw logits large before the model has learned useful compatibility, softmax can become prematurely sharp and gradients through the routing decision can shrink. Scaling keeps initial comparisons in a range where several candidates can still compete. Once trained, a head may deliberately become sharp, but it should do so through learned geometry rather than an accidental change in dimension.

Counterfactual interventions locate the causal role. Query and key changes act before softmax, so they can reroute information. Value changes act after the route has been chosen, preserving the attention distribution while changing the output.
Illustrative causal-intervention diagram.

Three keys, one query

Let the query be q = [1, 0]. Three keys are k₁ = [1, 0], k₂ = [0.8, 0.6], and k₃ = [0, 1]. Their dot products with q are 1, 0.8 and 0. With temperature 1 and no additional dimension factor, softmax gives approximately 0.457, 0.374 and 0.168.

Now give the positions values v₁ = [10, 0], v₂ = [0, 10], and v₃ = [−5, 5]. The output is 0.457v₁ + 0.374v₂ + 0.168v₃, which is approximately [3.73, 4.58]. The query never compares itself with these value vectors. Their influence is mediated by the keys.

A complete attention calculation at mental scale. The highest-scoring key supplies the largest contribution, but the output is still a mixture. Attention can behave like a soft lookup, a broad average, or anything between those regimes.
Illustrative numerical example; values rounded.

Softmax has three properties that make it useful here. It produces non-negative weights. It makes the weights sum to one. It is differentiable, so training can adjust queries, keys and upstream representations. Yet none of these properties says that a high weight identifies the unique reason for a later prediction. The value may have a small norm, contain information copied from elsewhere, or be cancelled by subsequent computation.

Boundary condition

Softmax always chooses among the offered candidates

If every key is irrelevant, ordinary softmax still returns a distribution that sums to one. With equal bad scores, it returns a uniform mixture. A system that needs “none of these” must represent that option through a null key, gate, mask, separate abstention path or later computation. Normalisation creates a relative choice, not evidence that any candidate is adequate.

A realistic configured-system example

Consider a code model processing: approved_limit = 5000; temporary_limit = 7000; charge < limit. At the token limit, the query may be shaped to retrieve the currently relevant definition. Keys at approved_limit and temporary_limit advertise different relations. Values carry features that can update the representation at limit.

If both keys collapse to nearly the same vector, the router cannot distinguish the definitions even when their values are perfectly different. If the keys are distinct but the values omit the amount or scope, the route can be correct while the retrieved content is useless. If a causal mask forbids looking ahead, a future redefinition is not a candidate at all. The configured behaviour therefore depends on address quality, payload quality and route entitlement, not on attention weights alone.

The two controls that keep routing honest

Why divide by the square root of key dimension? The answer is not that larger vectors are intrinsically dangerous. The issue is what happens to a sum of many roughly independent products.

Assume each component of q and k has mean zero and variance one, and components are independent. Each product qᵢkᵢ then has variance one. A dot product adds dk such products, so its variance is dk and its standard deviation grows as √dk. Larger key dimension therefore produces larger-magnitude logits even when no stronger relation has been learned. Softmax sees larger gaps and becomes sharper. The Transformer paper introduced division by √dk to counteract this effect.[5]

Dimension can create counterfeit confidence. Under independent, zero-mean, unit-variance components, raw dot-product spread grows as √dk. Dividing by √dk keeps the initial score scale approximately stable, so a wider head does not automatically become more decisive.
Illustrative analytical chart from the variance assumptions in Vaswani et al.

The derivation has a boundary. Trained queries and keys are neither perfectly independent nor guaranteed to have unit variance. Their norms can drift, dimensions can correlate, and normalisation placement changes the distribution. Square-root scaling is therefore a principled baseline, not a theorem that every trained head will remain well-conditioned. Measuring logit variance, attention entropy, query and key norms, and gradient behaviour is more informative than assuming the scale has done its job.

Temperature is a separate control

Temperature divides logits before softmax. At high temperature, score differences shrink and the distribution becomes broader. At low temperature, differences expand and the largest score dominates. Hinton, Vinyals and Dean used this same softmax property to soften class distributions during knowledge distillation.[6] In attention, temperature controls how much the router interpolates among candidates.

Temperature does not normally change the ranking of finite logits. If key A scores above key B, dividing both by the same positive temperature preserves that order. What changes is the margin expressed as probability mass. This makes temperature a competition control rather than a new similarity function.

Temperature chooses the routing regime. For fixed logits [2, 1, 0], lower temperature concentrates probability on the largest score, while higher temperature approaches a uniform mixture. The key ranking is unchanged; expressed confidence is not.
Illustrative synthetic calculation; entropy normalised by log 3.

Scaling and temperature can be written in the same denominator, but they answer different questions. Square-root scaling compensates for a predictable change in logit magnitude caused by representation dimension under stated assumptions. Temperature is an explicit choice or learned parameter that changes how score gaps become mixture weights. Conflating them makes debugging difficult: a head can be sharp because its vectors have large norms, because dimension is uncorrected, because temperature is low, or because the learned relation is genuinely decisive.

Four causes of a sharp route

Suppose one attention row has maximum weight 0.999. That number alone does not tell you why. The winning key may be better aligned with the query. Its norm may be much larger. The logits may have inherited excessive variance from the projections. Or an explicit temperature may be low. These causes predict different responses to intervention.

Normalise query and key vectors to unit length. If the route becomes broad, norm was carrying part of the decision. Hold vectors fixed and raise temperature. If the route broadens while ranking remains stable, competition was the control. Compare otherwise matched heads with different dk. If unscaled sharpness grows with dimension, statistical scale is implicated. Rotate only the query. If one key remains dominant across unrelated directions, inspect key norms, biases or mask structure.

This produces a practical decomposition:

CauseDiagnostic interventionExpected signature
Directional compatibilityRotate or replace the query while preserving norms.The winner changes when the demanded relation changes.
Norm dominanceCompare raw dot product with cosine-normalised scoring.A large-norm key loses advantage after normalisation.
Dimension-driven varianceVary dk in a matched initialisation with and without √dk scaling.Only the unscaled router sharpens systematically.
TemperatureResweep τ with vectors fixed.Ranking stays stable while entropy changes predictably.

The decomposition is not a universal explanation of trained models. Correlated dimensions, biases, positional terms and upstream normalisation can produce mixed signatures. Its value is procedural: each hypothesis is tied to a perturbation. The result either narrows the cause or reveals that the simple account is insufficient.

Break condition

Square-root scaling is not scale invariance

If every new dimension is a duplicate of the same signal, the dot product grows linearly with dimension, not as √dk. Dividing by √dk then leaves a residual √dk growth. The standard correction assumes something closer to independent contributions. Strong correlation, non-zero means or changing component variance breaks the derivation. This is why the executable lab labels its dimension control as a synthetic variance model rather than literal coordinate duplication.

Attention is a trajectory, not one opaque operation. Projection defines available relations and payloads. Comparison scores them. Masking controls entitlement. Scaling controls dimensional statistics. Temperature controls competition. Softmax and aggregation finally produce the contextual output.
Illustrative state trajectory.
How the claim changes under pressure
Chart · state
stateDiagram-v2
  [*] --> Claim
  state "Why three projections are<br/>necessary" as Claim
  state "The swapped envelopes" as Test
  state "A key is not a database key" as Revision
  Claim --> Test: expose mechanism
  Test --> Decision: evidence survives
  Test --> Revision: rival survives
  Revision --> Claim: narrow or rebuild
  Decision --> [*]
The revision loop begins with Why three projections are necessary and keeps counterexamples inside the reasoning path. Reading use: follow the relation, then return to the surrounding argument for evidence and limits.

Build it, break it, and know what it proves

The shortest path to intuition is to manipulate the mechanism directly. The laboratory below contains one query, three key-value pairs, a synthetic dimension model, temperature and an optional mask. Rotate the query and the route moves. Swap values and the route stays while the output changes. Increase dimension without scaling and the route sharpens for statistical rather than semantic reasons. Lower temperature and the same ranking becomes more decisive.

Executable lab: the five-intervention attention audit

Use the controls, then compare routing weights with the output vector. The lab uses synthetic vectors and runs entirely in the browser.

Output vector[0, 0]
Normalised entropy0.00
Largest route0.00

The synthetic dimension control multiplies raw score spread by √dₖ. Enabling standard scaling removes that artificial growth.

What each intervention establishes

InterventionExpected observationWhat a positive result permitsWhat a negative result suggests
Rotate queryScores and weights change according to key direction.The router is sensitive to query-key geometry.Keys may be collapsed, logits saturated, or the query ineffective.
Swap valuesWeights remain fixed; output changes.Address and payload paths are causally separable.The implementation may have coupled keys and values incorrectly.
Increase dkUnscaled weights sharpen; scaled weights remain stable in the synthetic variance model.The √dk correction cancels expected dimensional growth.Real vectors may violate independence or variance assumptions.
Change temperatureRank stays; entropy and largest weight change.Temperature controls mixture sharpness.Masking, ties, overflow or another normalisation may dominate.
Mask a keyIts weight becomes zero and legal weights renormalise.Route entitlement is enforced before aggregation.The mask is applied at the wrong stage or with an unsafe finite bias.

A positive audit does not show that a trained model has learned the intended relation. It only shows that the implementation obeys the mechanism and its invariants. To test learned behaviour, use task-relevant perturbations: replace a pronoun’s antecedent, swap two definitions, move a clause outside a window, or create a distractor with a larger key norm. Observe both the attention distribution and the downstream output.

From equation to production kernel

The direct matrix implementation materialises an n by n score matrix for a sequence of length n. Its arithmetic and memory demands grow quadratically with sequence length. That cost belongs to the standard global attention pattern, not to the conceptual distinction between address and payload. Efficient kernels can preserve the exact mathematical result while changing the order in which blocks are loaded, normalised and multiplied.

FlashAttention is an important example. It tiles the computation to reduce movement between levels of GPU memory while retaining exact attention rather than replacing it with an approximation.[11] The engineering lesson is subtle: an implementation can change its execution schedule without changing its routing contract. Equivalence should be checked numerically within the precision expected from different accumulation orders.

That contract includes more than the formula printed in a paper. Shapes must align. Every query must retain at least one legal key. Boolean masks and additive masks must have declared semantics. The stable softmax must avoid overflow. Mixed-precision execution must not turn a large negative mask into a finite route. Dropout, when used on attention weights during training, changes the realised mixture and should be disabled for deterministic evaluation. Batch and head dimensions must broadcast intentionally rather than accidentally.

A small test harness should therefore include invariants and metamorphic tests. Weights over legal keys sum to one. Masked keys receive zero. Permuting keys and values together permutes weights but preserves the output. Swapping values without keys preserves weights but changes output. Adding a constant to every legal logit preserves weights. Replicating the computation through an optimised kernel matches a simple reference within tolerance. These tests expose errors that an end-task accuracy number can hide.

Failure case: two identical addresses, conflicting payloads

A policy sentence contains “limit approved” and “limit revoked”. Suppose their key vectors are identical for the query “which limit status applies?”, but their values encode opposite statuses. Softmax must assign equal weights to the two positions unless another score term distinguishes them. The output becomes a mixture of approval and revocation.

Increasing value quality does not fix the route. Lowering temperature does not break the tie. Square-root scaling does not create a missing distinction. The repair belongs upstream: keys need a feature for temporal status, scope or position, or the mask must remove the superseded record. When addresses collide, payloads cannot choose themselves.

This failure also clarifies why larger context is not automatically better. Adding candidates changes the relative contest. A plausible distractor can take probability mass from a useful key even when the useful key’s raw score is unchanged. Long-context evaluation should therefore measure route stability under inserted distractors, duplicated facts, superseded facts and irrelevant high-norm tokens, not only whether the answer remains present somewhere in the window.

Python · NumPy reference implementation
import numpy as np


def softmax(x: np.ndarray) -> np.ndarray:
    """Numerically stable softmax over the last axis."""
    shifted = x - np.max(x, axis=-1, keepdims=True)
    exp_x = np.exp(shifted)
    return exp_x / np.sum(exp_x, axis=-1, keepdims=True)


def attention(
    q: np.ndarray,
    k: np.ndarray,
    v: np.ndarray,
    *,
    mask: np.ndarray | None = None,
    temperature: float = 1.0,
    scale: bool = True,
) -> tuple[np.ndarray, np.ndarray]:
    """Return (output, routing_weights) for one or more queries."""
    if temperature <= 0:
        raise ValueError("temperature must be positive")
    if q.shape[-1] != k.shape[-1]:
        raise ValueError("query and key dimensions must match")
    if k.shape[-2] != v.shape[-2]:
        raise ValueError("every key must have one value")

    logits = q @ np.swapaxes(k, -1, -2)
    if scale:
        logits = logits / np.sqrt(q.shape[-1])
    logits = logits / temperature

    if mask is not None:
        if mask.shape != logits.shape:
            raise ValueError("mask must match attention logits")
        logits = np.where(mask, logits, -np.inf)
        if np.any(np.all(~mask, axis=-1)):
            raise ValueError("each query needs at least one legal key")

    weights = softmax(logits)
    output = weights @ v
    return output, weights


# Minimal invariants
q = np.array([[1.0, 0.0]])
k = np.array([[1.0, 0.0], [0.8, 0.6], [0.0, 1.0]])
v = np.array([[10.0, 0.0], [0.0, 10.0], [-5.0, 5.0]])

out, w = attention(q, k, v, scale=False)
assert np.allclose(w.sum(axis=-1), 1.0)

swapped_out, swapped_w = attention(q, k, v[[1, 0, 2]], scale=False)
assert np.allclose(w, swapped_w)       # route unchanged
assert not np.allclose(out, swapped_out)  # payload changed

Run with Python 3.10+ and NumPy. The code follows the standard scaled dot-product structure and makes masking, temperature and invariants explicit. PyTorch’s official operator applies the scale before softmax and may select optimised kernels under the same high-level contract.[10]

Optional depth: why stable softmax subtracts the maximum

Exponentials grow quickly. For logits [1000, 999], direct exponentiation can overflow even though the desired probabilities are ordinary. Softmax is invariant to adding or subtracting the same constant from every logit. Subtracting the row maximum converts the pair to [0, −1], which yields the same probabilities without overflow.

This numerical transformation does not alter the route. It only changes how the same calculation is represented on finite hardware.

The implementation boundary makes entitlement visible. In causal self-attention, the score matrix is square and the upper triangle is forbidden. Masking must occur before softmax so illegal routes receive zero weight, while legal routes renormalise.
Illustrative system-boundary view.

The strongest boundary: routing weight is not causal responsibility

Attention weights are tempting explanations because they are explicit and easy to plot. Yet empirical studies have found cases where attention distributions correlate poorly with other importance measures, where removing highly weighted items has limited effect, and where very different distributions yield similar predictions.[8][9] Other work argues that the verdict depends on the definition of explanation and on the diagnostic protocol.[7]

The dispute becomes clearer through the address-payload split. A weight measures how strongly one value vector is mixed at one layer and head. Causal responsibility for a final prediction also depends on what the value contains, its norm, interactions with other positions, residual pathways, later layers and the output readout. A routing record can be useful evidence without being a sufficient explanation.

Attention can be non-identifiable from output. Different routing distributions can be offset by different values and still produce the same result. Explanation requires a declared target and interventions across the whole relevant computation, not a heatmap alone.
Illustrative counterexample.

A disciplined audit sequence

Begin with a single query and a tiny candidate set. Verify the reference calculation by hand. Then perform the payload swap, key replacement, query rotation, temperature sweep and mask test. Only after those local mechanisms behave as expected should you inspect a full trained layer. In the trained model, freeze all but one causal object at a time and record both local output change and final task change.

For interpretation, declare the target before running the test. “Which value changed this head’s output?” is narrower than “Which token caused the next word?” The first can often be answered with value replacement and contribution analysis. The second crosses residual connections, other heads, feed-forward transformations and the final readout. A valid local explanation should not be promoted silently into a model-wide one.

For design, decide whether the task requires soft mixture, near-hard selection or an explicit null route. A relation-extraction head may benefit from decisive routing. Evidence synthesis may need several contributors. Safety-sensitive retrieval may require a gate that refuses all candidates when none meets a sufficiency threshold. Temperature and softmax can shape competition, but they cannot define adequacy by themselves.

Open research hypothesis

Routing-regime profiles may predict attention failures better than mean entropy

A useful diagnostic may need the joint profile of query norms, key norms, logit variance, entropy, mask density and value contribution norms, rather than attention entropy alone. The hypothesis would be strengthened if this profile predicts saturation, distractor capture and gradient collapse across tasks better than any single metric. It would be weakened if simple entropy or maximum weight performs equally well under controlled interventions.

A rival explanation is that downstream residual computation dominates, making attention-level diagnostics weak regardless of profile quality. The smallest useful test is a single-layer synthetic task with controlled distractors, followed by a multi-layer replication. The proposal should not be used as a model-wide interpretability score.

A routing map becomes useful only when paired with intervention sensitivity. Entropy describes concentration; intervention measures consequence. Their combination changes the next diagnostic action and avoids treating sharpness as importance.
Practitioner decision instrument.
The evidence conversation
Chart · sequence
sequenceDiagram
  participant Q as Question
  participant M as Mechanism
  participant E as Evidence
  participant D as Decision
  Q->>M: The address is not the message
  M->>E: Why three projections are necessary
  E-->>M: compare rival explanations
  E->>D: Separate address, payload and regime before reading the map
  D-->>Q: revise scope or act
Question, mechanism, evidence and decision exchange the burdens developed in Attention from first principles. Reading use: follow the relation, then return to the surrounding argument for evidence and limits.

Separate address, payload and regime before reading the map

When an attention mechanism behaves unexpectedly, do not begin by staring at a heatmap. Decide which causal object could be wrong. If changing the query does not move the route, inspect query and key geometry. If the route looks correct but the output is wrong, inspect values. If wider heads become spuriously decisive, inspect scale and norm statistics. If the ranking is sensible but the mixture is too brittle or too diffuse, inspect temperature. If an illegal position contributes, inspect masking before anything else.

The same discipline changes how attention is communicated. A high weight supports the narrow statement that a value at one address received a large mixture coefficient at a particular layer and head. It does not, without further tests, support the broader statement that the token was the reason for the model’s answer. The latter requires intervention on the relevant path and a declared explanatory target.

The practical decision is to debug and interpret attention as a routed computation with separate address, payload and regime controls. This framing is more demanding than a heatmap, but it is also more useful. It tells an engineer what to perturb, what should remain invariant, and which conclusion a result actually permits.

Decision rule: before trusting any attention pattern, perform at least one address intervention, one payload intervention and one regime intervention. Treat the pattern as explanatory only for the target whose output changes under those controlled tests.

Glossary

Query
A learned vector representing what the current position seeks from candidate positions.
Key
A learned vector used to score whether a candidate position matches a query.
Value
The vector contribution carried from a candidate position after routing weights are chosen.
Logit
An unnormalised compatibility score before softmax.
Softmax
A differentiable transformation that converts relative logits into positive weights summing to one.
Temperature
A positive divisor that controls how sharply softmax expresses score differences.
Mask
A constraint that removes illegal query-key connections before normalisation.
Attention entropy
A measure of how broad or concentrated a routing distribution is, not a measure of correctness or consciousness.

References

  1. Bahdanau, D., Cho, K. and Bengio, Y. (2014). Neural Machine Translation by Jointly Learning to Align and Translate.
  2. Luong, M.-T., Pham, H. and Manning, C. D. (2015). Effective Approaches to Attention-based Neural Machine Translation.
  3. Graves, A., Wayne, G. and Danihelka, I. (2014). Neural Turing Machines.
  4. Sukhbaatar, S., Szlam, A., Weston, J. and Fergus, R. (2015). End-To-End Memory Networks.
  5. Vaswani, A. et al. (2017). Attention Is All You Need.
  6. Hinton, G., Vinyals, O. and Dean, J. (2015). Distilling the Knowledge in a Neural Network.
  7. Wiegreffe, S. and Pinter, Y. (2019). Attention is not not Explanation.
  8. Jain, S. and Wallace, B. C. (2019). Attention is not Explanation.
  9. Serrano, S. and Smith, N. A. (2019). Is Attention Interpretable?
  10. PyTorch. torch.nn.functional.scaled_dot_product_attention.
  11. Dao, T., Fu, D. Y., Ermon, S., Rudra, A. and Ré, C. (2022). FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness.