IT Essentials

Understanding Positional Embeddings in Modern LLMs: From Adding Positions to Rotating Them

How LLMs represent token order and distance, from GPT-2-style absolute position embeddings to the rotations of RoPE — and why a causal mask alone is not enough.

A model has to be told about order

A transformer receives a sentence as a sequence of tokens, but the attention computation itself has no notion of where a token sits. The same word carries different meaning depending on whether it comes early or late and how far it is from other words, so position has to be supplied separately. A piece summarized on GeekNews, “현대 LLM의 위치 임베딩 이해하기,” lays out three approaches to that problem.

It is tempting to assume the causal mask handles order. The mask stops a token from attending to later tokens, which encodes implicit order, but it does not tell the model the distance between two tokens. An explicit mechanism is still needed.

Adding absolute positions

GPT-2 adds a learned position vector to the input embedding. The original Transformer added fixed sine and cosine vectors that were never learned. Learned or not, both express absolute position — which slot in the sentence a token occupies.

RoPE: rotating instead of adding

RoPE (Rotary Position Embedding) rotates queries and keys inside attention rather than adding anything to the input. The dot product of a query and a key is the core operation for scoring how related two tokens are, and rotation makes relative position show up in that dot product. The key property: if the pre-rotation vectors are fixed, shifting both tokens by the same distance leaves the dot product unchanged. Position is conveyed by turning rather than adding. According to the piece, recent architectures use variants that rotate only some of the dimensions.

What stays open

Positional encoding is a design decision about how a model tells order apart, and it is a concept you keep meeting when reading architecture descriptions. The summary does not settle how much absolute and relative schemes differ on real tasks, or what benefit partial rotation brings. How positional encoding behaves at very long input lengths is outside the scope of the piece and worth checking separately.

Sources

Drafted by AI from the original sources and reviewed by an editor before publishing. Check the sources for the authoritative details.

#LLM #RoPE #Transformer #Positional Encoding

← IT essentials