Explain attention and Transformers

Quick Overview

Explain attention and Transformers evaluates core ML concepts, assumptions, math intuition, training/evaluation trade-offs, and practical failure modes in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.

Explain attention and Transformers

Company: Amazon

Role: Software Engineer

Category: Machine Learning

Difficulty: hard

Interview Round: Technical Screen

Derive the scaled dot-product self-attention: define Q, K, V, the scaling factor, masking, and softmax; discuss complexity. Explain the Transformer encoder/decoder architecture, residual connections, normalization strategy, and positional encoding. Compare BERT and GPT pretraining objectives, architectures, and typical downstream usage; discuss how these choices affect transfer and inference.

Overview: Explain attention and Transformers evaluates core ML concepts, assumptions, math intuition, training/evaluation trade-offs, and practical failure modes in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.

|Home/Machine Learning/Amazon
Amazon logo
Amazon
Jul 15, 2025
hardSoftware EngineerTechnical ScreenMachine Learning
10
0

Explain attention and Transformers

Scaled Dot-Product Self-Attention, Transformer Architecture, and BERT vs GPT

You are interviewing for a software engineer role focused on machine learning. Explain the core math and design choices behind Transformers and how they translate to practical trade-offs in transfer learning and inference.

1) Scaled Dot-Product Self-Attention

Derive and define the following:

  • Queries (Q), Keys (K), Values (V) and how they are computed from inputs
  • The scaling factor and why it is needed
  • Masking (padding and causal)
  • Softmax over attention logits
  • Time and memory complexity (including multi-head and autoregressive decoding)

2) Transformer Architecture

Explain the encoder–decoder Transformer architecture, including:

  • Encoder vs decoder stacks and their sublayers
  • Residual connections and the normalization strategy (pre-norm vs post-norm)
  • Positional encoding (sinusoidal and alternatives)

3) BERT vs GPT

Compare BERT and GPT in terms of:

  • Pretraining objectives
  • Architectural differences
  • Typical downstream usage
  • How these choices affect transfer learning and inference behavior/performance

Clarifying Questions to Ask Guidance

  • Clarify the task, data shape, labels, constraints, and evaluation metric.
  • State assumptions behind the math or modeling technique you choose.
  • Connect theory to practical training, debugging, and deployment implications.

What a Strong Answer Covers Guidance

  • Correct definitions and formulas where the prompt requires them.
  • A practical explanation of how the method behaves on real data.
  • Trade-offs, failure modes, diagnostics, and mitigation strategies.
  • Evaluation choices that match the product or modeling objective.

Follow-up Questions Guidance

  • How would noisy labels, class imbalance, or distribution shift affect the answer?
  • What would you monitor after deployment?
  • Which baseline would you compare against first?
Loading comments...