The machinery of attention is simple enough to state: every word in a sentence gets to look at every other word, weigh how much each one matters, and gather in what it needs. It is a flexible mechanism, and it hides a blind spot. Left to itself, attention has no idea what order the words came in. A sentence arrives as a handful of scrabble tiles tipped onto a table: all the pieces are there, and nothing says which came first. “Dog bites man” and “man bites dog” are, to raw attention, the same pile. Since word order carries a great deal of meaning, something has to hand the model the seating chart. Rotary Position Embedding — RoPE — is how most current models do it, and the move is physical: it tells each word where it sits by rotating it. This piece is about why that works, what it buys at longer lengths, and the one thing it does not fix.

Why order has to be supplied at all

It is worth pausing on the blind spot, because everything follows from it. Inside attention, each word is turned into a bundle of numbers — a vector, an arrow pointing somewhere in a high-dimensional space — and words compare themselves to one another by measuring how aligned their arrows are. That comparison does not depend on where in the sentence each word happened to appear. Swap the first and last word and the arrows are unchanged, so the comparisons come out identical. The mechanism is permutation-blind by construction. This is not a bug so much as a consequence of how the math is built, but it means that if the model is to know that “not” sits before “happy” rather than after it, the information has to be injected deliberately. Every positional scheme ever invented is a different answer to one question: how does each word learn where it sits?

The tempting first answer, and why it strains

The obvious idea is to stamp each word with its seat number — position one, position two, position three — by adding a position-specific pattern to its vector before attention sees it. This is the original approach, and it works. It also has a nagging weakness. The model learns what each seat number means only from the lengths it saw during training. Show it a text longer than anything it trained on and it meets seat numbers it has never encountered, and its sense of position frays. There is something wasteful about it too: language rarely cares about a word’s absolute seat. What matters is almost always relative — “the adjective two words before this noun,” “the subject back at the start of the clause.” That relationship is the same whether the phrase lands near the beginning of a paragraph or near the end. A scheme built around absolute seat numbers encodes the wrong thing and then hopes the model can recover the thing it wanted. RoPE encodes the right thing directly.

The core idea: rotate each word by its position

Here is the move at the heart of RoPE. Take each word’s vector and, before attention compares it with the others, rotate it by an angle that depends on its position in the sentence. The word in position one is turned a little; the word in position two, twice as much; position three, three times as much, and so on. Picture each word’s arrow lying on a clock face: RoPE spins the first word’s hand forward by one tick, the second word’s by two ticks, the tenth word’s by ten.

At first this looks as though it would reintroduce the absolute-position problem in a new costume, since each word is being turned by its own absolute seat number. What matters is what happens when two rotated words then compare themselves. Attention measures alignment between two arrows. Rotate two arrows and then measure how aligned they are, and the answer depends only on the difference between the two rotations, not on either rotation on its own. Turn both arrows by the same extra amount and their relative angle is untouched. So a word at position 5 and a word at position 8, each spun by its own absolute position, compare in a way that depends only on the gap — three positions apart — and come out identical for a pair at positions 105 and 108. The rotation is by absolute position, and what survives the comparison is purely relative distance. That is the whole trick: the simplicity of stamping each word independently, with the robustness of caring only about gaps, at the price of a pair of sines and cosines.

Rotating both arrows leaves only the gap

Figure 1. Rotating both arrows leaves only the gap.

A pinch of math: rotation is just a small turn

The idea is easy to make precise. Take a word’s vector and chop it into pairs of numbers — the first two, the next two, and so on. Each pair is treated as a two-dimensional arrow, a point on its own dial. To rotate a two-dimensional arrow $(x_1, x_2)$ by an angle $\theta$, apply the standard rotation:

