← Microsoft Interview Insights
I knew the broad strokes but fumbled explaining masked self-attention clearly.
Start by defining the encoder and decoder roles in the transformer, then contrast their architectural components and information flow. Highlight how the decoder's self-attention is masked and includes cross-attention to the encoder, and explain the implications for training and inference.
Pro tip: Emphasize that the decoder's masked self-attention enables autoregressive generation, which is crucial for tasks like machine translation and text generation, and mention how this affects parallelization and latency in production systems.
Explain that the encoder processes the input sequence bidirectionally to create contextual representations, while the decoder generates the output sequence autoregressively.
Describe that the encoder uses unmasked self-attention, whereas the decoder uses masked self-attention to prevent attending to future tokens, and also includes cross-attention over the encoder's output.
Note that each decoder layer has three sub-layers (masked self-attention, cross-attention, feed-forward) versus the encoder's two (self-attention, feed-forward), and that both use residual connections and layer normalization.
Mention that the encoder can process all input tokens in parallel, while the decoder must generate tokens sequentially during inference, though teacher forcing allows parallel training.
Connect these differences to practical considerations like latency, throughput, and memory usage in deployment, especially for real-time applications.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.