Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Learned PE: trainable per position embeddings; flexible and often slightly better in distribution; HARD CAP at max training position.
Imagine a theater that prints custom seat covers for every seat, row 1 seat A gets one design, row 1 seat B gets another, all the way through row 100. The theater learned which covers belong on which seats by trial and error. Now compare that to a different theater that uses a mathematical formula to color every seat, given a row and seat number, the formula spits out a color pattern, even for seats that haven't been built yet. The first theater (learned positional encoding) makes seats feel exactly right when you're inside the building it was trained on, but if you walk into row 101, there's no cover for that seat. The second theater (sinusoidal) has a cover for any seat number you can name, though the patterns aren't quite as snug for the seats it's actually seen.
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.
Walk the parametric vs nonparametric framing, give the hard cap on learned PE consequence (BERT's 512-token limit), note sinusoidal's weak in practice generalization, and explain why RoPE supersedes both.
| Property | Learned PE | Sinusoidal PE | RoPE |
|---|---|---|---|
| Trainable parameters | max_position × d_model | None | None |
| Defined at any position? | No (hard cap) | Yes (formula) | Yes (but angles cycle) |
| Bounded values? | Usually (no guarantee) | Yes (-1, 1) | Q, K norms unchanged |
| Structural smoothness | None (each vector independent) | Strong (sin/cos) | Strong (rotation) |
| In distribution fit | Often slightly best | Slightly weaker | Matches or beats both |
| Length extension | Requires retraining/interp | Weak generalization | PI / YaRN |
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.
Confusing 'fewer FLOPs' or 'numerical stability' with the actual tradeoff, the real distinction is parametric vs nonparametric, with the consequent hard cap on learned PE.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.