---
title: Self-attention is permutation-equivariant, so how does a transformer know token order? Compare sinusoidal, learned…
url: https://gurkanozkan.ai/learn/questions/research-positional-information-long-context-036/
markdown: https://gurkanozkan.ai/learn/questions/research-positional-information-long-context-036.md
kind: question
role: Research
stage: Technical
difficulty: Medium
json: https://gurkanozkan.ai/api/learn/questions/research-positional-information-long-context-036.json
robots: noindex
---

# Self-attention is permutation-equivariant, so how does a transformer know token order? Compare sinusoidal, learned absolute and rotary embeddings, and discuss extending context beyond the training length.

Research · Technical · Medium

## Answer

*Model answer, written in a candidate's voice*

### In short

- Self-attention without position signals is order-blind; causal masks help but do not encode absolute position.
- Sinusoidal embeddings use fixed frequencies and are not hard-capped, but extrapolate poorly beyond training length.
- Learned absolute embeddings are simple and strong in-distribution, but are tied to the trained maximum length.
- RoPE rotates q and k so scores depend on relative offset, but plain RoPE still degrades past the trained length; ALiBi instead biases attention by distance.
- Beyond training length: position interpolation, NTK/YaRN-style RoPE scaling, and long-sequence fine-tuning.
- Judge long context with retrieval-style tests, not only perplexity.

### In full

The core point is that attention itself is permutation-equivariant, so token order must be injected explicitly; a causal mask gives direction but not absolute position. Sinusoidal embeddings use fixed frequencies and can be computed for longer sequences, but they often degrade outside the training range. Learned absolute embeddings are easy and effective in-distribution, but they are capped at the trained maximum length and cannot simply be extended. RoPE rotates q and k so the dot product depends on relative offset, which gives a useful relative-position bias, although plain RoPE still degrades beyond the trained length; ALiBi is another option that adds a distance-based bias instead of positional vectors and was designed to extrapolate to longer inputs. To extend context, common approaches are position interpolation, NTK/YaRN-style scaling of RoPE frequencies, and long-sequence fine-tuning, though none guarantees reliable extrapolation. I would evaluate with retrieval-style tests such as needle-in-a-haystack, passkey, and long-context QA, because perplexity alone can look good while exact recall fails.

*Corrected by an independent AI reviewer.*

## What a strong answer covers

- Without position signals, attention ignores order.
- Sinusoidal: fixed frequencies. Learned absolute: capped at the trained length.
- RoPE rotates q and k so their dot product depends on relative offset. ALiBi is another option.
- Extension methods: position interpolation, NTK/YaRN scaling, long-sequence fine-tuning.
- Evaluate long context with retrieval-style tests.

## Common mistakes

- Ignoring extrapolation failure.
- Saying the causal mask alone fully encodes position without caveats.

## Topic guides

- [Transformers, attention and scaling](https://gurkanozkan.ai/learn/topics/transformers.md)
---

*Study material compiled with AI: drafted by a local model (Inkling 2 Mini) from public sources, then checked against those sources by independent AI reviewers (Claude) in November 2026. Not reviewed line by line by a person.*
