THIS EXPLANATION
THE ROOM
CDA·11 Computing, Data & AI 6 MIN · 8 STATIONS

Attention as a budget

A Socratic walk-through of attention as a budget — reasoned out one step at a time, not lectured.

abcdefgh
a

The question we started with

THE QUESTION #

How does a model work out which earlier word a pronoun refers to?

Take the sentence "The trophy did not fit in the suitcase because it was too large." Every English speaker resolves it to the trophy without effort. Swap "large" for "small" and the same pronoun now means the suitcase. Nothing about the pronoun changed; nothing about the grammar changed. Only a fact about the world moved.

So a model that handles this cannot be following a syntactic rule about nearest noun. It has to be weighing candidates. Which raises the question worth chasing: when a model reads it, what does it actually do with the words behind it — and what stops it simply mixing them all together into mush?

b

Reasoning it through

REASONING #

Suppose you were designing this. At the position of it, you have representations of all the earlier words available. You want to pull in information from the one that matters. The blunt option is to average them all, but an average of "trophy", "suitcase", "fit" and "because" tells you nothing — averaging destroys exactly the distinction you need.

So you want a weighted average, where the weights are computed rather than fixed. That is attention, and the mechanism has three parts worth naming. Each position emits a query — roughly, "what am I looking for?" Each position also emits a key — "what am I, to someone looking?" The model scores every query against every key with a dot product, and where a query and key point in similar directions, the score is high. Then each position offers a value, the content it will contribute if attended to, and the output at it is the sum of all values weighted by those scores.

Now the constraint that gives this piece its name. Those raw scores could be anything — large, negative, wildly different in scale. They are passed through a softmax, which exponentiates them and divides by their total. The consequence is precise and important: the weights are all positive and they sum to exactly one. Every position spends the same fixed budget of attention, distributed differently.

Ask what that buys us. Because the budget is fixed, attention is inherently competitive. There is no setting in which every earlier word is attended to strongly; giving more weight to the trophy necessarily means giving less to everything else. That is why the mechanism can select rather than merely accumulate. A model with an unnormalised sum could satisfy "attend to the trophy" by simply turning up the trophy without turning anything down, and the representation would drift in magnitude as sentences got longer.

Where does the world knowledge come in? The query emitted at it is not a fixed "find me a noun" probe. It is computed from the representation at that position, which by the middle layers already carries information gathered from the surrounding words — including "too large". The keys at "trophy" and "suitcase" carry what those words are, again in context. So the compatibility score between them can encode something like the thing that would be too large in a failed fit rather than mere nounhood. It is not looking up a fact about trophies; it is that the training data made these directions align.

One honest caveat. It is tempting to say "there is a coreference head that does this", and researchers have found heads whose attention pattern aligns strikingly with syntactic and coreference relations — Clark and colleagues showed this for BERT in 2019. But the clean story oversells it. The work is spread across many heads and layers, heads that look interpretable on one distribution behave differently on another, and no one has a reliable method for pointing at a head and saying "that is where this pronoun was resolved". The mechanism is well understood; the attribution of any particular resolution to any particular head is not.

c

The analogy

THE ANALOGY #
THE FIGURE

Think of a fixed sum of money you must spend completely, every round, on informants. You cannot save any and you cannot borrow. If one informant looks promising, funding them means defunding the others — the ranking is forced on you by the fact that the total never changes. That compulsion to allocate is what makes your final report a judgement about who mattered rather than a transcript of everyone who spoke.

WHERE IT BREAKS DOWN

Money buys a single informant's whole testimony, whereas attention returns a blend — the output at it is a genuine mixture of every value weighted by its share, so even a dominant candidate arrives contaminated with a little of everything else, and it is layers of subsequent processing, not a clean pick, that turn a mixture into a decision.

d

Clarifying the model

THE MODEL #

Three refinements.

