Zenaique

Compare absolute and relative positional encoding. What does the score depend on in each case?

MCQ·Medium·4.0 · 0·~1 min·Asked atMercorMicrosoft
Attempt it
TL;DR

Absolute PE makes the attention score depend on positions m and n separately; relative PE makes it depend only on the offset (m - n). The latter gives translation invariance and better length extrapolation.

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

Picture two people standing on a number line. Absolute thinking says 'one is at 7 and the other is at 12, and the score depends on those numbers'. Relative thinking says 'they are 5 apart, and that is all that matters'. If you slide both of them three steps to the right (now at 10 and 15), absolute thinking sees new numbers and recomputes. Relative thinking shrugs because the gap is still 5. Modern long-context models all want the relative behavior because real language patterns care about how far apart tokens are, not where they sit in the absolute timeline.

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.

Absolute versus relative positional encoding is one of the most consequential design splits in modern transformer architecture. The decision shapes whether a model can extrapolate to longer context than it was trained on. It determines which long-context extension techniques (YaRN, LongRoPE, NTK scaling) apply. It also indirectly drives the architectural convergence of 2024-2026 open-weight LLMs onto a small family of RoPE-based designs.

The formal definition: function-of property

Strip away all the named schemes and ask the bare question: what is the attention score s_mn = (q_m . k_n) / sqrt(d_k) a function of?

Absolute property

s_mn = f(q_m, k_n, m, n) where m and n enter as separate arguments. Shifting the whole sequence by a constant t (so position m becomes m+t, position n becomes n+t) changes the score, because the function sees the new absolute positions.

Relative property

s_mn = f(q_m, k_n, m - n) where only the offset (m - n) enters. Shifting the sequence does NOT change scores: s_{m+t, n+t} = s_{mn}.

The relative property is translation-equivariance of attention. It is the right inductive bias for sequence modeling because language patterns generally depend on how far apart tokens are, not on their absolute location in the sequence. The verb 'bites' links to a noun 5 tokens away whether that noun is at position 12 or at position 5012.

Why the formal definition matters

Named schemes can confuse the issue (sinusoidal involves sines, doesn't that make it 'relative'?). The function-of definition cuts through: sinusoidal PE is absolute because the score still ends up being a function of m and n separately. The use of trig functions in the encoding does not by itself confer the relative property.

\text{Translation equivariance}: \quad s_{m+t,\, n+t} = s_{m,n} \text{ for all } t
The five standard schemes, mapped
Why relative wins for long context
RoPE algebra: showing the relative property
The current convergence and what remains open
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.

  • Llama 3, Mistral, Qwen3, and DeepSeek-V3 all use RoPE because of its relative-position property and long-context extensibility.
  • Original 2017 transformer used sinusoidal absolute PE; BERT and GPT-2 used learned absolute PE.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QRoPE rotates Q and K. Show algebraically that the resulting dot product depends only on (m - n).
A

Represent each pair of adjacent Q dimensions as a complex number z_q. RoPE rotation is multiplication by e^{i theta m}. The dot product q_m . k_n becomes Re(z_q e^{i theta m} conj(z_k e^{i theta n})) = Re(z_q conj(z_k) e^{i theta (m - n)}). The exponent depends only on the offset.

1 more follow-up 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

Confusing where each scheme is APPLIED (input vs logits) with what each scheme is a FUNCTION OF (absolute positions vs offset). Those are independent axes.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • Define translation-equivariance of the attention score

  • Map each PE family (sinusoidal, learned, T5 bucket, RoPE, ALiBi) to absolute or relative

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