Match each positional encoding scheme to where it enters the architecture
Sinusoidal and learned-absolute PE enter once at the input embedding; RoPE rotates Q/K inside every attention layer; ALiBi and T5 relative bias add directly to pre-softmax attention scores in every layer.
Transformers don't know token order on their own; attention treats words like a bag, not a list. So you inject position information somewhere, and the choice of *where* matters as much as the choice of *what*. The old way (Vaswani 2017, BERT) was to stamp position numbers onto each word at the entry door, then never mention position again. Modern models (Llama, Mistral) rotate the query and key vectors inside every attention room by a position-dependent amount: fresher position info at every layer. ALiBi and T5 take a third route: don't touch the words at all, just add a 'how far apart are these two tokens' penalty to every attention score directly.
Detailed answer & concept explanation~6 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
3 min: name the three injection points, place each scheme, mention that modern LLMs converged on RoPE (per-layer Q/K).
| Scheme | Injection point | Per-layer or once | Length extrapolation |
|---|---|---|---|
| Sinusoidal PE | Token embedding (input) | Once | Poor in practice |
| Learned absolute | Token embedding (input) | Once | Hard cap at max_position |
| RoPE | Q and K vectors (per layer) | Every layer | Excellent with PI/YaRN |
| ALiBi | Pre-softmax attention score | Every layer | Excellent (built-in) |
| T5 relative bias | Pre-softmax attention score | Every layer | Good (logarithmic buckets) |
Real products, models, and research that use this idea.
- Llama 3.1 8B/70B/405B and Llama 4 Maverick/Scout all use RoPE with `base=500000` (Llama 3+) and YaRN scaling for long context: per-layer Q/K injection.
- BERT-base (2018) used learned absolute PE with `max_position = 512`: hard cap, no extrapolation; ModernBERT (2024) switched to RoPE for the same reason every other modern model did.
- BLOOM (2022) and MPT-7B (2023) used ALiBi for length extrapolation; both showed that per-head linear distance bias works well past training length.
- T5 (2020) used relative position bias as a learned scalar table per head: score-side injection but a discrete bucket lookup rather than a continuous formula.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy does RoPE extrapolate better than learned absolute PE?
QCan you combine RoPE with ALiBi in the same model?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Thinking RoPE adds to the input embedding (it doesn't; it rotates Q and K inside attention), or thinking ALiBi modifies the token vectors (it doesn't; it biases the attention scores directly).
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.