← Amazon Interview Insights

Amazon·Software Engineer·Technical Phone Screen·Senior

Senior
Jul 2026

Summary

Amazon Research Engineer technical screen, heavy on transformer internals. Felt like a graduate seminar more than a job interview, which I was not fully prepared for.

Questions Asked (5)

Q1

Walk me through the scaled dot-product attention formula, including why you divide by the square root of the key dimension.

Technical Trade-offsAlgorithms & Data Structures
Author's notes

I knew the formula cold but fumbled the intuition behind the scaling.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by writing the formula Attention(Q, K, V) = softmax(QK^T / sqrt(d_k)) V, then explain each component and the purpose of the scaling factor. Emphasize that dividing by sqrt(d_k) prevents the dot products from growing too large, which would push the softmax into regions with tiny gradients and hinder learning.

Pro tip: Mention that the scaling factor is derived from the variance of the dot product assuming independent components with zero mean and unit variance, and that without it, the softmax saturates, leading to vanishing gradients. This shows you understand the mathematical reasoning, not just the formula.

1. State the formula

Write the scaled dot-product attention equation clearly: Attention(Q, K, V) = softmax(QK^T / sqrt(d_k)) V. Define Q, K, V as queries, keys, and values, and d_k as the dimension of the keys.

2. Explain the dot product and softmax

Describe how QK^T computes similarity scores between queries and keys, and softmax converts these scores into a probability distribution over the values.

3. Introduce the scaling factor

Explain that dividing by sqrt(d_k) scales the dot products to have unit variance, preventing them from becoming too large in magnitude as d_k grows.

4. Discuss the consequences of no scaling

Without scaling, large dot products push the softmax into regions where gradients are extremely small, causing vanishing gradients and slow or unstable training.

5. Summarize the benefit

Conclude that scaling stabilizes training and improves gradient flow, which is crucial for deep models like Transformers.

Key Points to Mention

  • The formula: Attention(Q, K, V) = softmax(QK^T / sqrt(d_k)) V
  • Q, K, V represent queries, keys, and values; d_k is the key dimension
  • Dot product QK^T measures similarity between queries and keys
  • Softmax normalizes scores into attention weights
  • Scaling by sqrt(d_k) prevents large dot products that cause softmax saturation
  • Without scaling, gradients vanish, leading to poor training

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

How does multi-head attention work and what does it gain over single-head attention?

Technical Trade-offsSystem Design
Author's notes

This went better.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by explaining the mechanics of multi-head attention: how queries, keys, and values are linearly projected into multiple subspaces, attention is computed in parallel, and outputs are concatenated and projected. Then contrast with single-head attention, emphasizing the representational and practical benefits such as capturing diverse relationships and improving training stability. Finally, tie it to real-world impact like performance gains in models such as BERT and GPT.

Pro tip: Mention that multi-head attention increases model capacity without significantly increasing computational cost because each head operates on a lower-dimensional projection (d_model/h), making it a favorable trade-off. This shows you understand both the theoretical and practical engineering considerations.

1. Define the core mechanism

Explain that multi-head attention runs several attention operations in parallel, each with its own learned linear projections of queries, keys, and values.

2. Describe the computation flow

Detail how each head computes scaled dot-product attention independently, then outputs are concatenated and passed through a final linear projection.

3. Contrast with single-head attention

Highlight that single-head attention uses one set of projections, limiting it to a single representation subspace and reducing its ability to capture diverse patterns.

4. Explain the gains

Discuss benefits: ability to attend to different positions and represent multiple relationship types simultaneously, improved model expressiveness, and better training dynamics.

5. Connect to practical impact

Mention how this design has enabled state-of-the-art results in NLP and beyond, and note the efficiency trade-off (same total dimension, so cost is comparable).

Key Points to Mention

  • Parallel attention heads with independent linear projections
  • Concatenation of head outputs followed by a final linear layer
  • Ability to capture diverse linguistic and semantic relationships
  • Increased representational capacity without proportional compute increase
  • Improved training stability and convergence
  • Real-world success in Transformer-based models (e.g., BERT, GPT)

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

Describe the encoder-decoder transformer architecture: what each side is responsible for and how the decoder uses cross-attention over encoder outputs.

System DesignTechnical Trade-offs
Author's notes

Spent too long on the encoder and had to rush the decoder explanation.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining the encoder-decoder architecture at a high level, then break down the responsibilities of each component. Explain how cross-attention enables the decoder to leverage encoder outputs, and connect this to practical implications like training efficiency and inference trade-offs.

