Inferensys

Glossary

Encoder-Decoder Architecture

A Transformer configuration where an encoder processes the input sequence into a dense representation, and a separate decoder generates the output sequence autoregressively using cross-attention to the encoder's output.
Architect reviewing LLM integration architecture on laptop, system diagrams visible, modern technical office setup.
SEQUENCE-TO-SEQUENCE MODELING

What is Encoder-Decoder Architecture?

A foundational Transformer configuration designed for sequence transduction tasks where the input and output lengths differ.

The Encoder-Decoder Architecture is a neural network design where an encoder processes an input sequence into a dense, fixed-length contextual representation, and a separate decoder generates an output sequence autoregressively. The decoder uses cross-attention to attend to the encoder's output, aligning source and target tokens for tasks like machine translation.

Unlike decoder-only models, this architecture uses a bidirectional encoder for deep input understanding and a unidirectional decoder for generation. The encoder's self-attention is unmasked, while the decoder employs causal attention to prevent looking at future tokens, making it optimal for mapping one sequence to another.

ARCHITECTURAL FOUNDATIONS

Core Characteristics of Encoder-Decoder Architectures

The Encoder-Decoder architecture is a two-part Transformer configuration where an encoder processes the input sequence into a dense, contextualized representation, and a separate decoder generates the output sequence autoregressively, using cross-attention to reference the encoder's output.

01

Dual-Component Structure

The architecture consists of two distinct stacks of Transformer blocks. The encoder processes the entire input sequence bidirectionally, creating a rich, context-aware representation for each token. The decoder then generates the output sequence step-by-step, attending to both its own previously generated tokens via causal self-attention and the encoder's output via cross-attention. This separation of concerns makes it ideal for sequence-to-sequence tasks like machine translation, where the input and output lengths differ.

02

The Information Bottleneck

The encoder compresses the entire input sequence into a fixed-size set of hidden state vectors. This final encoder output acts as a dense representation that must capture all relevant semantic and syntactic information from the source. The decoder's cross-attention mechanism then learns to query this representation, extracting the specific information needed at each generation step. This bottleneck forces the model to learn a robust, generalized internal representation of the input.

03

Cross-Attention Mechanism

The critical link between encoder and decoder is cross-attention. In each decoder block, the Query vectors are derived from the decoder's current hidden state, while the Key and Value vectors come from the encoder's final output. This allows every token generation step to dynamically search the entire source sequence for relevant context. Unlike self-attention, cross-attention is not masked, giving the decoder full, bidirectional visibility into the input.

04

Autoregressive Generation

The decoder operates autoregressively, meaning it generates one token at a time, and each generated token is fed back as input for the next step. To prevent the decoder from peeking at future tokens during training, causal masking is applied to its self-attention layers. This ensures the model learns to predict the next token based only on past context, a process often referred to as teacher forcing during training.

05

Bidirectional vs. Unidirectional Context

A fundamental distinction is that the encoder uses bidirectional self-attention, allowing every token to attend to every other token in the input. This builds a deep, holistic understanding of the source. The decoder, however, uses unidirectional (causal) self-attention, preserving the left-to-right autoregressive property. This hybrid approach combines the deep comprehension of a bidirectional model with the generative capability of an autoregressive one.

06

Classic Use Case: Machine Translation

The original Transformer, introduced in the paper 'Attention Is All You Need', was an encoder-decoder model designed for machine translation. The encoder reads the source language sentence (e.g., English), and the decoder generates the target language sentence (e.g., French). This paradigm extends to many tasks:

  • Text Summarization: Long document in, concise summary out.
  • Question Answering: Passage and question in, answer span out.
  • Code Generation: Natural language description in, code snippet out.
ARCHITECTURAL COMPARISON

Encoder-Decoder vs. Decoder-Only Architectures

A feature-level comparison of the two dominant Transformer configurations used in modern sequence transduction and language modeling tasks.

FeatureEncoder-DecoderDecoder-Only

Core Mechanism

Bidirectional self-attention in encoder; causal self-attention and cross-attention in decoder

Causal self-attention only

Input Processing

Encoder processes full input sequence bidirectionally into a dense context representation

Input is processed unidirectionally, left-to-right, as part of the autoregressive stream

Cross-Attention

Autoregressive Generation

Typical Use Cases

Machine translation, summarization, speech recognition (seq2seq tasks)

Open-ended text generation, instruction following, code completion

Representative Models

T5, BART, Whisper, original Transformer (Vaswani et al., 2017)

GPT-4, Llama 3, Claude, Gemini, Mistral

Training Objective

Span corruption (denoising) or conditional generation

Next-token prediction (causal language modeling)

Context Window Efficiency

Encoder processes source once; decoder context window limited to generated output

Full context window consumed by concatenated input and generated output

ARCHITECTURAL LINEAGE

Prominent Models Using Encoder-Decoder Architectures

The encoder-decoder framework, initially popularized for sequence-to-sequence tasks, remains a dominant paradigm for conditional text generation. The following models represent key milestones in the evolution of this architecture, from the original Transformer to modern multimodal systems.

ARCHITECTURE DEEP DIVE

Frequently Asked Questions

Explore the core mechanics of the Encoder-Decoder Transformer, the foundational architecture behind sequence-to-sequence tasks like machine translation and text summarization.

An Encoder-Decoder architecture is a neural network design pattern consisting of two distinct Transformer stacks where the encoder processes the entire input sequence into a dense, context-rich representation, and the decoder generates the output sequence one token at a time. The encoder uses bidirectional self-attention to understand the full context of the input, while the decoder uses causal self-attention to generate outputs autoregressively. The critical link between them is cross-attention, where the decoder's Query vectors attend to the encoder's Key and Value vectors, allowing the generation process to dynamically focus on relevant parts of the source input. This design excels at sequence-to-sequence tasks like machine translation, where the input length differs from the output length.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.