Skip to content

Commit 776a8bf

Browse files
committed
Refactor lectures 19-20: add discussion slides, essay integration, and variant edits
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.
1 parent d571394 commit 776a8bf

7 files changed

Lines changed: 390 additions & 700 deletions

File tree

slides/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,17 @@ Explore concepts hands-on with our interactive web demos! Each demo runs directl
216216
- 📓 [Companion Notebook](https://colab.research.google.com/github/ContextLab/llm-course/blob/main/slides/week6/bert_variants_demo.ipynb)
217217
- 📊 [Slides PDF](https://contextlab.github.io/llm-course/slides/week6/lecture19.pdf) | 🌐 [Slides HTML](https://contextlab.github.io/llm-course/slides/week6/lecture19.html)
218218

219-
**Friday (Lecture 20):** Applications of Encoder Models
219+
**Friday (Lecture 20):** Encoders in the Real World
220220
- Novel applications: clinical NLP, legal tech, financial NER, scientific literature
221221
- Sentence-BERT and modern retrieval: from SBERT to E5 to NV-Embed (MTEB)
222222
- BERT in Google Search, industry adoption ($7.73B NLP market)
223223
- Brain-LLM alignment: neural encoding with language model representations
224-
- Systematic bias measurement (SAGED pipeline)
224+
- Language as brain-to-brain transmission: neural coupling and lossy compression
225+
- Societal consequences: fluency, classification-as-labor, measuring harm at scale
226+
- Discussion: is language a statistical phenomenon? The next decade of encoders
225227
- Reading: [Caucheteux & King (2022)](https://doi.org/10.1038/s42003-022-03036-1) - Brain-LLM alignment
226228
- Reading: [Aw et al. (2026)](https://openreview.net/forum?id=PgIlCCNxdB) - The Mind's Transformer (ICLR 2026)
229+
- Reading: [Stephens, Silbert & Hasson (2010)](https://doi.org/10.1073/pnas.1008662107) - Speaker-listener neural coupling
227230
- Reading: [Reimers & Gurevych (2019)](https://arxiv.org/abs/1908.10084) - Sentence-BERT
228231
- Reading: [Jiang et al. (2025)](https://aclanthology.org/2025.coling-main.202.pdf) - SAGED bias evaluation
229232
- 📓 [Companion Notebook](https://colab.research.google.com/github/ContextLab/llm-course/blob/main/slides/week6/encoder_applications_demo.ipynb)

slides/week6/lecture19.html

Lines changed: 162 additions & 408 deletions
Large diffs are not rendered by default.

slides/week6/lecture19.md

Lines changed: 58 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -397,183 +397,132 @@ ELECTRA is ideal when you have limited compute budget:
397397

398398
---
399399

400-
# Variant comparison summary
401-
402-
<div class="note-box" data-title="Choosing the right BERT variant">
403-
404-
| Model | Key innovation | Best for |
405-
|-------|---------------|----------|
406-
| **BERT** | MLM + NSP | Baseline, well-understood |
407-
| **RoBERTa** | Better training recipe | Maximum quality |
408-
| **ALBERT** | Parameter sharing | Memory-constrained deployment |
409-
| **DistilBERT** | Knowledge distillation | Speed-critical production |
410-
| **ELECTRA** | Replaced token detection | Limited training budget |
400+
# ModernBERT: 6 years of decoder tricks, applied to encoders
411401

412-
</div>
402+
<div class="definition-box" data-title="Key idea: modernize the encoder with techniques from the GPT era">
413403

414-
<div class="tip-box" data-title="General guidelines">
404+
[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?
415405

416-
- **Best quality:** RoBERTa-Large
417-
- **Best efficiency:** DistilBERT
418-
- **Limited memory:** ALBERT
419-
- **Limited training budget:** ELECTRA
420-
- **Good default:** RoBERTa-Base or BERT-Base
406+
| Component | BERT (2018) | ModernBERT (2024) |
407+
|-----------|-------------|-------------------|
408+
| Position encoding | Learned absolute (512 max) | **RoPE** (8,192 tokens) |
409+
| Attention | Full quadratic | **Flash Attention** + alternating global/local |
410+
| Padding | Processes pad tokens | **Unpadding** (only real tokens) |
411+
| Training data | 3.3B words | **2 trillion tokens** (600×) |
412+
| Code understanding | None | Trained on code corpora |
421413

422414
</div>
423415

424-
---
425-
426-
# Other notable BERT variants
427-
428-
<div class="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+
<div class="note-box" data-title="Results">
435417

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.
437419

438420
</div>
439421

440422
---
441423

442-
# Architecture evolution
424+
# ModernBERT key innovations
443425

444-
<div class="note-box" data-title="From BERT to ModernBERT: 6 years of progress">
426+
<div class="definition-box" data-title="RoPE (Rotary Position Embeddings)">
445427

446-
| Model | Year | Key innovation | Quality vs BERT |
447-
|-------|------|---------------|----------------|
448-
| BERT | 2018 | MLM + NSP | Baseline |
449-
| RoBERTa | 2019 | Better training recipe | +3–11 pts |
450-
| ALBERT | 2019 | Parameter sharing | 89% fewer params |
451-
| DistilBERT | 2019 | Knowledge distillation | 97% quality, 60% faster |
452-
| 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.
455429

456430
</div>
457431

458-
---
459-
460-
# ModernBERT deep dive
432+
<div class="definition-box" data-title="Flash Attention">
461433

462-
<div class="definition-box" data-title="Warner et al. (Dec 2024): bringing modern LLM techniques to encoders">
463-
464-
[ModernBERT](https://arxiv.org/abs/2412.13663) applies 6 years of decoder innovations to the encoder architecture:
465-
466-
| Innovation | BERT (2018) | ModernBERT (2024) |
467-
|-----------|-------------|-------------------|
468-
| Position encoding | Learned absolute (512 max) | **RoPE** (8,192 tokens) |
469-
| Attention | Full quadratic | **Flash Attention** + alternating global/local |
470-
| Padding | Processes pad tokens | **Unpadding** (only real tokens) |
471-
| Training data | 3.3B words | **2 trillion tokens** (600× more) |
472-
| Code understanding | None | Trained on code corpora |
434+
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.
473435

474436
</div>
475437

476-
<div class="important-box" data-title="Results">
438+
<div class="definition-box" data-title="Unpadding">
477439

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.
479441

480442
</div>
481443

482444
---
483445

484-
# Gemma Encoder and the encoder renaissance
446+
# Variant comparison summary
485447

486-
<div class="note-box" data-title="Google bets on encoders again (2025)">
448+
<div class="note-box" data-title="Choosing the right BERT variant">
487449

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.
450+
| Model | Key innovation | Best for |
451+
|-------|---------------|----------|
452+
| **BERT** | MLM + NSP | Baseline, well-understood |
453+
| **RoBERTa** | Better training recipe | Maximum quality (classic) |
454+
| **ALBERT** | Parameter sharing | Memory-constrained deployment |
455+
| **DistilBERT** | Knowledge distillation | Speed-critical production |
456+
| **ELECTRA** | Replaced token detection | Limited training budget |
457+
| **ModernBERT** | Modern training + RoPE + Flash Attention | Maximum quality (2024) |
489458

490459
</div>
491460

492-
<div class="tip-box" data-title="Why this matters">
461+
<div class="tip-box" data-title="General guidelines">
493462

494-
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
495468

496469
</div>
497470

498471
---
499472

500-
# Production deployment patterns
473+
# Other notable BERT variants
501474

502-
<div class="note-box" data-title="Getting encoders from prototype to production">
475+
<div class="note-box" data-title="The BERT family keeps growing">
503476

504-
| Optimization | Speedup | Memory savings | Quality loss |
505-
|-------------|---------|----------------|-------------|
506-
| **ONNX Runtime** | 2–5× | Moderate | None |
507-
| **TensorRT** (NVIDIA) | 5–10× | Moderate | None |
508-
| **INT8 quantization** | 2–4× | **4× smaller** | <1% |
509-
| **Distillation** (→ DistilBERT) | 1.6× | 40% smaller | ~3% |
510-
| **Full pipeline** (distill → quantize) | 10–20× | **8× smaller** | ~4% |
477+
[**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.
511478

512-
</div>
479+
[**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).
513480

514-
<div class="important-box" data-title="The cost argument">
481+
[**ERNIE**](https://arxiv.org/abs/1904.09223) (Baidu, 2019): Entity-level and phrase-level masking. Knowledge-enhanced pre-training. Strong on Chinese NLP tasks.
515482

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.
517484

518485
</div>
519486

520487
---
521488

522-
# Is the encoder dead?
489+
# The case against encoders
523490

524-
<div class="tip-box" data-title="Discussion: GPT-4 can classify text via prompting. Do we still need encoders?">
491+
<div class="warning-box" data-title="Why did people start saying 'the encoder is dead'?">
525492

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.
530494

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.
536496

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.
538498

539499
</div>
540500

541-
---
542-
543-
# Discussion
544-
545-
<div class="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+
<div class="tip-box" data-title="The argument in one sentence">
548502

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?
554504

555505
</div>
556506

557507
---
558-
<!-- _class: scale-85 -->
559508

560-
# Further reading
509+
# Gemma Encoder and the encoder renaissance
561510

562-
<div class="note-box" data-title="Further reading">
511+
<div class="definition-box" data-title="What is Gemma?">
563512

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.
565514

566-
[**Lan et al. (2019, *ICLR*)**](https://arxiv.org/abs/1909.11942) "ALBERT: A Lite BERT" — 89% parameter reduction via sharing.
515+
</div>
567516

568-
[**Sanh et al. (2019, *NeurIPS Workshop*)**](https://arxiv.org/abs/1910.01108) "DistilBERT" — Knowledge distillation for 60% speedup.
517+
<div class="note-box" data-title="Google bets on encoders again (2025)">
569518

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.
571520

572-
[**He et al. (2020, *ICLR*)**](https://arxiv.org/abs/2006.03654) "DeBERTa" — Disentangled attention, SOTA on SuperGLUE.
521+
</div>
573522

574-
[**Warner et al. (2024, *arXiv*)**](https://arxiv.org/abs/2412.13663) "ModernBERT" — Modern encoder with RoPE + Flash Attention.
523+
<div class="tip-box" data-title="Why this matters">
575524

576-
[**Google (2025, *arXiv*)**](https://arxiv.org/abs/2503.02656) "Gemma Encoder" — Encoder-only Gemma for sentence embeddings.
525+
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**.
577526

578527
</div>
579528

@@ -598,6 +547,6 @@ DistilBERT + INT8 quantization handles classification at ~$0.001/M tokens and ~2
598547

599548
<div class="tip-box" data-title="Up next...">
600549

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
602551

603552
</div>

slides/week6/lecture19.pdf

-462 KB
Binary file not shown.

0 commit comments

Comments
 (0)