Position as a rotation, not an addition
The original transformer adds a position vector to the token embedding, which mixes what a token is with where it sits, in the same coordinates.
Rotary embeddings instead rotate the query and key vectors by an angle proportional to their position, leaving the embedding itself untouched.
The vector is taken two dimensions at a time and each pair is rotated in its own plane, so the operation is a block-diagonal rotation matrix.
A rotation preserves length, so no information about the token is scaled away, which addition cannot promise.
Why the dot product becomes relative
Two rotations composed give a rotation by the difference of the angles, so the attention score depends only on .
That is the whole result. Absolute positions go in and only the relative distance comes out, without any extra parameters or a bias table.
Each pair of dimensions rotates at a different frequency, fast in the early dimensions and slow in the later ones.
The slow frequencies encode coarse position across a long document and the fast ones encode fine local order, which is the same reasoning as the sinusoidal scheme it replaced.
One attention step, in order
- Project the token to queries and keys as usual.
- Split each into consecutive pairs of dimensions.
- Rotate pair by , where is the token's position.
- Take the dot product of the rotated query and key.
- Softmax and apply to the values, which are not rotated at all.
Values carry content rather than being compared, so rotating them would distort what is retrieved without changing what is matched.
What it buys in practice
There are no learned position parameters, so nothing has to be resized when the context length changes.
It is applied inside every attention layer rather than once at the input, so the position signal does not have to survive fifty layers of mixing.
Scores decay as grows.
Distant tokens interfere across many frequencies at once, which produces a gentle decay with distance that matches how language actually behaves.
Extending the context
Position interpolation divides every frequency by the scaling factor, so a model trained at 4,000 tokens can read 32,000 by rotating more slowly.
It works because the model has seen every angle already. It is being asked to interpolate rather than to extrapolate, and a short fine-tune closes the remaining gap.
NTK-aware scaling refines this.
The refinement scales the slow dimensions harder than the fast ones, so long-range position stretches while local word order stays exactly as trained.
That is how almost every open model published with a long context reached it, and it is why RoPE is now near-universal.