First, this happens many times over in parallel. A layer runs several attention heads at once, each with its own queries, keys and values and therefore its own separate budget. One may track syntactic dependency, another positional proximity, another something with no human name. Their outputs are concatenated and mixed, so the "one fixed budget" picture is per head, not per model.

Second, the softmax's fixed total has a curious consequence: what does a head do when nothing in the sentence is relevant to it? It cannot abstain — the weights must still sum to one. In practice, models dump this unwanted mass on semantically empty positions, most often the very first token, a phenomenon documented as an attention sink. It is a real artefact with practical consequences: systems that trim old context must be careful not to evict the sink, or generation degrades.

Third, correct a natural misreading. A high attention weight is not the model "deciding" the pronoun's referent. It is one contribution to a representation that further layers will keep transforming. Attention weights are suggestive evidence about information flow, not an explanation of the output — which is exactly why interpretability work treats them with more caution than their intuitive appeal invites.

e

A picture of it

THE PICTURE #
Attention as a budget
Attention as a budget The single source on the left is one attention head at the position of the pronoun, and the width of the whole flow is fixed at 100 -- that is the softmax constraint made visible. Trace how the ribbons split: widening the trophy ribbon can only be paid for by narrowing the others. Follow every ribbon to the right and see that they all rejoin, which is the point of the analogy's breakdown -- the result is a blend, not a selection. The numbers are illustrative proportions chosen to show the shape of a typical resolution, not measurements from a specific model; only the fact that they total 100 is guaranteed by the mechanism. {"generator":"[email protected]","source":"../Socrates/.diagram-cache/_src/attention-as-a-budget.md","sourceIndex":1,"sourceLine":4,"sourceHash":"a088f08edd6e2e43915111ba32620bbd62bb095495d04acb33fcf2c3d9c0e786","diagramType":"sankey","layoutVariant":"source","repairedDuplicateIds":[],"motion":"entrance-with-reduced-motion-fallback","presentation":"editorial","attempt":1,"viewBox":{"x":0,"y":0,"width":720,"height":551},"qa":{"passed":true,"findings":[]}} Onehead'sbudgetatthewordit · 100 trophy · 46 suitcase · 21 large · 14 firsttokensink · 12 everythingelse · 7 Blendedrepresentationofit · 100

How to readThe single source on the left is one attention head at the position of the pronoun, and the width of the whole flow is fixed at 100 — that is the softmax constraint made visible. Trace how the ribbons split: widening the trophy ribbon can only be paid for by narrowing the others. Follow every ribbon to the right and see that they all rejoin, which is the point of the analogy's breakdown — the result is a blend, not a selection. The numbers are illustrative proportions chosen to show the shape of a typical resolution, not measurements from a specific model; only the fact that they total 100 is guaranteed by the mechanism.

f

What became clearer

WHAT CLEARED #
WHAT CLEARED

Attention resolves a pronoun by making every position spend one fixed unit of relevance across everything it can see. The queries and keys that set the split are computed from context, so the competition can be decided by meaning rather than by grammar or distance — which is why "too large" and "too small" send the same pronoun to different nouns. The normalisation is not housekeeping: it is what turns accumulation into selection, and its side effects, from competitive sharpening to the attention sink, follow directly from the total being conserved.

g

Where to go next

ONWARD #
  • Why the fixed budget also imposes a cost that grows with the square of the sequence length.
  • How Winograd-style sentences became a test of world knowledge rather than of grammar.
h

Key terms

TERMS #
TermWhat it means
Query, key, valuethe three projections of each position: what it seeks, how it advertises itself, and what it contributes when attended to.
Softmaxthe normalisation that turns raw scores into positive weights summing to one.
Attention headone independent instance of the mechanism, with its own budget, run alongside others in the same layer.
Attention sinkthe tendency to place leftover attention mass on a semantically empty position, usually the first token.
Coreferenceworking out which earlier expression a pronoun or referring phrase points to.

Every term the collection defines is gathered in the glossary.

Nearby on the shelf

4