$$\begin{pmatrix} x_1' \\ x_2' \end{pmatrix} = \begin{pmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{pmatrix} \begin{pmatrix} x_1 \\ x_2 \end{pmatrix}$$

That is all a rotation is: mix the two numbers together using sines and cosines so the arrow swings around the dial without changing length. RoPE sets the angle to be the word’s position $m$ times a fixed base rate, so the pair is turned by $m\theta$. Now the payoff. When a word at position $m$ compares with a word at position $n$, the comparison for each pair works out to depend on the angle $(m - n)\theta$ — the difference of their positions. The absolute positions $m$ and $n$ enter only through their difference. The interaction between two words becomes a function of $m - n$ alone, which is the relative-distance behaviour wanted, falling out of the arithmetic of rotation. This is the property the additive schemes could only approximate: there, position was added to content, the score expanded into four terms, and only one of them was a clean function of the gap. Here nothing else survives the comparison.

Fast and slow dials: caring about near and far at once

One more ingredient makes RoPE work in practice, and it explains a detail passed over above. Not every pair of numbers is rotated at the same rate. RoPE assigns each pair its own turning speed — some dials spin quickly as position advances, others turn slowly. The fast dials complete a full revolution over a few positions, so they are sensitive to fine, local distances: is this word right next to that one, or two away? The slow dials take hundreds or thousands of positions to come around, so they track coarse, long-range structure: are these two words in the same paragraph, or pages apart?

The hands of a clock divide labour the same way. A second hand resolves seconds and is useless for months; an hour hand gives the rough time of day and resolves nothing finer. By spinning many dials at many speeds at once, RoPE hands the model a multi-scale sense of distance — sharp up close, gentle far away — from the same act of rotation. This spread of frequencies is why RoPE captures both phrase-level and passage-level structure without any of it being learned or stored.

Many dials, many speeds

Figure 2. Many dials, many speeds.

Nothing to store, nothing to run out of

Step back and notice what RoPE does not need. There is no table of position patterns to learn, so there is nothing that runs out when a text grows longer than the training texts. The rotation for position one-thousand-and-one is computed the same way as the rotation for position five, by turning through a larger angle. Because the scheme is a mathematical function of position rather than a lookup of memorized values, it extends past its training lengths more gracefully than the old stamp-a-seat-number approach. It costs almost nothing to store and little to run: rotating a handful of number-pairs is cheap. It also acts on the query and key vectors before any score matrix exists, which leaves the fused attention kernels of FlashAttention undisturbed. A scheme that adds a bias to the score grid has to index into that grid instead, and the article on positional encoding records the consequence: a positional scheme that obstructs the fastest available kernel tends not to get adopted.

Learned table versus computed rotation

Figure 3. Learned table versus computed rotation.

Stretching a model to longer texts

RoPE opens a practical door, and it is the reason headlines keep appearing about models that support a context of hundreds of thousands of words. A model trained on short texts can be pushed to read much longer ones by adjusting the dials rather than retraining from scratch. The intuition is spatial: compress the new positions so far-apart words appear closer together, back inside the range of angles the model already understands, or rescale the turning speeds selectively, leaving the fast local dials sharp while stretching only the slow long-range ones. With a small amount of extra training, and occasionally none, a model built for modest lengths reads very long documents. It amounts to re-spacing the seats so an oversized room presents the angles of the familiar one, and it is much of the machinery behind the context windows that keep growing.

The rescaling is a trade, and it is worth naming as one. Compress every dial equally and neighbouring tokens become harder to tell apart, because the fine dials now turn through smaller arcs between adjacent words — which is exactly why the schemes that work rescale selectively, stretching the slow dials and leaving the fast ones alone. Reach is bought from local resolution, and the craft is in choosing where to spend it. Nor does RoPE extrapolate unaided. Run a model past its trained lengths without rescaling and quality falls away, which is the finding the article on positional encoding reports for every scheme in use, RoPE included. What the rescaling buys is a window, not the ability to use it. The dilution of attention across a longer context and the linear growth of the KV cache are untouched by anything done to the dials, and the article on long context treats both. Position is one constraint of several, and the only one rotation addresses.

What to carry forward

Attention is blind to word order, so order must be supplied, and language nearly always cares about relative position rather than absolute seat numbers. RoPE meets both facts with one move: it rotates each word’s vector by an angle proportional to its position, and because the comparison between two rotated words depends only on the difference of their rotations, what emerges is relative distance. Splitting the vector into many pairs and spinning each at its own speed supplies a multi-scale sense of near and far at once, and because the whole thing is a computed function of position rather than a stored table it neither runs out at new lengths nor costs much to use, and it acts early enough to leave the fused kernels alone. It displaced the earlier schemes on those properties rather than on accuracy. What it does not supply is extrapolation. Past the trained lengths the dials must be rescaled, and rescaling buys reach out of local resolution unless it is done selectively. Position was also only ever one of the constraints: attention still dilutes across a long window, and the cache still grows with every token. Rotation does not touch either.


The figures in this article follow the shared figure key , which explains what every shape, line style and colour means.