Skip to content
Technology, explained from the insideAI · Software · Digital payments
TayoTechTalk.

How AI Works

RoPE Explained: How Transformers Know Where Words Are

By Temitayo Solomon Gbadebo · December 2, 2026
Three ivory discs on a burgundy track, each with its dark pointer turned to a different angle.

“Amina paid Tunde” and “Tunde paid Amina” contain the same words. It would still be a serious mistake to record them as the same payment. The words say who is involved; their order tells us who paid whom.

A transformer needs a way to represent that order when it compares pieces of text. One widely used technique is rotary position embedding, usually shortened to RoPE. Its trick is to give each position a rotation so that comparing two positions reveals the gap between them.

What a position signal adds

Language models break text into tokens, which can be words, pieces of words or other units. A token’s position is its index in that sequence. That index is different from the token’s identity: the same token can appear at the start of one sentence and near the end of another.

Think about an attention score as one token asking, “How relevant is that token to me?” A comparison based only on the two tokens’ content would have no explicit way to distinguish an immediate neighbour from something twenty positions away. In a text-generating model, a causal mask can restrict which positions may look at which earlier positions. That restriction plays a different role from explicitly putting a position signal into the comparisons that are allowed.

The original Transformer paper used sine and cosine values to create a positional vector, which it added to the input embedding. That was one way to give position to the model. RoPE, introduced in the RoFormer paper, puts the signal into attention differently.

How a rotation reveals the gap

Attention computes a query vector for the token doing the looking and a key vector for a token it can look at. A vector is a list of numbers. You can picture a pair of those numbers as an arrow on a flat surface. RoPE rotates pairs of numbers in the query and key using their respective token positions.

For a toy example, imagine both arrows start pointing to the right and the rotation is 15 degrees per position. At positions 2 and 5, the arrows turn to 30 and 75 degrees. Their difference is 45 degrees. Move the same pair to positions 12 and 15: both arrows rotate further, but the difference is still 45 degrees. The signed position gap is the same. These angles illustrate the idea; they are not a model setting.

The actual attention comparison, a dot product, measures how the two vectors line up. If you keep their pre-rotation content fixed, rotating them both by the same extra angle leaves that comparison unchanged. So the positional part of the comparison depends on how far apart the two indices are, and in which direction, rather than where the pair begins. A real model rotates many pairs at different rates, instead of trying to represent every offset with a single arrow pair.

At positions 2 and 5 the arrows sit at 30 and 75 degrees; at positions 12 and 15 they sit at 180 and 225 degrees. Both differences are 45 degrees.
In this toy example, shifting both positions changes the individual angles but keeps the angle difference at 45 degrees.

What this does not tell the model

A relative offset says something about where two tokens sit. It does not tell the model what their relationship means. The model still learns which words tend to describe a nearby name, when a pronoun points back to a distant person or which part of a sentence states an exception.

Nor does shifting two words guarantee that the model will produce the same response. The little arrow example holds their content vectors fixed. In a real prompt, adding a paragraph or moving a sentence can change surrounding tokens, which earlier text each token can attend to, and the vectors themselves. The mathematical property concerns the rotation inside a particular comparison, not the model’s entire behaviour.

Why a longer sequence still needs testing

A rotation formula can produce angles for positions a model did not see during training. That alone does not mean the model works well at those positions. In research on positional interpolation, the authors extended RoPE-based models by scaling position indices back into a range closer to what the models had been trained to handle and then fine-tuning them. The result is evidence for a specific technique, not a guarantee that any model’s limits can be changed with one setting.

If you are testing a document assistant, put a relevant policy exception near the start of one test document and much farther from the question in another. Hold the rule and question constant, label the expected answer, and track whether the system cites the correct passage. This tests whether the full system uses the information reliably. It does not isolate RoPE, since the rest of the model and application also matter.

RoPE gives attention a way to represent position through rotation. The model can use that signal alongside the token content it already has, but it still has to learn what the ordering and distance mean for the task.