Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions phases/04-computer-vision/05-transfer-learning/docs/en.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ Transfer-learning runs need two numbers you would not track on a scratch run:

If fine-tuned is less than pretrained-only, you have a learning-rate or BN bug. Always print both.

```figure
transfer-learning
```

## Build It

### Step 1: Load a pretrained backbone and inspect it
Expand Down
4 changes: 4 additions & 0 deletions phases/04-computer-vision/14-vision-transformers/docs/en.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ Masked Autoencoder (He et al., 2022): mask 75% of patches at random, train the e

MAE makes ViT trainable on ImageNet-1k alone, hits SOTA, and is the current default self-supervised recipe.

```figure
batchnorm-inference
```

## Build It

### Step 1: Patch embedding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ After self-supervised pretraining, the standard evaluation is a **linear probe**

Linear probe is a pure measure of feature quality; fine-tuning typically adds 2-5 points but also mixes in the effect of head retraining.

```figure
data-augmentation
```

## Build It

### Step 1: Two-view augmentation pipeline
Expand Down
4 changes: 4 additions & 0 deletions phases/06-speech-and-audio/03-audio-classification/docs/en.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ ESC-50: 50 classes, 40 clips each — balanced, easy. UrbanSound8K: 10 classes,
| AudioSet mAP | 0.485 (AST) | 0.548 (BEATs-iter3) | HEAR leaderboard 2026 |
| Speech Commands v2 | 98% (CNN) | 99.0% (Audio-MAE) | HEAR v2 results |

```figure
mfcc-pipeline
```

## Build It

### Step 1: featurize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ Advantages: highest quality on offline ASR, easy to train with standard seq2seq

All these are encoder-decoder or RNN-T based. Pure CTC systems (wav2vec 2.0) sit around 1.8–2.1% on test-clean.

```figure
ctc-collapse
```

## Build It

### Step 1: greedy CTC decode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ When a new generative model paper drops, answer these five questions before read

You will re-answer these five for every lesson in this phase. By the end, they will be reflex.

```figure
autoencoder-bottleneck
```

## Build It

