What is the difference between absolute and relative positional encodings?

Last updated 22 November 2026

  • Absolute encodings tag each token with its own index once at the input. The model must infer distance indirectly, and this extrapolates poorly beyond training length.

  • Relative encodings make attention depend on the offset i - j inside every layer. Examples: Shaw et al. embeddings, T5 bias buckets, ALiBi linear penalty, and RoPE rotations.

  • Relative schemes give translation invariance, better length generalization and fit KV caching. Some variants cost extra compute or break fused attention kernels.

  • https://ml-digest.com/absolute-vs-relative-position-embeddings/
  • https://arunprakash-a.github.io/2024/02/02/PositionalEncodings.html
  • https://www.newline.co/@zaoyang/relative-vs-absolute-positional-embedding-in-decoders--bcbe7df9
All Transformers interview questions