RΘ,mR_{\Theta, m}

RoPE rotation matrix

Read "R theta m". It rotates a query or key vector by an angle that grows with the token's position m, so position is stored as an amount of rotation.

RoPE (rotary position embedding) splits the vector into d/2d/2 pairs of numbers and rotates each pair, like a point on a plane, by the angle mθim\theta_i. Here mm is the position and θi=10000−2(i−1)/d\theta_i = 10000^{-2(i-1)/d} is that pair's frequency. Fast-turning pairs distinguish nearby positions; slow-turning pairs distinguish distant ones.

Two rotations combine neatly: Rm⊤Rn=Rn−mR_m^\top R_n = R_{n-m}. So the score between a query at position mm and a key at position nn depends only on the distance n−mn - m. Each token is rotated by its own absolute position, yet attention only sees relative positions, and nothing is added to the embeddings.

Example

Rm=[cos⁡mθ−sin⁡mθsin⁡mθcos⁡mθ]R_{m} = \begin{bmatrix} \cos m\theta & -\sin m\theta \\ \sin m\theta & \cos m\theta \end{bmatrix}

The rotation for one pair of numbers at position m.

Where the course uses it

Related terms