seq2seq model

Sequence-to-Sequence (Seq2Seq) Models are the neural network architecture pattern where an encoder processes a variable-length input sequence into a fixed or variable-length representation, and a decoder generates a variable-length output sequence from that representation — the foundational architecture for machine translation, summarization, speech recognition, and any task that maps one sequence to another of potentially different length.

Seq2Seq Evolution

EraArchitectureKey InnovationExample
2014RNN Encoder-DecoderCompress input to fixed vectorSutskever et al.
2015RNN + AttentionAttend to any input positionBahdanau Attention
2017Transformer Enc-DecSelf-attention, parallelizable"Attention Is All You Need"
2019+Pre-trained Enc-DecTransfer learning + fine-tuningT5, BART, mBART
2020+Decoder-OnlyPrompting, no explicit encoderGPT-3, LLaMA

Original RNN Seq2Seq

1. Encoder RNN: Processes input tokens x₁...xₙ → produces final hidden state hₙ (context vector).
2. Context vector: Fixed-size summary of entire input → bottleneck!
3. Decoder RNN: Initialized with context vector → generates output tokens y₁...yₘ autoregressively.
- Problem: Fixed-size context vector cannot capture all information from long sequences.

Attention Mechanism (Bahdanau, 2015)

  • Instead of single context vector: Decoder attends to ALL encoder hidden states.
  • At each decoder step t: Compute attention weights over encoder states → weighted sum = context.
  • $c_t = \sum_i \alpha_{t,i} h_i$ where $\alpha_{t,i} = \text{softmax}(\text{score}(s_t, h_i))$
  • Result: Decoder can focus on relevant parts of input → dramatically improved translation quality.

Transformer Encoder-Decoder

  • Encoder: Stack of self-attention + FFN layers → contextual representations.
  • Decoder: Masked self-attention + cross-attention to encoder + FFN.
  • Cross-attention: Decoder queries attend to encoder outputs (keys and values from encoder).
  • Fully parallelizable (no recurrence) → much faster training.

Pre-trained Seq2Seq Models

ModelPre-training ObjectiveBest For
T5Text-to-text (span corruption)General NLP tasks
BARTDenoising autoencoderSummarization, generation
mBARTMultilingual denoisingMultilingual translation
NLLBTranslation-specific pre-training200+ language translation
Flan-T5Instruction-tuned T5Following instructions

Seq2Seq vs. Decoder-Only

AspectEncoder-DecoderDecoder-Only
Input processingBidirectional (encoder)Causal (left-to-right)
Cross-attentionYes (decoder→encoder)No
Best forTranslation, summarizationOpen-ended generation, chat
EfficiencyMore parameters for same qualitySimpler, scales better

Sequence-to-sequence models are the architectural foundation that enabled neural approaches to surpass traditional methods in machine translation and structured generation — while decoder-only models now dominate general-purpose language modeling, the encoder-decoder pattern remains the superior choice for tasks with distinct input and output sequences.

Go deeper with CFSGPT

Get AI-powered deep-dives, save terms, and run advanced simulations — free account.

Create Free Account