Explain Positional Encodings and Rotary Embeddings in Transformers
Last updated: November 29, 2026
Quick Overview
Self-attention is permutation invariant. Explain why transformers need positional information, compare sinusoidal, learned and rotary position embeddings, and discuss what matters when extending context length.
Amazon
November 29, 20260
0
0 solved
Self-attention is permutation invariant. Explain why transformers need positional information, compare sinusoidal, learned and rotary position embeddings, and discuss what matters when extending context length.
Amazon's LLM teams increasingly need longer contexts, for example for long documents in enterprise assistants or many reviews in a summary. A technical screen uses this to confirm the candidate understands the mechanics of attention, not just its API.
What the Interviewer Expects
- Show attention is permutation invariant without positions
- Describe absolute sinusoidal and learned embeddings
- Explain RoPE as rotating query and key pairs
- Show RoPE makes scores depend on relative position
- Discuss context extension issues
Key Topics to Cover
How to Approach This
- Understand the bias-variance trade-off. High training accuracy but low test accuracy signals overfitting.
- Choose evaluation metrics carefully based on the problem. Accuracy alone is often insufficient.
- Feature engineering is often more impactful than model selection.
- Know when to use tree-based models (tabular data) vs neural networks (unstructured data).
- Handle class imbalance with SMOTE, class weights, or appropriate loss functions.
Possible Follow-up Questions
- Why do learned absolute embeddings fail beyond the trained length?
- What does position interpolation do for RoPE?
- How does ALiBi differ from RoPE?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Explore ML Interview PrepSample Answer
Clarify
Clarify whether we discuss encoder or decoder models; both need positions, though causal masking provides weak implicit order. Context: extending a model trained on 4k tokens to 32k....
Approach
Attention treats inputs as a set: permuting tokens permutes outputs the same way, so 'dog bites man' equals 'man bites dog'. Fixes: (1) add sinusoidal vectors $PE_{(...