You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Lecture 19: RoBERTa hyperlinks + benchmark box, factorized embedding slide,
DistilBERT GLUE definition, ELECTRA tip/code completion, ModernBERT
moved after ELECTRA with innovations slide, case-against-encoders slide,
Gemma Encoder definition box, variant comparison table updated.
Lecture 20: Retitled 'Encoders in the real world'. Replaced understanding
debate and adversarial examples with 7 discussion-driven slides: language
as brain-to-brain transmission (Stephens et al. 2010), when fluency is
free, classification as labor, measuring harm at scale (SAGED), is
language a statistical phenomenon, the next decade, deep discussion.
Updated learning objectives and further reading.
[ModernBERT](https://arxiv.org/abs/2412.13663) (Warner et al., 2024) asks: what if we rebuilt BERT from scratch using everything we've learned from training decoders?
<divclass="note-box"data-title="The BERT family keeps growing">
429
-
430
-
[**DeBERTa**](https://arxiv.org/abs/2006.03654) (Microsoft, 2020): Disentangled attention separates content and position representations. Enhanced mask decoder. State-of-the-art on SuperGLUE.
431
-
432
-
[**SpanBERT**](https://arxiv.org/abs/1907.10529) (Facebook, 2019): Masks random contiguous *spans* instead of individual tokens. Span boundary objective. Better for extractive tasks (QA, coreference).
433
-
434
-
[**ERNIE**](https://arxiv.org/abs/1904.09223) (Baidu, 2019): Entity-level and phrase-level masking. Knowledge-enhanced pre-training. Strong on Chinese NLP tasks.
416
+
<divclass="note-box"data-title="Results">
435
417
436
-
[**BART**](https://arxiv.org/abs/1910.13461) (Facebook, 2019): Encoder-decoder architecture (not encoder-only). Denoising autoencoder with various corruption strategies. Excellent for generation tasks.
418
+
SOTA on [GLUE](https://gluebenchmark.com/), retrieval ([MTEB](https://huggingface.co/spaces/mteb/leaderboard)), and code understanding. Available as `answerdotai/ModernBERT-base` and `answerdotai/ModernBERT-large`. Proves that the encoder architecture still has room to grow.
437
419
438
420
</div>
439
421
440
422
---
441
423
442
-
# Architecture evolution
424
+
# ModernBERT key innovations
443
425
444
-
<divclass="note-box"data-title="From BERT to ModernBERT: 6 years of progress">
426
+
<divclass="definition-box"data-title="RoPE (Rotary Position Embeddings)">
445
427
446
-
| Model | Year | Key innovation | Quality vs BERT |
447
-
|-------|------|---------------|----------------|
448
-
| BERT | 2018 | MLM + NSP | Baseline |
449
-
| RoBERTa | 2019 | Better training recipe | +3–11 pts |
| ELECTRA | 2020 | Learn from all tokens | 4× less compute |
453
-
| DeBERTa | 2020 | Disentangled attention | SOTA on SuperGLUE |
454
-
| ModernBERT | 2024 | Modern training + RoPE + Flash Attention | SOTA on GLUE, retrieval |
428
+
Instead of learning a fixed position embedding for each slot (BERT's approach, capped at 512 tokens), RoPE encodes position by **rotating** the query and key vectors in attention. Relative distances are captured by the angle between rotated vectors. This generalizes to sequences longer than training length — ModernBERT handles **8,192 tokens** vs BERT's 512.
Standard attention materializes the full $T \times T$ attention matrix in GPU memory ($O(T^2)$ space). Flash Attention computes attention **tile-by-tile** in fast on-chip SRAM, never storing the full matrix. Same exact result, but ~2–4× faster and uses $O(T)$ memory. ModernBERT alternates between global attention (every token sees every token) and local attention (sliding window) across layers.
473
435
474
436
</div>
475
437
476
-
<divclass="important-box"data-title="Results">
438
+
<divclass="definition-box"data-title="Unpadding">
477
439
478
-
SOTA on GLUE, retrieval (MTEB), and code understanding benchmarks. Available as `answerdotai/ModernBERT-base` and `answerdotai/ModernBERT-large` on HuggingFace. Proves that encoder architecture still has room to grow when given modern training techniques.
440
+
Batched inputs require padding shorter sequences to the same length. BERT wastes compute processing these pad tokens through every layer. Unpadding **strips** pad tokens before the transformer and **reinserts** them after, so the model only processes real tokens. In batches with variable-length inputs, this can save 20–30% of total compute.
479
441
480
442
</div>
481
443
482
444
---
483
445
484
-
# Gemma Encoder and the encoder renaissance
446
+
# Variant comparison summary
485
447
486
-
<divclass="note-box"data-title="Google bets on encoders again (2025)">
448
+
<divclass="note-box"data-title="Choosing the right BERT variant">
487
449
488
-
[Gemma Encoder](https://arxiv.org/abs/2503.02656) (2025): Google's first encoder-only model since BERT, built by repurposing Gemma decoder weights for bidirectional encoding. Competitive with ModernBERT on sentence embedding tasks.
If Google — a company betting heavily on decoder-only models (Gemini) — still releases an encoder model, it signals that encoders serve a purpose decoders can't efficiently fill. The encoder isn't dead; it's being **modernized**.
463
+
-**Best quality (2024):** ModernBERT-Large
464
+
-**Best efficiency:** DistilBERT
465
+
-**Limited memory:** ALBERT
466
+
-**Limited training budget:** ELECTRA
467
+
-**Good default:** RoBERTa-Base or ModernBERT-Base
495
468
496
469
</div>
497
470
498
471
---
499
472
500
-
# Production deployment patterns
473
+
# Other notable BERT variants
501
474
502
-
<divclass="note-box"data-title="Getting encoders from prototype to production">
475
+
<divclass="note-box"data-title="The BERT family keeps growing">
[**ERNIE**](https://arxiv.org/abs/1904.09223) (Baidu, 2019): Entity-level and phrase-level masking. Knowledge-enhanced pre-training. Strong on Chinese NLP tasks.
515
482
516
-
DistilBERT + INT8 quantization handles classification at ~$0.001/M tokens and ~2ms per request. GPT-4 costs ~$30/M tokens at ~500ms per request. For high-volume single-task workloads, optimized encoders are **30,000× cheaper** and **250× faster**.
483
+
[**BART**](https://arxiv.org/abs/1910.13461) (Facebook, 2019): Encoder-decoder architecture (not encoder-only). Denoising autoencoder with various corruption strategies. Excellent for generation tasks.
517
484
518
485
</div>
519
486
520
487
---
521
488
522
-
# Is the encoder dead?
489
+
# The case against encoders
523
490
524
-
<divclass="tip-box"data-title="Discussion: GPT-4 can classify text via prompting. Do we still need encoders?">
491
+
<divclass="warning-box"data-title="Why did people start saying 'the encoder is dead'?">
525
492
526
-
**The case for "yes, encoders are obsolete":**
527
-
- Decoder-only models (GPT-4, Claude) can do classification, NER, QA via prompting
528
-
- One model for all tasks vs. fine-tuning separate models
529
-
- In-context learning eliminates the need for task-specific architectures
493
+
**2020 — In-context learning**: [GPT-3](https://arxiv.org/abs/2005.14165) (Brown et al.) showed that a single decoder model can perform classification, NLI, and QA via prompting — tasks that previously required fine-tuning separate BERT models for each.
530
494
531
-
**The case for "no, encoders still matter":**
532
-
- ModernBERT (2024) achieves SOTA on retrieval and classification — faster and cheaper than any decoder
533
-
- Gemma Encoder (2025) proves Google still sees value in the architecture
534
-
- Encoders are 10–100× cheaper to run than decoder models for classification tasks
535
-
- Most production search and retrieval systems still use encoders (Sentence-BERT, E5, NV-Embed)
495
+
**2023 — Decoders match fine-tuned encoders**: [GPT-4](https://arxiv.org/abs/2303.08774) (OpenAI) matched or exceeded fine-tuned BERT/RoBERTa on many NLU benchmarks without any task-specific training.
536
496
537
-
**The real answer:** It depends on your constraints. Encoders win on cost and latency. Decoders win on flexibility.
497
+
**2024 — Decoders do retrieval too**: [GritLM](https://arxiv.org/abs/2402.09906) (Muennighoff et al.) demonstrated a single decoder model that handles both generation *and* embedding at SOTA levels — the last domain where encoders had a clear advantage.
538
498
539
499
</div>
540
500
541
-
---
542
-
543
-
# Discussion
544
-
545
-
<divclass="tip-box"data-title="Questions to consider">
546
-
547
-
1.**Training vs architecture:** RoBERTa shows that training matters enormously. How much of BERT's "limitations" were really just undertrained models?
501
+
<divclass="tip-box"data-title="The argument in one sentence">
548
502
549
-
2.**The distillation paradox:** Why does a student model learn *better* from soft probability distributions than from hard labels? What "dark knowledge" is in the teacher's mistakes?
550
-
551
-
3.**Encoders in 2026:** Google, Hugging Face, and others are *still* releasing encoder models. If decoders can do everything, why? What does this tell us about the efficiency-flexibility tradeoff?
552
-
553
-
4.**Parameter sharing (ALBERT):** All 12 layers share the same weights and it still works. What does this imply about what transformer layers actually learn?
503
+
Why fine-tune six BERT models for six tasks when one decoder does them all via prompting?
554
504
555
505
</div>
556
506
557
507
---
558
-
<!-- _class: scale-85 -->
559
508
560
-
# Further reading
509
+
# Gemma Encoder and the encoder renaissance
561
510
562
-
<divclass="note-box"data-title="Further reading">
511
+
<divclass="definition-box"data-title="What is Gemma?">
563
512
564
-
[**Liu et al. (2019, *arXiv*)**](https://arxiv.org/abs/1907.11692) "RoBERTa: A Robustly Optimized BERT Pretraining Approach" — Better training recipe, same architecture.
513
+
[Gemma](https://arxiv.org/abs/2403.08295) (Google, 2024) is a family of open-weight **decoder-only** language models (2B and 7B parameters) built from the same research behind [Gemini](https://arxiv.org/abs/2312.11805). Outperforms similarly sized open models on 11/18 text benchmarks.
565
514
566
-
[**Lan et al. (2019, *ICLR*)**](https://arxiv.org/abs/1909.11942) "ALBERT: A Lite BERT" — 89% parameter reduction via sharing.
515
+
</div>
567
516
568
-
[**Sanh et al. (2019, *NeurIPS Workshop*)**](https://arxiv.org/abs/1910.01108) "DistilBERT" — Knowledge distillation for 60% speedup.
517
+
<divclass="note-box"data-title="Google bets on encoders again (2025)">
569
518
570
-
[**Clark et al. (2020, *ICLR*)**](https://arxiv.org/abs/2003.10555) "ELECTRA" — Learn from all tokens, not just masked ones.
519
+
[Gemma Encoder](https://arxiv.org/abs/2503.02656) (2025) repurposes Gemma's decoder weights for **bidirectional** encoding — Google's first encoder-only model since BERT. Competitive with ModernBERT on sentence embedding tasks.
571
520
572
-
[**He et al. (2020, *ICLR*)**](https://arxiv.org/abs/2006.03654) "DeBERTa" — Disentangled attention, SOTA on SuperGLUE.
521
+
</div>
573
522
574
-
[**Warner et al. (2024, *arXiv*)**](https://arxiv.org/abs/2412.13663) "ModernBERT" — Modern encoder with RoPE + Flash Attention.
If Google — a company betting heavily on decoder-only models (Gemini) — still releases an encoder model, it signals that encoders serve a purpose decoders can't efficiently fill. The encoder isn't dead; it's being **modernized**.
577
526
578
527
</div>
579
528
@@ -598,6 +547,6 @@ DistilBERT + INT8 quantization handles classification at ~$0.001/M tokens and ~2
598
547
599
548
<divclass="tip-box"data-title="Up next...">
600
549
601
-
Applications of encoder models: industry, neuroscience, and the "understanding" debate
550
+
Encoder models in the real world — applications, brain-model convergence, and what it all means for language and society
0 commit comments