AashishAIHub's picture
fix: restored 10/10 technical curriculum and SVG diagrams for Transformer Deep-Dive
de2603c
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Transformer Deep-Dive: Architectures & Foundations</title>
<!-- MathJax 3.x -->
<script>
MathJax = { tex: { inlineMath: [['$', '$'], ['\\(', '\\)']] } };
</script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--bg: #0f1419;
--surface: #1a1f2e;
--text: #e4e6eb;
--text-dim: #b0b7c3;
--cyan: #a371f7; /* Themed to Purple for CME295 */
--orange: #00d4ff; /* Themed to Cyan */
--green: #2ecc71;
--yellow: #ffaa00;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: var(--bg);
color: var(--text);
line-height: 1.6;
overflow-x: hidden;
}
.container {
max-width: 1400px;
margin: 0 auto;
padding: 20px;
}
header {
text-align: center;
margin-bottom: 40px;
padding: 30px 0;
border-bottom: 2px solid var(--cyan);
}
h1 {
font-size: 2.5em;
background: linear-gradient(135deg, var(--cyan), var(--orange));
background-clip: text;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
margin-bottom: 10px;
}
.subtitle {
color: var(--text-dim);
font-size: 1.1em;
}
.disclaimer {
margin-top: 50px;
padding: 20px;
border-top: 1px solid var(--surface);
color: var(--text-dim);
font-size: 0.85em;
text-align: center;
max-width: 800px;
margin-left: auto;
margin-right: auto;
}
.dashboard {
display: none;
}
.dashboard.active {
display: block;
}
.deep-dive-note {
background: rgba(163, 113, 247, 0.15);
border-left: 4px solid var(--cyan);
padding: 20px;
border-radius: 8px;
margin: 25px 0;
position: relative;
}
.deep-dive-note::before {
content: 'πŸ” TECHNICAL DEEP-DIVE';
font-size: 0.75em;
font-weight: 800;
color: var(--cyan);
display: block;
margin-bottom: 10px;
letter-spacing: 1px;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 25px;
margin: 40px 0;
}
.card {
background: linear-gradient(135deg, rgba(163, 113, 247, 0.1), rgba(0, 212, 255, 0.1));
border: 2px solid var(--cyan);
border-radius: 12px;
padding: 30px;
cursor: pointer;
transition: all 0.3s ease;
text-align: center;
position: relative;
}
.card:hover {
transform: translateY(-5px);
box-shadow: 0 10px 30px rgba(163, 113, 247, 0.2);
border-color: var(--orange);
}
.card-icon {
font-size: 3em;
margin-bottom: 15px;
}
.card h3 {
color: var(--cyan);
font-size: 1.5em;
margin-bottom: 10px;
}
.card p {
color: var(--text-dim);
font-size: 0.95em;
}
.category-label {
display: inline-block;
margin-top: 10px;
padding: 5px 12px;
background: rgba(163, 113, 247, 0.2);
border-radius: 20px;
font-size: 0.85em;
color: #d1b3ff;
}
.module {
display: none;
}
.module.active {
display: block;
animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
.btn-back {
display: inline-block;
text-decoration: none;
padding: 10px 20px;
background: var(--cyan);
color: var(--bg);
border: none;
border-radius: 6px;
cursor: pointer;
font-weight: 600;
margin-bottom: 25px;
transition: all 0.3s ease;
}
.btn-back:hover {
background: var(--orange);
}
.tabs {
display: flex;
gap: 10px;
margin-bottom: 30px;
flex-wrap: wrap;
justify-content: center;
border-bottom: 1px solid rgba(163, 113, 247, 0.2);
padding-bottom: 15px;
overflow-x: auto;
}
.tab-btn {
padding: 10px 20px;
background: var(--surface);
color: var(--text);
border: 2px solid transparent;
border-radius: 6px;
cursor: pointer;
font-size: 0.95em;
transition: all 0.3s ease;
font-weight: 500;
white-space: nowrap;
}
.tab-btn:hover {
background: rgba(163, 113, 247, 0.1);
border-color: var(--cyan);
}
.tab-btn.active {
background: var(--cyan);
color: var(--bg);
border-color: var(--cyan);
}
.tab {
display: none;
}
.tab.active {
display: block;
animation: fadeIn 0.3s ease;
}
.section {
background: var(--surface);
border: 1px solid rgba(163, 113, 247, 0.2);
border-radius: 10px;
padding: 30px;
margin-bottom: 25px;
transition: all 0.3s ease;
}
.section:hover {
border-color: var(--cyan);
box-shadow: 0 0 20px rgba(163, 113, 247, 0.1);
}
h2 {
color: var(--cyan);
font-size: 1.8em;
margin-bottom: 15px;
}
h3 {
color: var(--orange);
font-size: 1.3em;
margin-top: 20px;
margin-bottom: 12px;
}
h4 {
color: var(--green);
font-size: 1.1em;
margin-top: 15px;
margin-bottom: 10px;
}
p {
margin-bottom: 15px;
line-height: 1.8;
}
ul {
margin-left: 20px;
margin-bottom: 15px;
}
ul li {
margin-bottom: 8px;
}
.info-box {
background: linear-gradient(135deg, rgba(163, 113, 247, 0.1), rgba(0, 212, 255, 0.1));
border: 1px solid var(--cyan);
border-radius: 8px;
padding: 20px;
margin: 20px 0;
}
.box-title {
color: var(--orange);
font-weight: 700;
margin-bottom: 10px;
font-size: 1.1em;
}
.box-content {
color: var(--text-dim);
line-height: 1.7;
}
.formula {
background: rgba(163, 113, 247, 0.1);
border: 1px solid var(--cyan);
border-radius: 8px;
padding: 20px;
margin: 20px 0;
overflow-x: auto;
line-height: 1.8;
color: #d1b3ff;
text-align: center;
}
.code-block {
background: #0d1117;
border: 1px solid #30363d;
border-radius: 8px;
padding: 20px;
margin: 20px 0;
overflow-x: auto;
font-family: 'Fira Code', 'Consolas', monospace;
font-size: 0.88em;
line-height: 1.7;
white-space: pre-wrap;
color: #e6edf3;
}
.code-title {
display: block;
background: #161b22;
color: #8b949e;
padding: 8px 16px;
border-radius: 8px 8px 0 0;
border: 1px solid #30363d;
border-bottom: none;
font-size: 0.85em;
font-family: 'Fira Code', monospace;
margin-top: 20px;
}
.code-title+.code-block {
margin-top: 0;
border-radius: 0 0 8px 8px;
}
.code-block .keyword { color: #ff7b72; }
.code-block .string { color: #a5d6ff; }
.code-block .comment { color: #8b949e; }
.code-block .function { color: #d2a8ff; }
.code-block .builtin { color: #79c0ff; }
.code-block .number { color: #79c0ff; }
.callout {
border-left: 4px solid;
padding: 15px;
margin: 20px 0;
border-radius: 6px;
}
.callout.tip {
border-left-color: var(--green);
background: rgba(46, 204, 113, 0.05);
}
.callout.warning {
border-left-color: var(--yellow);
background: rgba(255, 170, 0, 0.05);
}
.callout.insight {
border-left-color: var(--cyan);
background: rgba(163, 113, 247, 0.05);
}
.callout-title {
font-weight: 700;
margin-bottom: 8px;
}
.list-item {
display: flex;
gap: 12px;
margin: 12px 0;
padding: 12px;
background: rgba(163, 113, 247, 0.05);
border-left: 3px solid var(--cyan);
border-radius: 4px;
}
.list-num {
color: var(--orange);
font-weight: 700;
min-width: 30px;
}
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
}
th, td {
padding: 12px;
text-align: left;
border: 1px solid rgba(163, 113, 247, 0.2);
}
th {
background: rgba(163, 113, 247, 0.1);
color: var(--cyan);
font-weight: 700;
}
@media (max-width: 768px) {
h1 { font-size: 1.8em; }
.tabs { flex-direction: column; }
.tab-btn { width: 100%; }
.grid { grid-template-columns: 1fr; }
}
</style>
</head>
<body>
<div class="container">
<!-- MAIN DASHBOARD -->
<div id="dashboard" class="dashboard active">
<header>
<h1>🧠 Transformer Deep-Dive</h1>
<p class="subtitle">From Attention to Reasoning: A Masterclass in Modern Architectures (2025 Edition)</p>
<div style="margin-top: 25px;">
<a href="../index.html" class="btn-back">← Back to Masterclass</a>
</div>
</header>
<div style="text-align: center; margin-bottom: 40px;">
<p style="color: var(--text-dim); font-size: 1.1em; max-width: 800px; margin: 0 auto;">
Master the architecture that powers modern AI. This comprehensive 9-module curriculum deeply covers NLP fundamentals,
Transformer internals, advanced LLM tuning, reasoning architectures, and agentic workflows.
</p>
</div>
<div class="grid" id="modulesGrid"></div>
</div>
<!-- MODULES CONTAINER -->
<div id="modulesContainer"></div>
</div>
<script>
const modules = [
{
id: "lecture-1",
title: "The Foundation: NLP & Transformers",
icon: "πŸ“š",
category: "NLP Basics",
color: "#a371f7",
description: "Tokenization, Word2Vec, RNNs, and the Self-Attention Mechanism that started it all."
},
{
id: "lecture-2",
title: "Transformer Architectures",
icon: "πŸ€–",
category: "Architecture",
color: "#00d4ff",
description: "Deep dive into MHA, GQA, RoPE, BERT, and GPT architectures."
},
{
id: "lecture-3",
title: "Inside Large Language Models",
icon: "🧠",
category: "LLM Internals",
color: "#ffaa00",
description: "Mixture of Experts, Decoding Strategies, Context Windows, and Prompting."
},
{
id: "lecture-4",
title: "Training & Tuning LLMs",
icon: "βš™οΈ",
category: "Training",
color: "#2ecc71",
description: "From Pretraining on massive sets to SFT, LoRA, and memory-saving Quantization."
},
{
id: "lecture-5",
title: "Aligning LLMs (RLHF/DPO)",
icon: "βš–οΈ",
category: "Alignment",
color: "#f771b6",
description: "Shaping AI behavior using RLHF, Reward Models, PPO, and DPO."
},
{
id: "lecture-6",
title: "Reasoning Models",
icon: "πŸ€”",
category: "Advanced",
color: "#ff6b35",
description: "Test-time compute, System 2 Thinking (o1-style), and GRPO RL formulation."
},
{
id: "lecture-7",
title: "Agentic LLMs & RAG",
icon: "πŸ•΅οΈ",
category: "Agents",
color: "#00c9a7",
description: "Augmenting models via Vector databases, Function Calling, and the ReAct loop."
},
{
id: "lecture-8",
title: "Evaluation & Benchmarks",
icon: "πŸ“Š",
category: "Evaluation",
color: "#a371f7",
description: "How to objectively measure LLMs using exact benchmarks or LLM-as-a-Judge."
},
{
id: "lecture-9",
title: "Multimodality & Trends",
icon: "πŸ‘οΈ",
category: "Frontier",
color: "#00d4ff",
description: "Vision Transformers (ViT), Diffusion models, and the expanding modalities."
}
];
const MODULE_CONTENT = {
"lecture-1": {
overview: `
<p>Before Large Language Models, computers needed a way to process human language reliably. This module covers the historic journey from basic NLP processing to the revolutionary architecture that powers modern AI.</p>
<div class="deep-dive-note">
Historically, RNNs were the deep learning standard for text, but they processed data sequentially, leading to information loss over long sentences (vanishing gradients). The Transformer paper ("Attention Is All You Need", 2017) completely eliminated recurrent layers in favor of the <strong>Self-Attention Mechanism</strong>, allowing the model to look at the entire context simultaneously.
</div>
`,
concepts: `
<div class="list-item">
<div class="list-num">01</div>
<div>
<strong>Tokenization & BPE:</strong> Transition from word-level to sub-word level. Byte Pair Encoding (BPE) uses a frequency-based merge strategy to build a vocabulary.
<div class="visual-demo" style="margin-top: 15px; background: rgba(0,0,0,0.2); padding: 15px; border-radius: 8px; border: 1px solid var(--green);">
<h4 style="color: var(--green); margin-bottom: 10px; font-size: 0.85em;">BPE Merging Strategy</h4>
<svg viewBox="0 0 400 120" style="width: 100%; height: auto;">
<!-- Initial state -->
<rect x="20" y="20" width="40" height="30" rx="4" fill="var(--surface)" stroke="var(--text-dim)" />
<text x="32" y="40" fill="var(--text)" font-size="12">l o</text>
<rect x="70" y="20" width="40" height="30" rx="4" fill="var(--surface)" stroke="var(--text-dim)" />
<text x="82" y="40" fill="var(--text)" font-size="12">w</text>
<rect x="120" y="20" width="40" height="30" rx="4" fill="var(--surface)" stroke="var(--text-dim)" />
<text x="132" y="40" fill="var(--text)" font-size="12">e r</text>
<!-- Merge Step -->
<path d="M 40 55 L 75 80" stroke="var(--green)" stroke-width="1" marker-end="url(#arrow-green)" />
<path d="M 90 55 L 85 80" stroke="var(--green)" stroke-width="1" marker-end="url(#arrow-green)" />
<rect x="60" y="85" width="60" height="30" rx="4" fill="rgba(46, 204, 113, 0.2)" stroke="var(--green)" />
<text x="75" y="105" fill="var(--text)" font-size="12">"low"</text>
<text x="130" y="105" fill="var(--text-dim)" font-size="10">+ "er" ...</text>
</svg>
<p style="font-size: 0.75em; color: var(--text-dim);">Frequent sequences (l+o+w) are merged into a single token, reducing sequence length while handling rare words.</p>
</div>
</div>
</div>
<div class="list-item">
<div class="list-num">02</div>
<div>
<strong>Word2Vec & Vector Spaces:</strong> Word embeddings map tokens into a high-dimensional continuous space (e.g., 512 dimensions). These vectors capture semantic relationships via dot products; tokens with similar meanings are geometrically close.
<div class="visual-demo" style="margin-top: 20px; background: rgba(0,0,0,0.2); padding: 20px; border-radius: 8px; border: 1px solid var(--cyan);">
<h4 style="color: var(--cyan); margin-bottom: 15px; font-size: 0.9em;">Visualizing Semantic Vector Math: King - Man + Woman β‰ˆ Queen</h4>
<svg viewBox="0 0 400 200" style="width: 100%; height: auto;">
<!-- Axes -->
<line x1="20" y1="180" x2="380" y2="180" stroke="var(--text-dim)" stroke-width="1" />
<line x1="20" y1="20" x2="20" y2="180" stroke="var(--text-dim)" stroke-width="1" />
<!-- Man to King -->
<circle cx="60" cy="140" r="4" fill="var(--orange)" />
<text x="70" y="145" fill="var(--text)" font-size="12">Man</text>
<line x1="60" y1="140" x2="160" y2="60" stroke="var(--orange)" stroke-width="2" stroke-dasharray="4" />
<circle cx="160" cy="60" r="4" fill="var(--orange)" />
<text x="170" y="65" fill="var(--text)" font-size="12">King</text>
<!-- Woman to Queen -->
<circle cx="150" cy="160" r="4" fill="var(--cyan)" />
<text x="160" y="165" fill="var(--text)" font-size="12">Woman</text>
<line x1="150" y1="160" x2="250" y2="80" stroke="var(--cyan)" stroke-width="2" stroke-dasharray="4" />
<circle cx="250" cy="80" r="4" fill="var(--cyan)" />
<text x="260" y="85" fill="var(--text)" font-size="12">Queen</text>
<!-- Relationship Vector -->
<path d="M 60 140 L 150 160" stroke="var(--green)" stroke-width="1" marker-end="url(#arrow)" />
<path d="M 160 60 L 250 80" stroke="var(--green)" stroke-width="1" marker-end="url(#arrow)" />
<defs>
<marker id="arrow" markerWidth="10" markerHeight="10" refX="0" refY="3" orient="auto" markerUnits="strokeWidth">
<path d="M0,0 L0,6 L9,3 z" fill="var(--green)" />
</marker>
</defs>
</svg>
<p style="font-size: 0.8em; color: var(--text-dim); margin-top: 10px;">The relationship vector (Gender) is consistently mapped across different nouns.</p>
</div>
<div class="visual-demo" style="margin-top: 20px; background: rgba(0,0,0,0.2); padding: 20px; border-radius: 8px; border: 1px solid var(--orange);">
<h4 style="color: var(--orange); margin-bottom: 15px; font-size: 0.9em;">Latent Space Clustering</h4>
<svg viewBox="0 0 400 150" style="width: 100%; height: auto;">
<!-- Cluster 1: Fruit -->
<g>
<circle cx="80" cy="70" r="30" fill="var(--cyan)" opacity="0.1" />
<circle cx="70" cy="60" r="3" fill="var(--cyan)" /> <text x="75" y="62" fill="var(--text-dim)" font-size="10">Apple</text>
<circle cx="90" cy="80" r="3" fill="var(--cyan)" /> <text x="95" y="82" fill="var(--text-dim)" font-size="10">Banana</text>
<circle cx="65" cy="85" r="3" fill="var(--cyan)" /> <text x="50" y="95" fill="var(--text-dim)" font-size="10">Orange</text>
</g>
<!-- Cluster 2: Transport -->
<g>
<circle cx="280" cy="80" r="35" fill="var(--orange)" opacity="0.1" />
<circle cx="270" cy="70" r="3" fill="var(--orange)" /> <text x="275" y="72" fill="var(--text-dim)" font-size="10">Car</text>
<circle cx="300" cy="90" r="3" fill="var(--orange)" /> <text x="305" y="92" fill="var(--text-dim)" font-size="10">Truck</text>
<circle cx="260" cy="100" r="3" fill="var(--orange)" /> <text x="240" y="115" fill="var(--text-dim)" font-size="10">Airplane</text>
</g>
</svg>
<p style="font-size: 0.8em; color: var(--text-dim); margin-top: 10px;">Embeddings naturally group semantically similar concepts together in vector clusters.</p>
</div>
</div>
</div>
<div class="list-item">
<div class="list-num">03</div>
<div>
<strong>The RNN Vanishing Gradient:</strong> Recurrent architectures process tokens sequentially, leading to information loss. Transformers solve this by processing all tokens simultaneously.
<div class="visual-demo" style="margin-top: 15px; background: rgba(0,0,0,0.2); padding: 15px; border-radius: 8px; border: 1px solid #e74c3c;">
<h4 style="color: #e74c3c; margin-bottom: 10px; font-size: 0.85em;">Sequential (RNN) vs. Parallel (Transformer)</h4>
<svg viewBox="0 0 400 150" style="width: 100%; height: auto;">
<!-- RNN Part -->
<text x="20" y="25" fill="#e74c3c" font-size="10" font-weight="bold">RNN (Bottleneck)</text>
<rect x="20" y="40" width="30" height="20" rx="2" fill="var(--surface)" stroke="var(--text-dim)" />
<path d="M 50 50 L 70 50" stroke="var(--text-dim)" marker-end="url(#arrow-red)" />
<rect x="70" y="40" width="30" height="20" rx="2" fill="var(--surface)" stroke="var(--text-dim)" />
<path d="M 100 50 L 120 50" stroke="#e74c3c" stroke-width="2" marker-end="url(#arrow-red)" />
<text x="125" y="55" fill="#e74c3c" font-size="20">...</text>
<!-- Transformer Part -->
<text x="220" y="25" fill="var(--cyan)" font-size="10" font-weight="bold">Transformer (All-at-once)</text>
<rect x="220" y="40" width="20" height="15" rx="1" fill="var(--cyan)" opacity="0.3" />
<rect x="250" y="40" width="20" height="15" rx="1" fill="var(--cyan)" opacity="0.3" />
<rect x="280" y="40" width="20" height="15" rx="1" fill="var(--cyan)" opacity="0.3" />
<path d="M 230 55 L 290 85" stroke="var(--cyan)" opacity="0.4" />
<path d="M 260 55 L 290 85" stroke="var(--cyan)" opacity="0.4" />
<path d="M 290 55 L 290 85" stroke="var(--cyan)" opacity="0.8" />
<rect x="220" y="85" width="100" height="40" rx="4" fill="var(--surface)" stroke="var(--cyan)" />
<text x="235" y="110" fill="var(--cyan)" font-size="12">Attention Layer</text>
</svg>
<p style="font-size: 0.75em; color: var(--text-dim);">Transformers eliminate the time-step dependency, removing the "forgetting" bottleneck of RNNs.</p>
</div>
</div>
</div>
<div class="list-item">
<div class="list-num">04</div>
<div>
<strong>Self-Attention Mechanism:</strong> The dynamic computation of weights via Query (Q), Key (K), and Value (V) projections.
<div class="visual-demo" style="margin-top: 15px; background: rgba(0,0,0,0.2); padding: 15px; border-radius: 8px; border: 1px solid var(--yellow);">
<h4 style="color: var(--yellow); margin-bottom: 10px; font-size: 0.85em;">Query, Key, and Value Interaction</h4>
<svg viewBox="0 0 400 150" style="width: 100%; height: auto;">
<!-- Q, K, V nodes -->
<circle cx="50" cy="40" r="15" fill="var(--cyan)" /> <text x="45" y="45" fill="var(--bg)" font-weight="bold">Q</text>
<circle cx="150" cy="40" r="15" fill="var(--orange)" /> <text x="145" y="45" fill="var(--bg)" font-weight="bold">K</text>
<circle cx="250" cy="40" r="15" fill="var(--green)" /> <text x="145" y="45" fill="var(--bg)" font-weight="bold" /> <text x="245" y="45" fill="var(--bg)" font-weight="bold">V</text>
<!-- Dot product -->
<path d="M 65 40 L 135 40" stroke="var(--yellow)" stroke-width="2" marker-end="url(#arrow-yellow)" />
<text x="75" y="30" fill="var(--yellow)" font-size="10">Internal product (Score)</text>
<!-- Weighted Sum -->
<path d="M 165 40 L 235 40" stroke="var(--text-dim)" opacity="0.5" />
<path d="M 150 55 L 200 100" stroke="var(--yellow)" marker-end="url(#arrow-yellow)" />
<path d="M 250 55 L 210 100" stroke="var(--green)" marker-end="url(#arrow-green)" />
<rect x="170" y="105" width="60" height="30" rx="4" fill="var(--surface)" stroke="var(--yellow)" />
<text x="182" y="125" fill="var(--text)" font-size="10">Context Z</text>
</svg>
<p style="font-size: 0.75em; color: var(--text-dim);">The Query looks for specific information in the Keys. The score determines how much of the Value is retrieved.</p>
</div>
</div>
</div>
`,
math: `
<h3>The Self-Attention Equation</h3>
<p>The core mathematical breakthrough that allows parallel processing of context is the Scaled Dot-Product Attention equation.</p>
<div class="formula">
$$ \\text{Attention}(Q, K, V) = \\text{softmax}\\left( \\frac{QK^T}{\\sqrt{d_k}} \\right) V $$
</div>
<div style="text-align: left; max-width: 600px; margin: 0 auto; color: var(--text-dim);">
<p><strong>Query (Q):</strong> What the current token is looking for.</p>
<p><strong>Key (K):</strong> What other tokens offer.</p>
<p><strong>Value (V):</strong> The actual information represented by the token.</p>
<p><strong>$\\sqrt{d_k}$:</strong> A scaling factor to prevent gradients from disappearing during softmax.</p>
</div>
`,
code: `
<span class="code-title">πŸ“„ attention.py</span>
<div class="code-block"><span class="keyword">import</span> torch
<span class="keyword">import</span> torch.nn.functional <span class="keyword">as</span> F
<span class="keyword">import</span> math
<span class="keyword">def</span> <span class="function">scaled_dot_product_attention</span>(Q, K, V, mask=<span class="keyword">None</span>):
<span class="string">"""
Compute 'Scaled Dot Product Attention'
"""</span>
d_k = Q.size(-<span class="number">1</span>)
<span class="comment"># 1. Compute dot product (scores)</span>
scores = torch.matmul(Q, K.transpose(-<span class="number">2</span>, -<span class="number">1</span>)) / math.sqrt(d_k)
<span class="comment"># 2. Apply masking (essential for autoregressive generation)</span>
<span class="keyword">if</span> mask <span class="keyword">is</span> <span class="keyword">not</span> <span class="keyword">None</span>:
scores = scores.masked_fill(mask == <span class="number">0</span>, -<span class="number">1e9</span>)
<span class="comment"># 3. Softmax to get probabilities/attention weights</span>
attention_weights = F.softmax(scores, dim=-<span class="number">1</span>)
<span class="comment"># 4. Multiply by values</span>
output = torch.matmul(attention_weights, V)
<span class="keyword">return</span> output, attention_weights</div>
`
},
"lecture-2": {
overview: `
<p>The original Transformer architecture has been significantly optimized. This module explores how researchers modified Attention constraints to build faster, larger foundation models.</p>
<div class="info-box">
<div class="box-title">Evolution of the Transformer</div>
<div class="box-content">
While the original 2017 architecture contained both an <strong>Encoder</strong> and a <strong>Decoder</strong>, modern models generally specialize: BERT uses only the Encoder for classification/understanding, while GPT uses only the Decoder for generative text.
</div>
</div>
`,
concepts: `
<h3>Architectural Optimizations</h3>
<div class="list-item">
<div class="list-num">01</div>
<div><strong>Multi-Head Attention (MHA):</strong> By projecting Q, K, and V into multiple lower-dimensional "heads," the model can attend to information from different representation subspaces simultaneously. One head might focus on syntax, while another focuses on sentiment.</div>
</div>
<div><strong>Multi-Head Attention (MHA):</strong> By projecting Q, K, and V into multiple lower-dimensional "heads," the model can attend to information from different representation subspaces simultaneously. One head might focus on syntax, while another focuses on sentiment.</div>
</div>
<div class="list-item">
<div class="list-num">03</div>
<div>
<strong>KV Cache & GQA:</strong> Autoregressive generation requires re-calculating attention. Grouped-Query Attention (GQA) reduces memory bandwidth.
<div class="visual-demo" style="margin-top: 15px; background: rgba(0,0,0,0.2); padding: 15px; border-radius: 8px; border: 1px solid var(--cyan);">
<h4 style="color: var(--cyan); margin-bottom: 10px; font-size: 0.85em;">Head Grouping: MHA vs GQA</h4>
<svg viewBox="0 0 400 120" style="width: 100%; height: auto;">
<!-- MHA -->
<text x="20" y="20" fill="var(--text-dim)" font-size="10">MHA (1:1)</text>
<rect x="25" y="30" width="10" height="10" fill="var(--cyan)" /> <line x1="35" y1="35" x2="55" y2="35" stroke="var(--orange)" /> <rect x="55" y="30" width="10" height="10" fill="var(--orange)" />
<rect x="25" y="45" width="10" height="10" fill="var(--cyan)" /> <line x1="35" y1="50" x2="55" y2="50" stroke="var(--orange)" /> <rect x="55" y="45" width="10" height="10" fill="var(--orange)" />
<!-- GQA -->
<text x="220" y="20" fill="var(--cyan)" font-size="10">GQA (Many-to-One)</text>
<rect x="225" y="30" width="10" height="10" fill="var(--cyan)" />
<rect x="225" y="45" width="10" height="10" fill="var(--cyan)" />
<rect x="225" y="60" width="10" height="10" fill="var(--cyan)" />
<path d="M 235 35 L 265 50" stroke="var(--orange)" />
<path d="M 235 50 L 265 50" stroke="var(--orange)" />
<path d="M 235 65 L 265 50" stroke="var(--orange)" />
<rect x="265" y="45" width="10" height="10" fill="var(--orange)" />
</svg>
<p style="font-size: 0.75em; color: var(--text-dim);">GQA shares Key/Value heads across multiple Query heads, drastically reducing the KV Cache memory footprint.</p>
</div>
</div>
</div>
<div class="list-item">
<div class="list-num">03</div>
<div>
<strong>RoPE (Rotary Position Embeddings):</strong> Relative distance encoded as rotations in the complex plane.
<div class="visual-demo" style="margin-top: 15px; background: rgba(0,0,0,0.2); padding: 15px; border-radius: 8px; border: 1px solid var(--orange);">
<h4 style="color: var(--orange); margin-bottom: 10px; font-size: 0.85em;">RoPE: Rotation in Latent Space</h4>
<svg viewBox="0 0 400 120" style="width: 100%; height: auto;">
<!-- Coordinate System -->
<circle cx="200" cy="60" r="40" fill="none" stroke="var(--text-dim)" opacity="0.3" stroke-dasharray="2" />
<line x1="160" y1="60" x2="240" y2="60" stroke="var(--text-dim)" opacity="0.5" />
<line x1="200" y1="20" x2="200" y2="100" stroke="var(--text-dim)" opacity="0.5" />
<!-- Vector 1 -->
<line x1="200" y1="60" x2="235" y2="40" stroke="var(--cyan)" stroke-width="2" marker-end="url(#arrow-cyan)" />
<text x="240" y="45" fill="var(--cyan)" font-size="10">Pos 1 (ΞΈ)</text>
<!-- Vector 2 -->
<line x1="200" y1="60" x2="180" y2="25" stroke="var(--orange)" stroke-width="2" marker-end="url(#arrow-orange)" />
<text x="160" y="25" fill="var(--orange)" font-size="10">Pos 2 (2ΞΈ)</text>
</svg>
<p style="font-size: 0.75em; color: var(--text-dim);">Position is encoded as a rotation angle. The dot product between rotated vectors naturally captures relative distance.</p>
</div>
</div>
</div>
<div class="list-item">
<div class="list-num">04</div>
<div>
<strong>Normalization (RMSNorm):</strong> Faster weight stabilization.
<div class="visual-demo" style="margin-top: 15px; background: rgba(0,0,0,0.2); padding: 15px; border-radius: 8px; border: 1px solid var(--cyan);">
<h4 style="color: var(--cyan); margin-bottom: 10px; font-size: 0.85em;">RMSNorm vs LayerNorm</h4>
<svg viewBox="0 0 400 100" style="width: 100%; height: auto;">
<rect x="50" y="30" width="100" height="40" fill="var(--surface)" stroke="var(--text-dim)" />
<text x="60" y="55" fill="var(--text-dim)" font-size="10">Mean + Var</text>
<path d="M 160 50 L 200 50" stroke="var(--text-dim)" marker-end="url(#arrow-dim)" />
<rect x="210" y="30" width="100" height="40" fill="rgba(0, 212, 255, 0.1)" stroke="var(--cyan)" />
<text x="220" y="55" fill="var(--cyan)" font-size="10">RMS Scaling Only</text>
</svg>
<p style="font-size: 0.75em; color: var(--text-dim);">RMSNorm removes the mean-centering step, making it computationally faster for high-throughput models.</p>
</div>
</div>
</div>
`
},
"lecture-3": {
overview: `
<p>What makes an LLM "Large" and how do we extract the best performance out of it? This module rips open the generative engine inside models like GPT-4, Llama 3, and Claude.</p>
`,
concepts: `
<h3>LLM Internals & Inference</h3>
<div class="list-item">
<div class="list-num">01</div>
<div>
<strong>Mixture of Experts (MoE):</strong> Scaling model capacity without scaling compute. For each token, a "Router" selects a subset of "Experts."
<div class="visual-demo" style="margin-top: 15px; background: rgba(0,0,0,0.2); padding: 15px; border-radius: 8px; border: 1px solid var(--green);">
<h4 style="color: var(--green); margin-bottom: 10px; font-size: 0.85em;">Sparse Expert Routing (MoE)</h4>
<svg viewBox="0 0 400 120" style="width: 100%; height: auto;">
<rect x="60" y="45" width="60" height="40" rx="4" fill="var(--surface)" stroke="var(--cyan)" />
<text x="70" y="70" fill="var(--cyan)" font-size="12">Router</text>
<line x1="120" y1="65" x2="200" y2="35" stroke="var(--green)" stroke-width="2" marker-end="url(#arrow-green)" />
<line x1="120" y1="65" x2="200" y2="95" stroke="var(--green)" stroke-width="2" marker-end="url(#arrow-green)" />
<rect x="200" y="20" width="80" height="30" rx="2" fill="rgba(46, 204, 113, 0.2)" stroke="var(--green)" />
<text x="215" y="40" fill="var(--text)" font-size="10">Expert 1</text>
<rect x="200" y="80" width="80" height="30" rx="2" fill="rgba(46, 204, 113, 0.2)" stroke="var(--green)" />
<text x="215" y="100" fill="var(--text)" font-size="10">Expert N</text>
</svg>
<p style="font-size: 0.75em; color: var(--text-dim);">The Router only activates the most relevant Feed-Forward networks for each specific token.</p>
</div>
</div>
</div>
<div class="list-item">
<div class="list-num">02</div>
<div>
<strong>KV Cache Management (vLLM):</strong> Efficient memory allocation.
<div class="visual-demo" style="margin-top: 15px; background: rgba(0,0,0,0.2); padding: 15px; border-radius: 8px; border: 1px solid var(--orange);">
<h4 style="color: var(--orange); margin-bottom: 10px; font-size: 0.85em;">PagedAttention: Virtual Memory for LLMs</h4>
<svg viewBox="0 0 400 100" style="width: 100%; height: auto;">
<rect x="20" y="30" width="30" height="30" fill="var(--orange)" opacity="0.8" />
<rect x="55" y="30" width="30" height="30" fill="var(--orange)" opacity="0.4" />
<path d="M 35 65 L 150 80" stroke="var(--orange)" stroke-dasharray="2" />
<path d="M 70 65 L 220 50" stroke="var(--orange)" stroke-dasharray="2" />
<rect x="150" y="65" width="25" height="25" fill="var(--orange)" opacity="0.8" />
<rect x="180" y="35" width="25" height="25" fill="var(--surface)" stroke="var(--text-dim)" />
<rect x="210" y="35" width="25" height="25" fill="var(--orange)" opacity="0.4" />
</svg>
<p style="font-size: 0.75em; color: var(--text-dim);">Non-contiguous memory slots are mapped to the sequence, eliminating waste and internal fragmentation.</p>
</div>
</div>
</div>
<div class="list-item">
<div class="list-num">03</div>
<div>
<strong>Continuous Batching:</strong> Dynamic request handling in production.
<div class="visual-demo" style="margin-top: 15px; background: rgba(0,0,0,0.2); padding: 15px; border-radius: 8px; border: 1px solid var(--green);">
<h4 style="color: var(--green); margin-bottom: 10px; font-size: 0.85em;">Static vs. Continuous Batching</h4>
<svg viewBox="0 0 400 120" style="width: 100%; height: auto;">
<!-- Static -->
<text x="20" y="20" fill="var(--text-dim)" font-size="10">Static (Wait for all)</text>
<rect x="25" y="30" width="100" height="20" fill="rgba(231, 76, 60, 0.3)" stroke="#e74c3c" />
<text x="35" y="44" fill="var(--text)" font-size="9">Req A, B, C...</text>
<!-- Continuous -->
<text x="220" y="20" fill="var(--green)" font-size="10">Continuous (Fill voids)</text>
<rect x="225" y="30" width="60" height="20" fill="var(--green)" opacity="0.3" stroke="var(--green)" />
<text x="230" y="44" fill="var(--text)" font-size="9">Req A (End)</text>
<rect x="290" y="30" width="60" height="20" fill="var(--cyan)" opacity="0.3" stroke="var(--cyan)" />
<text x="295" y="44" fill="var(--text)" font-size="9">Req D (New)</text>
<path d="M 285 55 L 290 30" stroke="var(--green)" stroke-dasharray="2" marker-end="url(#arrow-green)" />
</svg>
<p style="font-size: 0.75em; color: var(--text-dim);">Continuous batching injects new requests into the batch as soon as others finish, maximizing GPU utilization.</p>
</div>
</div>
</div>
<div class="list-item">
<div class="list-num">04</div>
<div>
<strong>Temperature & Sampling:</strong> Probability sharpening.
<div class="visual-demo" style="margin-top: 15px; background: rgba(0,0,0,0.2); padding: 15px; border-radius: 8px; border: 1px solid var(--orange);">
<h4 style="color: var(--orange); margin-bottom: 10px; font-size: 0.85em;">Effect of Temperature (T)</h4>
<svg viewBox="0 0 400 100" style="width: 100%; height: auto;">
<!-- T=0.1 -->
<text x="20" y="20" fill="var(--text-dim)" font-size="10">T=0.1 (Factual)</text>
<path d="M 25 80 L 40 20 L 55 80" stroke="var(--orange)" stroke-width="2" fill="none" />
<text x="35" y="95" fill="var(--orange)" font-size="9">Sharp Peak</text>
<!-- T=1.0 -->
<text x="160" y="20" fill="var(--text-dim)" font-size="10">T=1.0 (Balanced)</text>
<path d="M 165 80 Q 200 40 235 80" stroke="var(--cyan)" stroke-width="2" fill="none" />
<!-- T=2.0 -->
<text x="300" y="20" fill="var(--text-dim)" font-size="10">T=2.0 (Creative)</text>
<path d="M 305 75 Q 350 70 395 75" stroke="#e74c3c" stroke-width="2" fill="none" />
<text x="315" y="95" fill="#e74c3c" font-size="9">Uniform/Flat</text>
</svg>
<p style="font-size: 0.75em; color: var(--text-dim);">Low temperature concentrates probability on the top token; high temperature distributes it across many options.</p>
</div>
</div>
</div>
<div class="list-item">
<div class="list-num">05</div>
<div>
<strong>Few-Shot Prompting:</strong> In-context learning via demonstration.
<div class="visual-demo" style="margin-top: 15px; background: rgba(0,0,0,0.3); padding: 15px; border-radius: 8px; border: 1px solid var(--cyan);">
<h4 style="color: var(--cyan); margin-bottom: 10px; font-size: 0.85em;">Few-Shot Prompt Structure</h4>
<svg viewBox="0 0 400 100" style="width: 100%; height: auto;">
<rect x="20" y="10" width="360" height="80" rx="4" fill="var(--surface)" stroke="var(--cyan)" />
<text x="30" y="30" fill="var(--text)" font-size="10">Input: Dog -> Output: Animal</text>
<text x="30" y="50" fill="var(--text)" font-size="10">Input: Car -> Output: Transport</text>
<line x1="30" y1="60" x2="370" y2="60" stroke="var(--cyan)" opacity="0.3" />
<text x="30" y="80" fill="var(--orange)" font-size="10" font-weight="bold">Input: Apple -> Output: [Model Predicts...]</text>
</svg>
</div>
</div>
</div>
<div class="list-item">
<div class="list-num">06</div>
<div>
<strong>Chain of Thought (CoT):</strong> Step-by-step logic exploration.
<div class="visual-demo" style="margin-top: 15px; background: rgba(0,0,0,0.2); padding: 15px; border-radius: 8px; border: 1px solid var(--yellow);">
<h4 style="color: var(--yellow); margin-bottom: 10px; font-size: 0.85em;">Reasoning Search Tree</h4>
<svg viewBox="0 0 400 120" style="width: 100%; height: auto;">
<circle cx="200" cy="20" r="10" fill="var(--cyan)" />
<path d="M 195 30 L 150 60" stroke="var(--yellow)" />
<path d="M 205 30 L 250 60" stroke="var(--yellow)" />
<circle cx="150" cy="70" r="10" fill="var(--surface)" stroke="var(--yellow)" />
<circle cx="250" cy="70" r="10" fill="var(--green)" />
<path d="M 250 80 L 250 100" stroke="var(--green)" marker-end="url(#arrow-green)" />
<text x="210" y="115" fill="var(--green)" font-size="10">Optimal Logic Path Found</text>
</svg>
<p style="font-size: 0.75em; color: var(--text-dim);">The model explores paths (thoughts), rejects bad ones, and follows the correct logical chain.</p>
</div>
</div>
</div>
`,
math:`
<h3>Sampling using Temperature</h3>
<div class="formula">
$$ p_i = \\frac{e^{z_i / T}}{\\sum_j e^{z_j / T}} $$
</div>
<p style="text-align: center; color: var(--text-dim);">
Where $T$ is the temperature parameter. As $T \\to 0$, it becomes a deterministic $\\max$ operation.<br>
As $T \\to \\infty$, the distribution becomes uniform across all possible tokens.
</p>
`
},
"lecture-4": {
overview: `
<p>How are these giant models built? The lifecycle of training a Foundation Model spans months and costs millions.</p>
`,
concepts: `
<h3>Pretraining & Scaling Deep Dive</h3>
<div class="list-item">
<div class="list-num">01</div>
<div>
<strong>Scaling Laws (Chinchilla):</strong> The relationship between Parameters (N) and Data (D).
<div class="visual-demo" style="margin-top: 15px; background: rgba(0,0,0,0.2); padding: 15px; border-radius: 8px; border: 1px solid var(--cyan);">
<h4 style="color: var(--cyan); margin-bottom: 10px; font-size: 0.85em;">Chinchilla Compute-Optimal Frontier</h4>
<svg viewBox="0 0 400 150" style="width: 100%; height: auto;">
<!-- Axes -->
<line x1="40" y1="120" x2="360" y2="120" stroke="var(--text-dim)" />
<line x1="40" y1="20" x2="40" y2="120" stroke="var(--text-dim)" />
<text x="300" y="140" fill="var(--text-dim)" font-size="9">Tokens (D)</text>
<text x="10" y="20" fill="var(--text-dim)" font-size="9" transform="rotate(-90 40 20)">Loss</text>
<!-- Log Curves -->
<path d="M 50 110 Q 150 40 350 30" fill="none" stroke="var(--cyan)" stroke-width="2" />
<circle cx="200" cy="50" r="4" fill="var(--orange)" />
<text x="210" y="55" fill="var(--orange)" font-size="10">Optimal Balance</text>
</svg>
<p style="font-size: 0.75em; color: var(--text-dim);">Tokens and Parameters should be scaled equally for a given compute budget.</p>
</div>
</div>
</div>
<div class="list-item">
<div class="list-num">02</div>
<div>
<strong>Data Mixing & Quality:</strong> The "garbage in, garbage out" rule.
<div class="visual-demo" style="margin-top: 15px; background: rgba(0,0,0,0.2); padding: 15px; border-radius: 8px; border: 1px solid var(--green);">
<h4 style="color: var(--green); margin-bottom: 10px; font-size: 0.85em;">Data Hygiene Pipeline</h4>
<svg viewBox="0 0 400 120" style="width: 100%; height: auto;">
<text x="20" y="20" fill="var(--text-dim)" font-size="10">Raw Web (Petabytes)</text>
<rect x="20" y="30" width="60" height="40" fill="var(--surface)" stroke="var(--text-dim)" />
<path d="M 80 50 L 120 50" stroke="var(--text-dim)" marker-end="url(#arrow-dim)" />
<rect x="120" y="30" width="100" height="40" rx="4" fill="var(--surface)" stroke="var(--cyan)" />
<text x="125" y="55" fill="var(--cyan)" font-size="10">Dedupe (MinHash)</text>
<path d="M 220 50 L 260 50" stroke="var(--text-dim)" marker-end="url(#arrow-dim)" />
<rect x="260" y="30" width="100" height="40" rx="4" fill="rgba(46, 204, 113, 0.2)" stroke="var(--green)" />
<text x="268" y="55" fill="var(--text)" font-size="10">Quality Classifier</text>
<path d="M 360 50 L 380 50" stroke="var(--green)" marker-end="url(#arrow-green)" />
</svg>
<p style="font-size: 0.75em; color: var(--text-dim);">Filtering removes 90% of raw data to ensure only high-quality information reaches the model.</p>
</div>
</div>
</div>
<div class="list-item">
<div class="list-num">03</div>
<div>
<strong>Learning Rate Schedules:</strong> Maintaining training stability.
<div class="visual-demo" style="margin-top: 15px; background: rgba(0,0,0,0.2); padding: 15px; border-radius: 8px; border: 1px solid var(--orange);">
<h4 style="color: var(--orange); margin-bottom: 10px; font-size: 0.85em;">Cosine Decay with Warmup</h4>
<svg viewBox="0 0 400 120" style="width: 100%; height: auto;">
<line x1="40" y1="100" x2="360" y2="100" stroke="var(--text-dim)" />
<line x1="40" y1="20" x2="40" y2="100" stroke="var(--text-dim)" />
<path d="M 40 100 L 80 30 Q 200 30 360 100" fill="none" stroke="var(--orange)" stroke-width="2" />
<text x="45" y="45" fill="var(--orange)" font-size="8">Warmup</text>
<text x="180" y="45" fill="var(--orange)" font-size="8">Cosine Decay</text>
<text x="300" y="115" fill="var(--text-dim)" font-size="9">Training Steps</text>
</svg>
</div>
</div>
</div>
<div class="list-item">
<div class="list-num">04</div>
<div>
<strong>3D Parallelism:</strong> Splitting the model across huge H100 clusters.
<div class="visual-demo" style="margin-top: 15px; background: rgba(0,0,0,0.2); padding: 15px; border-radius: 8px; border: 1px solid var(--cyan);">
<h4 style="color: var(--cyan); margin-bottom: 10px; font-size: 0.85em;">Tensor vs. Pipeline vs. Data Parallelism</h4>
<svg viewBox="0 0 400 120" style="width: 100%; height: auto;">
<!-- Data Parallelism -->
<rect x="20" y="20" width="30" height="30" fill="var(--cyan)" opacity="0.3" stroke="var(--cyan)" />
<rect x="20" y="60" width="30" height="30" fill="var(--cyan)" opacity="0.3" stroke="var(--cyan)" />
<text x="20" y="105" fill="var(--cyan)" font-size="8">Data Par (Batch)</text>
<!-- Pipeline Parallelism -->
<rect x="150" y="40" width="30" height="30" fill="var(--orange)" opacity="0.4" />
<path d="M 180 55 L 210 55" stroke="var(--orange)" marker-end="url(#arrow-orange)" />
<rect x="210" y="40" width="30" height="30" fill="var(--orange)" opacity="0.6" />
<text x="160" y="105" fill="var(--orange)" font-size="8">Pipeline Par (Layers)</text>
<!-- Tensor Parallelism -->
<rect x="300" y="40" width="60" height="15" fill="rgba(163, 113, 247, 0.5)" stroke="var(--cyan)" />
<rect x="300" y="60" width="60" height="15" fill="rgba(163, 113, 247, 0.5)" stroke="var(--cyan)" />
<text x="300" y="105" fill="var(--cyan)" font-size="8">Tensor Par (Weights)</text>
</svg>
</div>
</div>
</div>
`
},
"lecture-5": {
overview: `
<p>Even an SFT model might generate harmful, politically biased, or unsafe answers. Alignment refers to shaping the model's outputs to heavily mirror human preferences.</p>
`,
concepts: `
<h3>Fine-Tuning & Alignment</h3>
<div class="list-item">
<div class="list-num">01</div>
<div><strong>SFT (Supervised Fine-Tuning):</strong> Converting a "next-token predictor" into a "helpful assistant." The model is trained on (Prompt, Completion) pairs. This stage teaches the model the "Instruction Following" format and the appropriate tone for interaction.</div>
</div>
<div class="list-item">
<div class="list-num">02</div>
<div><strong>PEFT (Parameter-Efficient Fine-Tuning):</strong> Techniques like LoRA (Low-Rank Adaptation) freeze the base weights and only train a small subset of "delta" weights. This reduces the VRAM requirement by 100x and allows multiple specialized models to share the same base weights in memory.</div>
</div>
<div class="list-item">
<div class="list-num">03</div>
<div>
<strong>Alignment (RLHF & DPO):</strong> Shaping behavior to match human values.
<div class="visual-demo" style="margin-top: 15px; background: rgba(0,0,0,0.2); padding: 15px; border-radius: 8px; border: 1px solid var(--orange);">
<h4 style="color: var(--orange); margin-bottom: 10px; font-size: 0.85em;">The Alignment Lifecycle (RLHF)</h4>
<svg viewBox="0 0 400 120" style="width: 100%; height: auto;">
<!-- Lifecycle Nodes -->
<rect x="20" y="45" width="60" height="30" rx="2" fill="var(--surface)" stroke="var(--cyan)" />
<text x="35" y="65" fill="var(--text)" font-size="10">SFT</text>
<path d="M 80 60 L 120 60" stroke="var(--text-dim)" marker-end="url(#arrow-dim)" />
<rect x="120" y="45" width="100" height="30" rx="2" fill="var(--surface)" stroke="#e74c3c" />
<text x="130" y="65" fill="var(--text)" font-size="10">Reward Model</text>
<path d="M 220 60 L 260 60" stroke="var(--text-dim)" marker-end="url(#arrow-dim)" />
<rect x="260" y="45" width="100" height="30" rx="2" fill="rgba(46, 204, 113, 0.2)" stroke="var(--green)" />
<text x="275" y="65" fill="var(--text)" font-size="10">PPO / DPO</text>
<!-- Feedback loop -->
<path d="M 310 45 Q 200 0 50 45" fill="none" stroke="var(--green)" stroke-dasharray="2" marker-end="url(#arrow-green)" />
</svg>
<p style="font-size: 0.75em; color: var(--text-dim);">Alignment fine-tunes the base model to prioritize helpfulness and safety based on preference data.</p>
</div>
</div>
</div>
<div class="list-item">
<div class="list-num">04</div>
<div><strong>Catastrophic Forgetting:</strong> A major challenge in fine-tuning where a model loses its general knowledge (pretraining facts) while learning a specific task. Mitigation strategies includes lower learning rates and mixing in pretraining data during the fine-tuning phase.</div>
</div>
`
},
"lecture-6": {
overview: `
<p>Generative modeling reaches its ceiling when answers require long planning steps. "Reasoning Models" (like DeepSeek R1 and OpenAI o1) use RL to develop an inner monologue.</p>
<div class="callout tip">
<div class="callout-title">System 1 vs System 2</div>
Standard LLMs are "System 1" (instinctual, fast reflexes). Reasoning models unlock "System 2" (methodical, slow, deep thinking).
</div>
`,
concepts: `
<h3>Logic, Math & Verification</h3>
<div class="list-item">
<div class="list-num">01</div>
<div>
<strong>Reasoning Trajectories:</strong> Spending "test-time compute" to solve complex problems.
<div class="visual-demo" style="margin-top: 15px; background: rgba(0,0,0,0.2); padding: 15px; border-radius: 8px; border: 1px solid var(--cyan);">
<h4 style="color: var(--cyan); margin-bottom: 10px; font-size: 0.85em;">CoT vs. Reasoning Models (o1/R1)</h4>
<svg viewBox="0 0 400 120" style="width: 100%; height: auto;">
<!-- Prompt -->
<rect x="10" y="10" width="60" height="20" rx="2" fill="var(--surface)" stroke="var(--cyan)" />
<text x="18" y="25" fill="var(--text)" font-size="9">Prompt</text>
<!-- Hidden Trajectory -->
<path d="M 70 20 L 150 20 L 150 60 L 250 60" fill="none" stroke="var(--orange)" stroke-width="2" stroke-dasharray="3" />
<rect x="130" y="70" width="100" height="20" rx="2" fill="rgba(255, 170, 0, 0.1)" stroke="var(--orange)" />
<text x="140" y="85" fill="var(--orange)" font-size="8">Thinking Tokens...</text>
<!-- Output -->
<path d="M 230 80 L 320 80" stroke="var(--green)" marker-end="url(#arrow-green)" />
<rect x="320" y="70" width="60" height="25" rx="2" fill="rgba(46, 204, 113, 0.1)" stroke="var(--green)" />
<text x="335" y="85" fill="var(--text)" font-size="9">Answer</text>
</svg>
<p style="font-size: 0.75em; color: var(--text-dim);">Reasoning models explore multiple paths internally before committing to a final visible output.</p>
</div>
</div>
</div>
<div class="list-item">
<div class="list-num">02</div>
<div><strong>Verifiable Rewards (RL on Math/Code):</strong> Unlike subjective chat data, math and code have ground-truth answers. Reinforcement Learning can optimize a model purely on output verification (does it pass the test cases?), allowing the model to "learn to think" without human-labeled reasoning paths.</div>
</div>
<div class="list-item">
<div class="list-num">03</div>
<div><strong>AlphaCode & Strawberry Logic:</strong> Strategies for searching through potential solution spaces. The model generates many candidates, verifies them, and uses the correct ones to further tune its internal policy. This moves LLMs from "System 1" (instinctive) to "System 2" (deliberative) thinking.</div>
</div>
`
},
"lecture-7": {
overview: `
<p>An LLM is just a brain locked in a vault. Agentic frameworks give it the ability to connect to databases, browse the web, and execute actions.</p>
`,
concepts: `
<h3>Agent & Integration Paradigms</h3>
<div class="list-item">
<div class="list-num">01</div>
<div>
<strong>RAG (Retrieval-Augmented Generation):</strong> Connecting LLMs to private data via Vector DBs.
<div class="visual-demo" style="margin-top: 15px; background: rgba(0,0,0,0.2); padding: 15px; border-radius: 8px; border: 1px solid var(--cyan);">
<h4 style="color: var(--cyan); margin-bottom: 10px; font-size: 0.85em;">RAG Pipeline</h4>
<svg viewBox="0 0 400 80" style="width: 100%; height: auto;">
<rect x="20" y="25" width="60" height="30" fill="var(--surface)" stroke="var(--cyan)" />
<text x="35" y="45" fill="var(--cyan)" font-size="10">Query</text>
<path d="M 80 40 L 120 40" stroke="var(--text-dim)" marker-end="url(#arrow-dim)" />
<rect x="120" y="15" width="80" height="50" rx="2" fill="var(--surface)" stroke="var(--orange)" />
<text x="135" y="45" fill="var(--orange)" font-size="10">Vector DB</text>
<path d="M 200 40 L 250 40" stroke="var(--text-dim)" marker-end="url(#arrow-dim)" />
<rect x="250" y="15" width="100" height="50" rx="4" fill="var(--surface)" stroke="var(--green)" />
<text x="260" y="45" fill="var(--green)" font-size="10">Augmented Prompt</text>
</svg>
</div>
</div>
</div>
<div class="list-item">
<div class="list-num">02</div>
<div><strong>Function Calling (Tool Use):</strong> Models finetuned to halt generation and return a strictly formatted JSON specifying an API name and extracted parameters (e.g., <code>{"name":"get_weather", "location":"Boston"}</code>).</div>
</div>
<div class="list-item">
<div class="list-num">03</div>
<div>
<strong>The ReAct Pattern:</strong> The Thought β†’ Action β†’ Observation cycle.
<div class="visual-demo" style="margin-top: 15px; background: rgba(0,0,0,0.2); padding: 15px; border-radius: 8px; border: 1px solid var(--yellow);">
<h4 style="color: var(--yellow); margin-bottom: 10px; font-size: 0.85em;">Agentic ReAct Loop</h4>
<svg viewBox="0 0 400 120" style="width: 100%; height: auto;">
<!-- Circle of nodes -->
<circle cx="200" cy="30" r="15" fill="var(--cyan)" /> <text x="220" y="35" fill="var(--text)" font-size="10">Thought</text>
<circle cx="300" cy="80" r="15" fill="var(--orange)" /> <text x="320" y="85" fill="var(--text)" font-size="10">Action</text>
<circle cx="100" cy="80" r="15" fill="var(--green)" /> <text x="40" y="85" fill="var(--text)" font-size="10">Observation</text>
<!-- Connection arrows -->
<path d="M 215 35 Q 260 45 290 65" fill="none" stroke="var(--text-dim)" marker-end="url(#arrow-dim)" />
<path d="M 285 85 Q 200 100 115 85" fill="none" stroke="var(--text-dim)" marker-end="url(#arrow-dim)" />
<path d="M 110 65 Q 140 45 185 35" fill="none" stroke="var(--text-dim)" marker-end="url(#arrow-dim)" />
</svg>
</div>
</div>
</div>
`
},
"lecture-8": {
overview: `
<p>Evaluating an LLM's intelligence is extremely complex since language is subjective. This module covers benchmarks and the transition to algorithmic judges.</p>
`,
concepts: `
<h3>Benchmarks & Human Calibration</h3>
<div class="list-item">
<div class="list-num">01</div>
<div>
<strong>Chatbot Arena & Elo System:</strong> Crowdsourced human ranking.
<div class="visual-demo" style="margin-top: 15px; background: rgba(0,0,0,0.2); padding: 15px; border-radius: 8px; border: 1px solid var(--cyan);">
<h4 style="color: var(--cyan); margin-bottom: 10px; font-size: 0.85em;">LMSYS Arena Battle</h4>
<svg viewBox="0 0 400 100" style="width: 100%; height: auto;">
<rect x="40" y="30" width="100" height="50" rx="4" fill="var(--surface)" stroke="var(--cyan)" />
<text x="60" y="60" fill="var(--text)" font-size="10">Model A</text>
<text x="180" y="60" fill="var(--orange)" font-size="12" font-weight="bold">VS</text>
<rect x="260" y="30" width="100" height="50" rx="4" fill="var(--surface)" stroke="var(--green)" />
<text x="280" y="60" fill="var(--text)" font-size="10">Model B</text>
<path d="M 200 70 L 200 90" stroke="var(--text-dim)" marker-end="url(#arrow-dim)" />
<text x="165" y="105" fill="var(--text-dim)" font-size="9">Crowd Voting</text>
</svg>
</div>
</div>
</div>
<div class="list-item">
<div class="list-num">02</div>
<div><strong>Model Contamination:</strong> A critical issue where benchmark questions are accidentally included in the model's pretraining data (the model "memorizes" the test). Modern evals use private, fresh, or dynamically generated datasets to prevent this.</div>
</div>
<div class="list-item">
<div class="list-num">03</div>
<div><strong>Eval-as-a-Service:</strong> Tools like DeepEval or RAGAS focus on specific metrics for agents, such as Hallucination Rate, Factuality, and Context Adherence, rather than just general conversational quality.</div>
</div>
`
},
"lecture-9": {
overview: `
<p>The bleeding edge. The integration of image, audio, and generation models merging into singular foundation interfaces.</p>
`,
concepts: `
<h3>The Multi-Senses Architecture</h3>
<div class="list-item">
<div class="list-num">01</div>
<div>
<strong>Vision Transformers (ViT):</strong> "An Image is worth 16x16 words."
<div class="visual-demo" style="margin-top: 15px; background: rgba(0,0,0,0.2); padding: 15px; border-radius: 8px; border: 1px solid var(--cyan);">
<h4 style="color: var(--cyan); margin-bottom: 10px; font-size: 0.85em;">Image-to-Patch Tokenization</h4>
<svg viewBox="0 0 400 120" style="width: 100%; height: auto;">
<!-- Image Grid -->
<rect x="20" y="20" width="60" height="60" fill="var(--cyan)" opacity="0.1" stroke="var(--cyan)" />
<line x1="40" y1="20" x2="40" y2="80" stroke="var(--cyan)" opacity="0.3" />
<line x1="60" y1="20" x2="60" y2="80" stroke="var(--cyan)" opacity="0.3" />
<line x1="20" y1="40" x2="80" y2="40" stroke="var(--cyan)" opacity="0.3" />
<line x1="20" y1="60" x2="80" y2="60" stroke="var(--cyan)" opacity="0.3" />
<!-- Flattening -->
<path d="M 85 50 L 150 50" stroke="var(--text-dim)" marker-end="url(#arrow-dim)" />
<!-- Linear Projection -->
<rect x="160" y="40" width="20" height="20" fill="var(--cyan)" stroke="var(--cyan)" />
<rect x="190" y="40" width="20" height="20" fill="var(--cyan)" stroke="var(--cyan)" />
<rect x="220" y="40" width="20" height="20" fill="var(--cyan)" stroke="var(--cyan)" />
<text x="250" y="55" fill="var(--text-dim)" font-size="12">...</text>
<!-- Input to Transformer -->
<path d="M 170 35 L 250 15" stroke="var(--orange)" stroke-dasharray="2" />
<text x="260" y="20" fill="var(--orange)" font-size="10">Attention Ready</text>
</svg>
<p style="font-size: 0.75em; color: var(--text-dim);">Images are flattened into patches, enabling the same Transformer architecture to handle visual data as tokens.</p>
</div>
</div>
</div>
<div class="list-item">
<div class="list-num">02</div>
<div>
<strong>Contrastive Learning (CLIP):</strong> Creating the bridge between eyes and mind.
<div class="visual-demo" style="margin-top: 15px; background: rgba(0,0,0,0.2); padding: 15px; border-radius: 8px; border: 1px solid var(--orange);">
<h4 style="color: var(--orange); margin-bottom: 10px; font-size: 0.85em;">Dual-Encoder Alignment</h4>
<svg viewBox="0 0 400 120" style="width: 100%; height: auto;">
<rect x="40" y="20" width="60" height="30" fill="var(--surface)" stroke="var(--cyan)" />
<text x="50" y="40" fill="var(--cyan)" font-size="10">Text Enc</text>
<rect x="40" y="70" width="60" height="30" fill="var(--surface)" stroke="var(--orange)" />
<text x="50" y="90" fill="var(--orange)" font-size="10">Img Enc</text>
<path d="M 110 35 L 200 60" stroke="var(--cyan)" />
<path d="M 110 85 L 200 60" stroke="var(--orange)" />
<circle cx="210" cy="60" r="15" fill="var(--green)" />
<text x="230" y="65" fill="var(--green)" font-size="10">Joint Space</text>
</svg>
<p style="font-size: 0.75em; color: var(--text-dim);">By training on millions of image-caption pairs, CLIP learns a unified understanding across modalities.</p>
</div>
</div>
</div>
<div class="list-item">
<div class="list-num">03</div>
<div><strong>Autoregressive Vision:</strong> Future state where models generate pixels token-by-token (just like text) or use latent diffusion bridges to generate extremely consistent high-definition visual narratives.</div>
</div>
`
}
};
// --- Core Application Logic ---
function initDashboard() {
const grid = document.getElementById("modulesGrid");
const container = document.getElementById("modulesContainer");
modules.forEach((module, index) => {
const card = document.createElement("div");
card.className = "card";
card.style.borderColor = module.color;
card.onclick = () => switchTo(module.id + "-module");
card.innerHTML = `
<div class="card-icon">${module.icon}</div>
<h3>${module.title}</h3>
<p>${module.description}</p>
<span class="category-label" style="background: ${module.color}22; color: ${module.color};">${module.category}</span>
`;
grid.appendChild(card);
const moduleHTML = createModuleHTML(module);
container.innerHTML += moduleHTML;
});
}
function createModuleHTML(module) {
const content = MODULE_CONTENT[module.id] || {};
return `
<div class="module" id="${module.id}-module">
<button class="btn-back" onclick="switchTo('dashboard')">← Back to Dashboard</button>
<header>
<h1>${module.icon} ${module.title}</h1>
<p class="subtitle">${module.description}</p>
</header>
<div class="tabs">
<button class="tab-btn active" onclick="switchTab(event, '${module.id}-overview')">Overview</button>
<button class="tab-btn" onclick="switchTab(event, '${module.id}-concepts')">Key Concepts</button>
${content.math ? `<button class="tab-btn" onclick="switchTab(event, '${module.id}-math')">Math & Theory</button>` : ''}
${content.applications ? `<button class="tab-btn" onclick="switchTab(event, '${module.id}-applications')">Applications</button>` : ''}
${content.code ? `<button class="tab-btn" onclick="switchTab(event, '${module.id}-code')">Code</button>` : ''}
</div>
<div id="${module.id}-overview" class="tab active">
<div class="section">
<h2>πŸ“– Overview</h2>
${content.overview || '<p>Content in development.</p>'}
</div>
</div>
<div id="${module.id}-concepts" class="tab">
<div class="section">
<h2>🎯 Key Concepts</h2>
${content.concepts || '<p>Content in development.</p>'}
</div>
</div>
${content.math ? `
<div id="${module.id}-math" class="tab">
<div class="section">
<h2>πŸ“ Math & Theory</h2>
${content.math}
</div>
</div>` : ''}
${content.applications ? `
<div id="${module.id}-applications" class="tab">
<div class="section">
<h2>🌍 Applications</h2>
${content.applications}
</div>
</div>` : ''}
${content.code ? `
<div id="${module.id}-code" class="tab">
<div class="section">
<h2>🐍 Implementation</h2>
${content.code}
</div>
</div>` : ''}
</div>
`;
}
function switchTo(target) {
document.querySelectorAll('.dashboard, .module').forEach(el => {
el.classList.remove('active');
});
const elem = document.getElementById(target);
if (elem) {
elem.classList.add('active');
window.scrollTo(0, 0);
}
}
function switchTab(e, tabId) {
const module = e.target.closest('.module');
if (!module) return;
module.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
module.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
const tab = document.getElementById(tabId);
if (tab) tab.classList.add('active');
e.target.classList.add('active');
if (window.MathJax && window.MathJax.typesetPromise) {
window.MathJax.typesetPromise([tab]).catch(function (err) { console.log('MathJax typeset:', err); });
}
}
// Initialize application
initDashboard();
</script>
<footer class="disclaimer">
<p><strong>Disclaimer:</strong> This content is an independent educational synthesis based on public research papers (e.g., "Attention Is All You Need", "Chinchilla Scaling Laws") and open-source materials. It is not affiliated with, endorsed by, or sponsored by any university or academic institution. Branding is used for informational purposes only. Β© 2025 AI Engineering Masterclass.</p>
</footer>
</body>
</html>