Explain Self-Attention and Why Transformers Displaced Recurrent Networks

Last updated: November 29, 2026

Quick Overview

Explain how scaled dot-product self-attention works, why the scaling factor exists, and why transformers replaced RNNs and LSTMs for most language tasks, including the costs they introduced.

Microsoft
Machine Learning
Machine Learning Engineer
Microsoft
November 29, 2026
Machine Learning Engineer
Technical Screen
Machine Learning
Medium

0

0

0 solved


Explain how scaled dot-product self-attention works, why the scaling factor exists, and why transformers replaced RNNs and LSTMs for most language tasks, including the costs they introduced.

Microsoft ML screens for Azure AI, Bing, and Copilot teams routinely include a fundamentals question on transformers because those teams fine-tune and serve them daily. The interviewer is checking that you can derive attention, explain the softmax scaling, and reason about the quadratic cost and how serving systems work around it.

What the Interviewer Expects
  • Writes the attention formula with queries, keys, and values and explains each
  • Justifies dividing by the square root of the key dimension using variance
  • Explains multi-head attention and positional information
  • Contrasts parallelism and long-range dependency handling with RNNs
  • States the O(n^2) memory and compute cost in sequence length and known mitigations
  • Mentions causal masking and the KV cache for generation
Key Topics to Cover
Self-attention
Transformers
Positional encoding
KV cache
Computational complexity
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 does generation with a KV cache make each new token cost O(n) rather than O(n^2)?
  • What do rotary position embeddings do differently from learned absolute positions?
  • How do FlashAttention or sparse attention reduce cost, and what do they trade?
  • When might a recurrent or state space model still be preferable?
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

I will cover single-head attention, the scaling factor, multi-head attention, positions, why it beat RNNs, and the cost profile, focusing on decoder-style models since that is what most products serve...

Approach

Each token embedding xix_i is projected to a query qi=xiWQq_i = x_i W_Q, key ki=xiWKk_i = x_i W_K, and value vi=xiWVv_i = x_i W_V. A token's output is a weighted average of all values, where the weights reflect how ...


Submit Your Answer
Markdown supported