Zenaique

Spot the flaw: a claim that attention by itself notices position.

Spot the error·Medium·4.0 · 0·~2 min·Asked atDatabricksJasperUber·Relevant atMicrosoft
Attempt it

Click any words you think contain an error. Click again to unmark.

Mark at least one word to submit.
TL;DR

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.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

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.

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:

Attn(X)=softmax ⁣(XWQ(XWK)dk)XWV\text{Attn}(X) = \text{softmax}\!\left(\frac{XW_Q (XW_K)^\top}{\sqrt{d_k}}\right) XW_V

For any permutation matrix P (which permutes rows), substituting PX for X gives:

Attn(PX)=PAttn(X)\text{Attn}(PX) = P \cdot \text{Attn}(X)

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'.

Why the misconception is common
The four production positional schemes
Practical consequences of getting this right
The unifying principle
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.

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.
Sign in to see more production examples.

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?
A

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.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

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.

Sign in to see all red flags and common mistakes.

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

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
Explain scaled dot product attention.
Short answer·Medium