Attention / Position
verifiedRotary Position Embedding
Rather than adding position to a token's representation, RoPE rotates it — by an angle proportional to where it sits. Two tokens dotted together then depend only on the angle between them, which is the distance separating them. Relative position falls out of the geometry instead of being learned.
Rotate each pair of dimensions of Q and K by an angle proportional to position before the dot product. It touches queries and keys only, never values, and adds no parameters. The relative property holds exactly, which is why it extrapolates further than absolute schemes and why context-extension tricks work by rescaling its base frequency.
Group the d sub k dimensions into pairs and rotate pair i at position m by angle mθ sub i with θ sub i = 10000 super −2i/d . Then ⟨R sub m q, R sub n k⟩ depends on m − n alone. Scaling θ's base extends the usable context by slowing the rotation.
8 values. The left group decays steeply; the right group is 67% of the way to flat, and reads flatter than the left.
Rotation rates across dimension pairs, fastest first. Drag the count to see the spread of scales a position is encoded across.
Reviewed by opendroid · 2026-08-04
- arXiv:2104.09864 — RoFormer: Enhanced Transformer with Rotary Position Embedding