For each item, decide which other items matter using query–key matches, then blend their values — the core operation inside transformers.
Attention lets a model decide, for *each* item, which other items matter right now. Instead of treating all inputs equally, it dynamically pulls in exactly the context it needs. This single operation is the heart of every transformer.
Every item produces three vectors, by analogy with looking something up:
q — what the current item is *looking for* (its question).k — what each item *offers* (its label, to be matched against queries).v — the actual *content* an item contributes when attended to.√d_k to keep them from getting too large as the vectors grow.# scaled dot-product attention (Vaswani et al., 2017)
scores = Q @ K.T / sqrt(d_k) # how well each query matches each key
weights = softmax(scores) # rows sum to 1 — the focus distribution
output = weights @ V # weighted blend of the valuesit matches the key of animal more strongly than street. Softmax puts most weight on animal, so it's output vector is mostly the *value* of animal — the model has resolved the reference by attending to it.n. Doubling the sequence quadruples the work and memory — the main reason long-context efficiency is an active research area.