MLCrack

    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

    ArchitectureAttentionPre-trainingBest For
    Encoder-only (BERT)BidirectionalMasked LMClassification, NER, embeddings
    Decoder-only (GPT)Causal (left→right)Next token predictionText generation, chat
    Encoder-decoder (T5)Bi + causal + crossSpan corruptionTranslation, 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.