The code for this lesson is a lightweight visualization: fit a 1-D mixture-of-Gaussians from samples using three toy approaches (kernel density, discrete histogram, and a nearest-sample "GAN-ish" generator) so you can see the difference between explicit vs implicit density on a problem you can print on one screen.
Expand Down
4 changes: 4 additions & 0 deletions phases/08-generative-ai/11-audio-generation/docs/en.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ The 2024-2026 trend: flow matching is winning for music (faster inference, clean
| AudioCraft 2 | Music + SFX | Flow matching | ~5s for 5s clip |
| Riffusion v2 | Music | Spectrogram diffusion | ~10s |

```figure
score-matching
```

## Build It

`code/main.py` simulates the core idea: train a tiny next-token transformer on synthetic "audio token" sequences generated from two distinct "styles" (alternating low and high tokens for style A, monotonic ramp for style B). Condition on style and sample.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ Flow matching with a Gaussian-conditional path is diffusion *with a specific noi

What flow matching added: the *clarity* of the target (a plain velocity), a cleaner loss, and the license to experiment with non-Gaussian interpolants.

```figure
normalizing-flow
```

## Build It

`code/main.py` implements 1-D flow matching on a two-mode Gaussian mixture. The vector field `v_θ(x, t)` is a tiny MLP trained with the straight-line target. At inference, integrate 1, 2, 4, and 20 Euler steps and compare sample quality.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ with `λ ∈ [0, 1]`. `λ = 0` is TD (low variance, high bias). `λ = 1` is MC (

Three terms: policy-gradient loss, value regression, entropy bonus. `c_v ~ 0.5`, `c_e ~ 0.01` are canonical starting points.

```figure
actor-critic
```

## Build It

### Step 1: a critic
Expand Down
4 changes: 4 additions & 0 deletions phases/09-reinforcement-learning/08-ppo/docs/en.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ Same actor-critic structure as A2C. Three coefficients, usually `c_v = 0.5`, `c_

**KL-penalty variant.** The original paper proposed an alternative using an adaptive KL penalty: `L = L^{PG} - β · KL(π_θ || π_old)` with `β` adjusted based on observed KL. The clipping version became dominant; the KL variant survives in RLHF (where KL to the reference policy is a separate constraint you always want anyway).

```figure
ppo-clip
```

## Build It

### Step 1: capture `log π_old(a | s)` at rollout time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ In 2026 the PPO step is mostly replaced by DPO (Phase 10 · 08) because it is ch
- **Process reward models (PRMs):** score partial solutions (each reasoning step), used in both RLHF and GRPO variants for reasoning.
- **Constitutional AI / RLAIF:** use an aligned LLM to generate preferences instead of humans. Scales the preference budget.

```figure
reward-model
```

## Build It

This lesson uses tiny synthetic "prompts" and "responses" represented as strings. The RM is a linear scorer over a bag-of-tokens representation. No real LLM — the *shape* of the pipeline matters, not the scale. See `code/main.py`.
Expand Down
4 changes: 4 additions & 0 deletions phases/11-llm-engineering/01-prompt-engineering/docs/en.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ The best prompts are model-agnostic. They work on GPT-5, Claude Opus 4.7, Gemini
5. Test with temperature=0 first to isolate prompt quality from sampling randomness
6. Include 2-3 few-shot examples -- they transfer across models better than instructions alone

```figure
cot-decomposition
```

## Build It

### Step 1: Prompt Template Library
Expand Down
4 changes: 4 additions & 0 deletions phases/11-llm-engineering/02-few-shot-cot/docs/en.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ Chaining beats single-prompt for three reasons:

The right technique depends on three factors: accuracy requirement, latency budget, and cost tolerance. For most production systems, few-shot CoT with a 3-sample self-consistency fallback covers 90% of use cases.

```figure
few-shot-curve
```

## Build It

We will build a math problem solver that combines few-shot prompting, chain-of-thought reasoning, and self-consistency voting into a single pipeline. Then we will add tree-of-thought for hard problems.
Expand Down
4 changes: 4 additions & 0 deletions phases/11-llm-engineering/05-context-engineering/docs/en.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ The key insight: different queries need different context. A static system promp

This is what separates a good AI application from a great one. The model is the same. The context is the differentiator.

```figure
lost-in-the-middle
```

## Build It

### Step 1: Token Counter
Expand Down
4 changes: 4 additions & 0 deletions phases/11-llm-engineering/10-evaluation/docs/en.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ You do not have to build everything from scratch. These tools provide eval infra

For this lesson, we build it from scratch so you understand every layer. In production, use one of these tools.

```figure
llm-judge-rubric
```

## Build It

### Step 1: Define the Eval Data Structures
Expand Down
4 changes: 4 additions & 0 deletions phases/11-llm-engineering/11-caching-cost/docs/en.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ Here is a real breakdown for a RAG chatbot serving 10,000 DAU.

The embedding cost for semantic caching ($180/month) pays for itself within the first hour of cache hits.

```figure
semantic-cache
```

## Build It

### Step 1: Cost Calculator
Expand Down
4 changes: 4 additions & 0 deletions phases/11-llm-engineering/15-prompt-caching/docs/en.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ Violate the order — put the user message above the system prompt, interleave d

Anthropic's 25% write premium means a cached block has to be read at least twice to net-save money. 1 write + 1 read averages 0.675x cost per request (saves 32%); 1 write + 10 reads averages 0.205x (saves 80%). Rule of thumb: cache anything you expect to reuse at least 3 times within the TTL.

```figure
prompt-cache-hit
```

## Build It

### Step 1: Anthropic prompt caching with explicit markers
Expand Down
4 changes: 4 additions & 0 deletions phases/12-multimodal-ai/03-blip2-qformer-bridge/docs/en.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ Flamingo (Lesson 12.04) predated BLIP-2 and used the same cross-attention idea b

All four are valid. The deciding question is whether you are constrained on token budget or on quality-per-token.

```figure
modality-projection
```

## Use It

`code/main.py` builds a stdlib Q-Former-style cross-attention:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ Otter (2023) builds on OpenFlamingo with instruction tuning on MIMIC-IT (a datas

Pick BLIP-2 for single-image VQA on a budget. Pick Flamingo/Idefics2 for interleaved, few-shot, or multi-image reasoning.

```figure
cross-attention-fusion
```

## Use It

`code/main.py` demonstrates:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ Fuyu (Adept, 2023) is a related approach: skip the separate vision encoder entir

AnyGPT (Zhan et al., 2024) extends Chameleon to four modalities: text, image, speech, music. Same VQ-VAE trick for each, shared transformer. Any-to-any generation. Covered more in Lesson 12.16.

```figure
vq-codebook
```

## Use It

`code/main.py` builds a toy end-to-end early-fusion model:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ Janus-Pro (Lesson 12.15) refines Transfusion's idea by decoupling the vision enc

2026 production VLMs that emit images — Gemini 3 Pro, GPT-5, Claude Opus 4.7's image generation path — almost certainly use some descendant of this family. Details are proprietary.

```figure
cfg-guidance-scale
```

## Use It

`code/main.py` builds a toy Transfusion on a tiny MNIST-like problem:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ For video VLMs in 2026:
- Output: structured JSON with time + event fields.
- Benchmarks: VideoMME + TempCompass for general; EgoSchema for long-horizon.

```figure
video-temporal-patches
```

## Use It

`code/main.py` includes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ MMAU (Massive Multimodal Audio Understanding) is the 2024-2025 audio reasoning b

Open SOTA (AF3) at 0.72; proprietary frontier ~0.78 (Gemini 2.5 Pro, Claude Opus 4.7). The gap is smaller than VideoMME's open-vs-closed delta, indicating audio-LLMs are maturing.

```figure
audio-text-ctc
```

## Use It

`code/main.py`:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ Cross-modal evaluation is still immature. Common proxies:

No standard benchmark spans all modalities. Most papers evaluate on domain-specific tasks.

```figure
contrastive-matrix
```

## Use It

`code/main.py`:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ Three tiny functions translate it to the three provider shapes. The harness in `

Production teams wrap this translator in `AbstractToolset` (Pydantic AI), `UniversalToolNode` (LangGraph), or `BaseTool` (LlamaIndex). Phase 13 · 17 ships a gateway that exposes an OpenAI-shaped API in front of any of the three.

```figure
function-call-args
```

## Use It

`code/main.py` defines one canonical `Tool` dataclass and three translators that emit the OpenAI, Anthropic, and Gemini declaration JSON. It then parses a hand-crafted provider response of each shape into the same canonical call object, demonstrating that the semantics are identical under the skin. Run it and diff the three declarations side by side.
Expand Down
4 changes: 4 additions & 0 deletions phases/13-tools-and-protocols/04-structured-output/docs/en.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ One retry is usually enough. Three retries catches weak-model flakes. Beyond thr

Constrained decoding works on small models. A 3B-parameter open model with grammar enforcement out-performs a 70B-parameter model with raw prompting on structured tasks. This is the main reason structured outputs matter for production: it decouples reliability from model size.

```figure
constrained-decoding
```

## Use It

`code/main.py` ships a minimal JSON Schema 2020-12 validator in stdlib (types, required, enum, min/max, pattern, items, additionalProperties). It wraps an `Invoice` schema and runs a fake LLM output through the validator, demonstrating parse error, schema violation, and refusal paths. Swap the fake output for any provider's real response in production.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ Plan-and-Act scales the pattern to long-horizon web and mobile agents. The key c

Anthropic's Dec 2024 guidance: start with the simplest. If the task is one tool call plus a summary, do not build ReWOO. If the task is a 40-step research assignment, do not do ReAct alone.

```figure
rewoo-plan
```

## Build It

`code/main.py` implements a toy ReWOO:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ Most production agents do not run LATS. They run ReAct with tool-grounded verifi

AlphaEvolve (Lesson 11) is the 2025 extreme: evolutionary search over code, machine-checkable fitness, frontier gains (first 4x4 matmul improvement in 56 years).

```figure
tree-of-thoughts
```

## Build It

`code/main.py` implements:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ OpenAI Agents SDK ships this pattern as "output guardrails." A guardrail is a va
- **Over-refinement.** Each refine pass adds latency and tokens. Budget 1-3 passes; after that, escalate to human review.
- **CRITIC on trivial tasks.** If there is no external verifier, CRITIC degenerates to Self-Refine; do not pay the latency for a stub verifier.

```figure
self-refine
```

## Build It

`code/main.py` implements Self-Refine and CRITIC on a toy task: produce a short bullet list given a topic. The verifier checks format (3 bullets, each under 60 chars). CRITIC adds an external "fact verifier" that penalizes known hallucinations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ Letta V1 (`letta_v1_agent`, 2026) deprecates `send_message`/heartbeat and inline
- **Silent drift.** Sleep-time agent rewrites a block and the primary agent never notices. Version blocks and surface diffs in the trace.
- **Poisoned consolidation.** Sleep-time agent processes attacker-reachable content into core. Lesson 27 applies to the sleep-time surface too.

```figure
memory-blocks
```

## Build It

`code/main.py` implements:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ For production agents this translates to a "what's missing" operator: given the
- **Composed-skill drift.** Parent skill depends on a child that was refined. Version skills; a parent pinned to v1 doesn't magically pick up v3.
- **Retrieval quality.** Vector retrieval over skill descriptions degrades as the library grows past a few hundred. Supplement with tag filters and hard constraints ("only skills with `category=tooling`").

```figure
voyager-skills
```

## Build It

`code/main.py` implements a stdlib skill library:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ Short-term (within a run — conversation history in state) and long-term (acros
- **Non-deterministic nodes.** Resume assumes node inputs produce the same state update. Random seeds, wall-clock, external APIs must be captured.
- **Over-use of conditional edges.** A graph with every edge conditional is a state machine that cannot be reasoned about. Prefer linear chains with occasional branches.

```figure
langgraph-state
```

## Build It

`code/main.py` implements a stdlib stateful graph:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ Decision order:
- **Bouncing handoffs in swarm.** A -> B -> A -> B. Use hop counters.
- **Fake hierarchy.** Three layers because "enterprise"; two actual teams. Collapse.

```figure
orchestration-pattern
```

## Build It

`code/main.py` implements all four patterns in stdlib against a scripted LLM:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ Zhuge et al. ("Mindstorms in Natural Language-Based Societies of Mind," arXiv:23
- **Topic drift.** Debates over many rounds drift from the original question. Mitigation: re-inject the question every round.
- **Compute blowup.** N agents × R rounds = N·R LLM calls, each with a context that grows. A 5-agent, 5-round debate is 25 calls at growing context. Cost per question can exceed 10× a single CoT call.

```figure
multi-agent-debate
```

## Build It

`code/main.py` runs a 3-agent × 3-round debate on a math question where each agent starts with a different (possibly wrong) answer. Agents are scripted — each "updates" by averaging the neighbors' answers weighted by a scripted confidence. Convergence is visible in the round-by-round log.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ This is a layered-defense model: CAI shapes behaviour; classifiers enforce invar

The axis is "where does the preference signal come from." CAI's 2022 paper was the first serious shift from human to AI signal at frontier scale.

```figure
constitutional-ai
```

## Use It

`code/main.py` simulates the CAI critique-and-revise loop on a toy lexicon. A "principle" flags tokens from a harmful set. Given an initial response, the critique identifies the harmful tokens, and the revision replaces them. After 200 iterations the "trained" model has internalized the revision rule. Compare the base model, RLHF-shaped toy, and CAI-shaped toy on a held-out prompt set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ Even perfect inner alignment to the base objective is not enough. Reward hacking

Lessons 6-11 form the "deception and oversight" arc. Lesson 6 gives the vocabulary. Lesson 7 (Sleeper Agents) demonstrates persistence. Lesson 8 (In-Context Scheming) demonstrates capability. Lesson 9 (Alignment Faking) demonstrates spontaneous emergence. Lesson 10 (AI Control) describes the defensive paradigm. Lesson 11 (Scalable Oversight) describes the positive agenda.

```figure
interpretability-probe
```

## Use It

`code/main.py` simulates a mesa-optimizer in a two-period environment. A base optimizer (SGD) trains a policy over actions. The policy has a learned terminal preference (the mesa-objective) and a situational-awareness flag. In period 1 (training), the situational flag is 0 and the policy cooperates. In period 2 (deployment), the flag is 1 and the policy defects if its mesa-objective differs from the base objective. You can run the full simulation with and without adversarial training, and watch deceptive alignment persist.
Expand Down
Loading
Loading