Coding Now – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 9667708830
Back to Generative AI Notes
Topic #409

Encoder-Decoder Architecture

The original 2017 transformer used two separate stacks — an encoder that processes the full input at once, and a decoder that generates output step by step, attending back to the encoder's representation. This architecture is still used today for specific tasks, though most modern general-purpose LLMs use a simpler decoder-only design instead.

How It Was Originally Used: Translation

Input (French):  "Le chat est noir"
  ↓
Encoder: processes the entire input sentence at once,
         building a rich representation of its full meaning

Decoder: generates the output one token at a time, attending
         to (a) what it's generated so far, and (b) the
         encoder's representation of the full input

Output (English):  "The" → "cat" → "is" → "black"

Two Kinds of Attention at Work

Attention TypeWhereWhat It Does
Self-attention (encoder)Within the encoderLets the input sentence relate its own tokens to each other
Self-attention (decoder)Within the decoderLets the output-so-far relate to itself (causal/masked, see Self-Attention)
Cross-attentionDecoder attending to encoderLets each output token look back at the full input representation

Where Encoder-Decoder Models Still Matter

Tasks with a clear, fixed source and a genuinely different target sequence — translation, and some summarization/structured-transformation tasks — still use encoder-decoder architectures. Encoder-only models (like BERT-style architectures) are separately used for understanding-focused tasks (classification, embeddings) where no generation is needed at all.

Why Most Modern Chat/Generation LLMs Don't Use This

General-purpose conversational and generation-focused LLMs mostly use decoder-only architectures instead — simpler (one stack, not two), and well suited to open-ended generation where there isn't a clean "fixed input, then generate output" split the way translation has. See Decoder-Only Transformers for why this became the dominant approach for general-purpose LLMs.

Common Mistakes

  • Assuming all transformers are encoder-decoder — most modern general-purpose LLMs are decoder-only, a meaningfully simpler architecture
  • Confusing cross-attention (decoder attending to encoder) with self-attention (a sequence attending to itself) — they serve different structural roles

Interview Relevance

"When would you still use an encoder-decoder architecture today?" — a good answer: tasks with a clear, distinct source-to-target transformation, like translation, where the encoder's job (understand the whole input) is genuinely different from the decoder's job (generate a related but distinct output).

Practice Question

Explain why a translation task benefits from cross-attention (decoder attending to the full encoder output), in terms of what the decoder needs to "see" while generating each output word.

Related Notes

Want to go beyond the notes?

Join CodingNow's Generative AI course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →