Home Knowledge Base Positional Encodings in Transformers

Positional Encodings in Transformers are the mechanisms that inject sequence order information into the attention mechanism — which is inherently permutation-invariant — enabling the model to distinguish between tokens at different positions and generalize to sequence lengths beyond those seen during training, with modern approaches like RoPE and ALiBi replacing the original sinusoidal encodings.

Why Position Information Is Needed

Self-attention computes Q·Kᵀ between all token pairs — the operation treats the token sequence as an unordered set. Without positional information, the sentences "dog bites man" and "man bites dog" produce identical attention patterns. Positional encodings break this symmetry.

Encoding Methods

Context Length Extension

RoPE-based models can extend their context window beyond training length through:

Positional Encodings are the hidden mechanism that gives transformers their sense of order and distance — a seemingly minor architectural detail whose choice directly determines whether a language model can handle 4K or 1M+ token contexts.

positional encoding transformerrotary position embeddingrelative positionsinusoidal positionrope alibi position

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.