In a transformer-based sequence-to-sequence model, what are the primary functions of the encoder and decoder? How does information flow between them during both training and inference?
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
In a transformer-based sequence-to-sequence model, the encoder and decoder serve distinct but complementary roles in processing and generating sequences:
Encoder: The encoder processes the input sequence, capturing its informational content and contextual relationships. It transforms the input into a set of continuous representations, which encapsulate the input sequence's information in a form that the decoder can utilize.
Full worked answer
In a transformer-based sequence-to-sequence model, the encoder and decoder serve distinct but complementary roles in processing and generating sequences:
Encoder: The encoder processes the input sequence, capturing its informational content and contextual relationships. It transforms the input into a set of continuous representations, which encapsulate the input sequence's information in a form that the decoder can utilize.
Decoder: The decoder receives the encoder's output representations and generates the output sequence, one element at a time. It uses the encoder's representations along with the previously generated elements to produce the next element in the sequence.
During training and inference, information flows between the encoder and decoder primarily through the encoder's output representations. In addition, the decoder uses self-attention to consider its previous outputs when generating the next output, ensuring coherence and contextuality in the generated sequence. In some transformer variants, cross-attention mechanisms in the decoder also allow direct attention to the encoder's outputs at each decoding step, further enhancing the model's ability to generate relevant and accurate sequences based on the input.
What a good answer covers
- Encoder: The encoder processes the input sequence, capturing its informational content and contextual…
- It transforms the input into a set of continuous representations, which encapsulate the input sequence's…
- Decoder: The decoder receives the encoder's output representations and generates the output sequence,…
- It uses the encoder's representations along with the previously generated elements to produce the next…
- During training and inference, information flows between the encoder and decoder primarily through the…
Key terms: Encoder · Decoder
In the glossary: Attention
Quick-fire answer from the Awesome Generative AI Guide (MIT) · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep