Spot the flaw: a claim that attention by itself notices position.
Click any words you think contain an error. Click again to unmark.
The flaw is the premise. Attention has zero positional awareness on its own; it is permutation-invariant. Locality comes from positional encoding plus training, not from attention itself.
Imagine a librarian who can fetch any book from a shelf in equal time no matter where it sits. Now blindfold the librarian. Without any markers on the shelves, the librarian has no idea which book is at position 1 versus position 100, all the shelf does is hold books and offer them up on request. Attention is that blindfolded librarian. The 'shelf positions' (positional encoding) are the markers we add so the librarian can reason about order at all.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
The claim in the question is a tempting but incorrect intuition. Trained transformers show clear locality patterns in their attention maps, so it is natural to read those patterns as evidence that attention itself encodes position. The truth is the opposite: attention has no positional awareness whatsoever. It is a set operation. Every bit of positional structure in a trained transformer flows from the positional encoding scheme, which is an architectural injection, not an emergent property of attention.
This is one of the most fundamental properties of self-attention, and getting it wrong causes a cascade of downstream confusions: about which positional scheme to choose for length extrapolation, about why models fail on shuffled inputs, about the difference between attention pattern and positional encoding, about why ViT works at all on image patches.
This deep dive walks the permutation-invariance argument, the four production positional encoding schemes, why trained models show locality patterns despite attention's positional blindness, and the practical consequences of getting this distinction right.
The permutation-invariance argument
Self-attention is permutation-equivariant by construction. Shuffle the input tokens and the outputs shuffle the same way, with no extra positional bias.
The math
Let X be the input matrix of shape (n, d) where row i is the embedding of token i. Self-attention computes:
For any permutation matrix P (which permutes rows), substituting PX for X gives:
The operator commutes with permutation. The indices i and j appear in the score s_ij = q_i . k_j / sqrt(d_k) only as labels for which rows you are looking at, not as values entering the computation. No positional bias is added by attention.
What this means concretely
- Input order matters for what the OUTPUT looks like (rows are in a specific order), but not for what is computed at each output position.
- A token at position 5 with embedding e_5 attends identically to a token with embedding e_5 at position 100, given the same K and V from the rest of the sequence.
- The model has no way to express 'the token immediately before me' without a positional signal.
Without positional encoding, the model cannot distinguish 'dog bites man' from 'man bites dog'.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
Real products, models, and research that use this idea.
- Vaswani et al. 2017 introduced sinusoidal positional encoding precisely because attention has no positional awareness.
- Llama 4 Maverick, Mistral Large 3, Qwen 3.5, and DeepSeek V4 all use RoPE for positional encoding.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy does RoPE give the attention dot product a relative-position property?
RoPE rotates Q and K by position-dependent angles such that q_m . k_n depends only on the difference m - n. The rotation factors cancel for everything except the relative offset, giving the model a built-in relative-position structure without learnable per-position parameters.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Reading attention's locality-friendly behavior in trained models as evidence that attention itself encodes position. The locality comes from the positional encoding plus training; remove the encoding and the behavior vanishes.
60 second bullets to scan on the way to the call.
What permutation invariance means for self-attention
Why q_i . k_j does not depend on the indices i and j without positional encoding
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.