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
Machine Learning
Machine Learning Engineer
Amazon
November 29, 2026
Machine Learning Engineer
Technical Screen
Machine Learning
Medium

0

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
Transformers
Self-attention
Positional encoding
Rotary embeddings
Context length
How to Approach This
  1. Understand the bias-variance trade-off. High training accuracy but low test accuracy signals overfitting.
  2. Choose evaluation metrics carefully based on the problem. Accuracy alone is often insufficient.
  3. Feature engineering is often more impactful than model selection.
  4. Know when to use tree-based models (tabular data) vs neural networks (unstructured data).
  5. 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 Prep
Sample 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 softmax(QK⊤/d)V\text{softmax}(QK^\top/\sqrt d)V 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_{(...


Submit Your Answer
Markdown supported