LLM & Transformer Fundamentals·Question 107 of 109Quick-fire

Discuss the role of cross-attention in transformer-based encoder-decoder models. How does it facilitate the generation of output sequences based on information from the input sequence?

Quick-fire answer from the Awesome Generative AI Guide (MIT)

Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.

Model answer: the part to lead with

Cross-attention is a mechanism in transformer-based encoder-decoder models that allows the decoder to focus on different parts of the input sequence as it generates each token of the output sequence. It plays a crucial role in tasks such as machine translation, summarization, and question answering, where the output depends directly on the input content.

Full worked answer

Cross-attention is a mechanism in transformer-based encoder-decoder models that allows the decoder to focus on different parts of the input sequence as it generates each token of the output sequence. It plays a crucial role in tasks such as machine translation, summarization, and question answering, where the output depends directly on the input content.

During the decoding phase, for each output token being generated, the cross-attention mechanism queries the encoder's output representations with the current state of the decoder. This process enables the decoder to "attend" to the most relevant parts of the input sequence, extracting the necessary information to generate the next token in the output sequence. Cross-attention thus facilitates a dynamic, content-aware generation process where the focus shifts across different input elements based on their relevance to the current decoding step.

This ability to selectively draw information from the input sequence ensures that the generated output is contextually aligned with the input, enhancing the coherence, accuracy, and relevance of the generated text.

What a good answer covers

  • Cross-attention is a mechanism in transformer-based encoder-decoder models that allows the decoder to…
  • It plays a crucial role in tasks such as machine translation, summarization, and question answering,…
  • During the decoding phase, for each output token being generated, the cross-attention mechanism queries…
  • This process enables the decoder to "attend" to the most relevant parts of the input sequence,…
  • Cross-attention thus facilitates a dynamic, content-aware generation process where the focus shifts…

Quick-fire answer from the Awesome Generative AI Guide (MIT) · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep