What is the sinusoidal positional encoding, and why is a linear function of ? How do rotary position embeddings (RoPE) make attention scores depend only on relative position?
Sequence models and transformers, Positional encoding
Level L4 Advanced. Length Medium. Nature Th+Mat Both.
What's being asked
Whether you can use the angle-addition formulas to show the encoding has a relative-position structure, and know how RoPE turns that into a property of the dot product.
Key idea
Each frequency pair at position is a point on a circle, so a shift by is a rotation: . RoPE rotates and by angles set by their positions, and for 2-D rotation matrices , .
Steps
- Definition: and , with , where is the model dimension. The frequencies fall geometrically from to about .
- Shift: by and , each pair at equals the rotation matrix above (which depends only on ) times the pair at . Stacking the pairs gives a block-diagonal matrix with .
- Limitation: sinusoids are added to the embeddings , so the score mixes content with absolute position. Relative position is available, but not enforced.
- RoPE: split and into 2-D pairs, and rotate pair by angle at position : and .
- Then , which depends on the positions only through . RoPE is applied to queries and keys in every layer, not to values, and it is not added to the embeddings.
Common mistakes
- Getting the frequency wrong, e.g. without the minus sign.
- Claiming that additive sinusoidal encodings make attention purely relative.
- Applying RoPE to the values, or adding it to the input embeddings.
How long your answer should be
About 4 minutes; the rotation identity and the RoPE line.
Last checked on 4 December 2026.
Read this
Previous in Sequence models and transformers: In speculative decoding, a draft model proposes tokens and each is accepted independently with probability . How do you derive the expected number of tokens produced per target-model forward pass, what is its value for and , and what is the expected speedup if one draft forward pass costs of a target forward pass?
Next in Sequence models and transformers: How can softmax attention be written as a kernel smoother? Why does replacing by a feature-map kernel reduce the cost from to ? How can causal linear attention be computed as an RNN, and what is lost?