What is positional encoding?

Positional encoding is the method that tells a Transformer the order of each token in a sequence, or the relative distance between tokens, so the attention mechanism can use order information.

It is also called positional embedding. It is needed because unmasked self-attention does not see order by itself: without position, “the bank called the customer” and “the customer called the bank” look like the same set of tokens. Rotary Position Embedding and Attention with Linear Biases are specific methods of this general idea.

Topic
Machine learning, models and training
Also known as
Positional embedding, position encoding
Origin
2017, Vaswani et al., sinusoidal positional encoding

How positional encoding works

  1. Absolute methods produce a vector per position and add it to the token embedding; the vector can be computed with sine and cosine functions or learned in training.
  2. Relative methods bring position into attention as the distance between tokens.
  3. RoPE rotates query and key vectors by position, making the attention score between two tokens depend on their relative distance.
  4. The encoding type shapes how a model behaves on sequences longer than those seen in training.

In more detail

Hybrid RoPE and NoPE layers and multi-dimensional position

Recent architectures take positional encoding beyond one-dimensional text: some interleave RoPE layers with layers that use no positional encoding (NoPE) to balance local precision with long-range recall. Multimodal models use multi-dimensional M-RoPE, encoding height, width and time separately for images and video.

Commonly confused terms

TermHow it differs
Positional embeddingPositional encoding generally refers to deterministic functions or geometric operations (sinusoidal waves, RoPE rotations, ALiBi slopes) injecting position, whereas positional embedding typically denotes learned position lookup vectors added to token embeddings.
Token embeddingToken embeddings map vocabulary IDs to semantic vectors independent of sequence order, whereas positional encoding injects sequence index or relative distance so attention distinguishes identical tokens at different positions.

Why positional encoding matters for on-premises AI

Company documents are long and the context window is often the limit in in-house use. Whether a model can safely stretch its context window beyond its training length depends largely on positional encoding; models using RoPE can be adapted to longer inputs with context extension techniques. Model choice should check measured long-document performance, not just advertised context length.

ON-PREMISES EXAMPLE

A law firm picks a long-context model to review contracts of hundreds of pages in one pass, first testing with its own documents how accurately the model finds a clause near the end.

Common questions

Why is positional encoding needed?

The attention mechanism treats tokens as an unordered set. Without position the model cannot see differences in meaning that come from word order.

How does RoPE differ from classic positional encoding?

Classic methods add a position vector to the token embedding. RoPE brings position into attention by rotating query and key vectors, representing relative distance naturally and adapting more easily to long context.

Sources

In the glossary: Glossary, M to Q

What does this term mean for your infrastructure?

We can work out together in a technical assessment how it maps onto your data, hardware and security requirements.

Request a technical assessment →

This site sets no cookies. Visitor numbers are counted in aggregate using a cookieless method that does not identify anyone. See the Privacy Policy for details.