Match each positional encoding scheme to where it enters the architecture
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
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.
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.
What an interviewer would ask next. Try answering before peeking at the approach.
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.