Pro tip: Relate the architecture to real-world systems (e.g., machine translation, Amazon's Alexa) and discuss trade-offs like latency vs. quality, showing you understand both theory and application.

1. Define the overall architecture

Briefly describe the encoder-decoder transformer as a sequence-to-sequence model with two main stacks: encoder and decoder.

2. Explain the encoder's role

Detail how the encoder processes the input sequence through self-attention and feed-forward layers to produce contextualized representations.

3. Explain the decoder's role

Describe how the decoder generates the output sequence autoregressively, using masked self-attention and cross-attention.

4. Detail cross-attention mechanism

Explain that in cross-attention, queries come from the decoder, while keys and values come from the encoder's output, allowing the decoder to focus on relevant input parts.

5. Discuss implications and trade-offs

Mention how this design impacts training (parallelization) and inference (sequential decoding), and any trade-offs like computational cost.

Key Points to Mention

  • Encoder uses self-attention to build bidirectional context; decoder uses masked self-attention for autoregressive generation.
  • Cross-attention allows the decoder to attend to all encoder positions, enabling effective conditioning on the input.
  • The encoder's output is a sequence of vectors, each representing a token with context from the entire input.
  • Decoder generates one token at a time, using previously generated tokens and cross-attention to the encoder.
  • Training can be parallelized over output tokens due to teacher forcing, but inference is sequential.
  • This architecture is foundational for tasks like machine translation, summarization, and speech recognition.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q4

When would you choose an encoder-only model versus a decoder-only model versus a full encoder-decoder model?

Technical Trade-offsProduct Sense & Ideation
Author's notes

Pretty comfortable here.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining the core architectural differences and their implications for task types, then map each architecture to specific use cases and trade-offs. Emphasize that the choice depends on the task requirements, data availability, and constraints like latency and compute. Conclude with a decision framework that ties back to business impact and engineering practicality.

Pro tip: Frame your answer around the bias-variance trade-off and the 'no free lunch' theorem: encoder-only models excel at understanding, decoder-only at generation, and encoder-decoder at sequence-to-sequence tasks. Mention that at Amazon, customer obsession means choosing the simplest model that solves the problem while optimizing for cost and latency.

1. Clarify the task

Identify whether the problem is discriminative (classification, extraction), generative (text completion, chat), or sequence-to-sequence (translation, summarization). This determines the suitable architecture.

2. Compare architectural strengths

Explain that encoder-only models (e.g., BERT) use bidirectional attention for rich contextual understanding, decoder-only models (e.g., GPT) use causal attention for autoregressive generation, and encoder-decoder models (e.g., T5) combine both for tasks requiring input understanding and output generation.

3. Evaluate trade-offs

Discuss trade-offs in compute, latency, memory, and data efficiency. Encoder-only is efficient for understanding tasks; decoder-only scales well for generation but may be less sample-efficient for structured outputs; encoder-decoder is versatile but heavier.

4. Consider constraints and business goals

Factor in production constraints like inference cost, latency requirements, and available training data. At Amazon, align with customer needs and operational excellence—choose the model that delivers the best customer experience within budget.

5. Provide a recommendation with examples

Give concrete examples: encoder-only for sentiment analysis or named entity recognition; decoder-only for chatbots or code generation; encoder-decoder for translation or summarization. State when you would deviate based on empirical results.

Key Points to Mention

  • Encoder-only models (e.g., BERT) are best for tasks requiring deep bidirectional context understanding, such as classification, sentiment analysis, and extractive QA.
  • Decoder-only models (e.g., GPT) excel at open-ended generation, few-shot learning, and tasks where the output is a continuation of the input, like chatbots and code completion.
  • Encoder-decoder models (e.g., T5, BART) are ideal for sequence-to-sequence tasks where input and output are distinct, such as translation, summarization, and generative QA.
  • Trade-offs include inference latency, compute cost, model size, and the amount of labeled data needed; encoder-only often requires less data for fine-tuning on understanding tasks.
  • Consider the 'no free lunch' theorem: no single architecture is best for all tasks; empirical evaluation is key.
  • At Amazon, tie the choice to customer obsession and operational excellence—choose the simplest model that meets customer needs and scales efficiently.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q5

Explain padding masks and causal masks in transformers: what each one does and why both are necessary.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Causal masking I nailed.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Define each mask separately, explaining their purpose and mechanism, then contrast why both are needed in transformer architectures. Use a concrete example like a batch of padded sequences to illustrate how each mask affects attention.

Pro tip: Mention that padding masks are data-dependent (based on sequence lengths) while causal masks are structural (always lower triangular), and note that they can be combined by addition or multiplication before the softmax.

1. Define padding masks

Explain that padding masks prevent attention from attending to padding tokens, which are added to make sequences in a batch the same length. They are binary masks where 1 indicates a real token and 0 indicates padding.

2. Define causal masks

Explain that causal masks (also called look-ahead masks) prevent attention to future tokens in autoregressive models like GPT. They are lower triangular matrices ensuring position i can only attend to positions ≤ i.

3. Explain why both are necessary

Padding masks are needed for batch processing with variable-length sequences to avoid attending to meaningless padding. Causal masks are needed for autoregressive generation to maintain the auto-regressive property. They address different problems and are often used together.

4. Describe implementation

Mention that masks are applied by adding a large negative value (e.g., -1e9) to attention scores before softmax, effectively zeroing out attention weights for masked positions. Padding and causal masks can be combined via element-wise multiplication or addition.

5. Provide an example

Illustrate with a batch of two sequences of different lengths, showing how padding mask zeros out padding tokens, and how causal mask ensures each token only attends to previous tokens.

Key Points to Mention

  • Padding masks handle variable-length sequences in a batch by masking out padding tokens.
  • Causal masks enforce autoregressive property by preventing attention to future tokens.
  • Both masks are applied to attention scores before softmax, typically by adding a large negative value.
  • Padding masks are data-dependent; causal masks are structural and fixed.
  • They can be combined when both are needed, e.g., in decoder self-attention with padded sequences.
  • Without padding masks, the model would attend to padding, harming performance; without causal masks, the model would cheat by seeing future tokens.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.