Chapter 1: Descartes' puzzle↗
When looking at a piece of wax, what exactly is being seen?
In the Second Meditation, published in 1641, Descartes brings a piece of wax, fresh from a beehive, near a fire. Its color, shape, smell and texture change, yet it is recognized as the same wax.
Seeing becomes more than an inventory of sensory properties. Descartes appeals to an inspection of the mind, inspectio mentis, to discuss understanding and judgment. This is not yet a computational theory of selective attention.
More than three centuries later, a related question appears in neural networks: what is meant when a model is said to “attend”?
Chapter 2: A counterintuitive turn↗
Recurrent models such as RNNs, LSTMs and GRUs update a state along the sequence. The next state depends on the previous one. Information resembles water passing through successive gates.
That feels natural. Language unfolds in order; music unfolds in time. But ordered inputs do not require every internal computation to queue in the same order.
Attention did not begin in 2017. Bahdanau, Cho and Bengio's work, released in 2014 and published at ICLR 2015, already let translation models read different source positions as needed, alleviating the bottleneck of a fixed-length summary.
In 2017, Attention Is All You Need introduced the Transformer, replacing the central sequence-aligned recurrent path with self-attention. Positions could interact directly rather than passing information through every intermediate state.
That interaction has a visibility boundary. Full encoder self-attention can read the entire sentence; an autoregressive decoder uses a causal mask to exclude future information. Training can process many positions of a known sequence in parallel, while generation still usually produces new tokens one at a time.
The organization of computational dependencies changes. Time and order do not disappear.
Chapter 3: An analogy, the detective's inquiry↗
Imagine a detective investigating a case.
Along the recurrent route, witnesses are interviewed in order and earlier statements continually folded into notes. By the hundredth witness, details from the first may be hard to recover. This illustrates transmission through a limited state; recurrent systems with attention need not rely on a single summary alone.
Self-attention is more like placing statements in one hall, where each position can read other available material as needed. In causal decoding, later statements have not been released. Earlier positions cannot peek ahead.
Which arrangement is more likely to uncover the truth? That depends on the task, representation and training. A hall shortens communication paths without guaranteeing accurate testimony or a correct investigation.
Chapter 4: The mathematics of attention↗
Open the hood. What actually happens in that hall?
4.1 Query, key and value: search, matching and content↗
Start with three roles:
- Query: what conditions does this position use to seek information?
- Key: what vector does another position offer for matching?
- Value: what content is actually transmitted after matching?
Think of entering a library with a query about quantum mechanics, matching catalogue information, then reading the contents. Model Q, K and V vectors are not hand-written topic labels, and the operation need not select just one book.
For self-attention, let contain representations at positions. Learned matrices produce:
Here, and . Different projections give the same input its query, key and value roles. Cross-attention can obtain queries and key–value pairs from different sequences.
4.2 Scaled dot products: allocate weights, then collect content↗
Basic scaled dot-product attention is:
The mask adds zero for visible positions and for prohibited ones. Row of distributes query position 's weights across keys; contains the aggregated outputs.
First, gives compatibility scores. A dot product depends on vector lengths as well as directions. It is neither simply cosine similarity nor a statistical correlation coefficient.
Second, divide by and apply softmax row by row. In this basic form, each row has nonnegative weights summing to one; masked positions receive no weight.
Third, combine values with those weights. Before output projection, a head produces a weighted combination rather than retrieving one untouched book. Attention dropout or a subsequent output projection also prevents treating the entire module as that same convex combination.
4.3 Why divide by a square root?↗
The original paper offers an illustrative assumption. If all components of and are mutually independent, with mean zero and variance one, then has variance . Larger dimensions can produce large scores, pushing softmax toward sharp distributions with very small gradients. Scaling restores variance one under this assumption.
This motivates a design choice. It does not mean trained representations always behave as independent random variables. The weights provide learned information routing, not an explanation that is valid by default.
Chapter 5: Multiple heads, multiple perspectives↗
One head may not suffice because matching need not follow one criterion.
Back in the library, one reader cares about topic, another about difficulty, a third about date. This offers an intuition for different projections; it does not assign those jobs to heads in advance.
Multi-head attention computes with separate and combines the results. If head outputs , write:
After concatenation, , with output projection . The original base Transformer uses eight heads, , and per head. These are configuration choices, not constants for every model.
Clark and colleagues' 2019 analysis of BERT finds heads attending to delimiters, particular positional offsets, or patterns corresponding to syntax and coreference. Heads need not be nonredundant, and a pattern alone does not show that one head independently performs a linguistic function.
A detective team can read clues differently. Establishing who advanced the conclusion also requires following the transmitted content and its downstream effects.
Chapter 6: Positional encoding, the ghost of the sequence↗
Wait. If positions match directly, where does order enter?
6.1 The same words, a different relation↗
Consider a deterministic full self-attention map without positional encoding or masking. If permutes input rows, then:
Permute the input, and the output permutes with it. This is permutation equivariance, not an unchanged output matrix. For corresponding words, however, this layer alone does not identify their original sequence indices.
The Chinese sentences “我爱你” and “你爱我” contain the same words—“I,” “love” and “you”—but express different relations. Without an additional order signal, full matching cannot be expected to know which came first.
A causal mask changes the premise: different positions see different prefixes, introducing asymmetry. The unmasked equivariance argument does not apply unchanged to every Transformer setting.
6.2 Sinusoidal positions↗
The original paper adds positional encodings to input embeddings. Its sinusoidal version is:
Here, is position and indexes sine–cosine dimension pairs, assuming even . Each pair has a different frequency. For a fixed offset, the new encoding within each pair is a linear transformation of the old one.
The same word embedding at the first and third positions therefore becomes different after position is added.
These functions can be evaluated beyond the training length. That does not guarantee reliable behavior on unseen long sequences. Computing a new coordinate and learning to use it are different achievements.
Chapter 7: Attention as epistemology↗
Return to Descartes.
Why is wax recognized as the same wax after its appearance changes? The question makes the organization and judgment within seeing less self-evident. A Transformer offers a specific computation: calculate content-dependent matching weights, aggregate vectors and pass the result onward.
There is a suggestive connection, not a philosophical proof supplied by the formula. Content-dependent weighting does not establish mental inspection, understanding or a subjective gaze in Descartes' sense.
An attention visualization does show part of the model's computation. How that part contributes to the result cannot be read from heatmap colors alone. Jain and Wallace, 2019, show that different weights can yield similar predictions in some settings; this does not prove attention has no causal role. For the methodological debate, see Hume's Ghost.
Calling a machine “attentive” first identifies a computational relationship. What psychological meaning is being added beyond it?
That may be the least familiar question inside this familiar word.