LLMS & TRANSFORMERS · INTERVIEW QUESTION
What is the difference between encoder-only, decoder-only, and encoder-decoder transformers?
🟡 intermediate · Pre-training & Fine-tuning
Hint: BERT vs GPT vs T5. Think about the attention mask and use cases.
Answer
The three Transformer architectures differ in attention masking and pre-training objectives.
Comparison
| Architecture | Attention | Pre-training | Best For |
|---|---|---|---|
| Encoder-only (BERT) | Bidirectional | Masked LM | Classification, NER, embeddings |
| Decoder-only (GPT) | Causal (left→right) | Next token prediction | Text generation, chat |
| Encoder-decoder (T5) | Bi + causal + cross | Span corruption | Translation, summarization |
Encoder-Only (BERT)
Sees all tokens bidirectionally. Excellent for understanding tasks but cannot generate text natively.
Decoder-Only (GPT)
Causal attention mask — each token only sees past tokens. Naturally suited for generation.
Encoder-Decoder (T5, BART)
Encoder sees input bidirectionally, decoder generates output with cross-attention to encoder.
Modern trend: decoder-only dominates (GPT-4, LLaMA, Claude) because it scales better and handles all tasks via prompting.
Related questions
- Explain the difference between LoRA, full fine-tuning, and prompt tuning. When would you use each?
- How do you evaluate LLMs? What benchmarks and metrics matter?
- Explain the tokenization strategies used in LLMs: BPE, WordPiece, and SentencePiece.
- What is the scaling laws relationship between model size, data, and compute?
- Explain the self-attention mechanism in detail. What are Q, K, V and why do we use scaled dot-product attention?