Write the Rules
Build a spam filter the 1980s way — by writing rules — then watch it meet new messages. Finally, let a learning algorithm work it out from examples instead.
Visual mode
1–9 of 52 experiments
Pick an experiment to build one intuition, or choose the chapter you're studying.
Chapter 1
Build a spam filter the 1980s way — by writing rules — then watch it meet new messages. Finally, let a learning algorithm work it out from examples instead.
Draw walls on a grid and watch breadth-first, depth-first and A* search find their way — and count how much each has to explore.
Chapter 2
Drag two vectors and watch their dot product and cosine similarity change with the angle between them.
Drop a point on a loss landscape and watch gradient descent, momentum and Adam race to the bottom. Push the learning rate until training diverges; add noise to see stochastic gradient descent.
Edit a 2×2 matrix and watch it stretch, rotate, shear or collapse the plane — then add ReLU and see how a neural-network layer folds space.
A rare condition, an imperfect test: see why a positive result can still mean you're probably fine — Bayes' theorem as counting.
Shrink a secant line until it becomes the tangent — the derivative — then use it to take a gradient-descent step downhill.
Adjust a model's scores for the next word and watch cross-entropy loss and perplexity respond — the exact quantity language models are trained to minimize.
Evaluate the same model on hundreds of random test sets and watch the measured accuracy wobble — why small benchmarks can't separate close models.
Chapter 3
Fit curves of increasing complexity to 12 noisy points. Training error keeps falling; error on new data falls, then soars. Then add regularization.
Train a linear classifier with gradient descent and watch its decision boundary settle — then see it fail on XOR.
A fraud detector on imbalanced data: move the threshold and watch precision, recall, the confusion matrix and the ROC curve respond.
Chapter 4
A real two-layer network you can train, edit and dissect: watch activations flow forward, the decision boundary bend, and backpropagation send each example's error back to every weight.
Send a gradient backwards through up to 40 layers and see it shrink to nothing or blow up — and how ReLU and good initialization fix it.
Chapter 5
Slide a 3×3 filter over a tiny picture, see the nine multiplications behind every output, edit the weights, then add ReLU and pooling.
Slice a sound into short windows, measure each window's frequencies, and discover why no window length is sharp in both time and frequency.
Watch Q-learning fill in a value table move by move, and see an agent settle for a small reward until optimism or a gentler discount changes its mind.
Chapter 6
Build a sentence with a count-based model: see exactly which words it looks at, which corpus lines it counts, and how the chain rule multiplies each step.
Train a tiny 2-D word2vec live in your browser and watch words that share neighbours drift together; compare with one-hot IDs, where nothing transfers.
Read a long sentence one word at a time and watch how much of an early clue survives in a plain RNN versus a gated memory cell.
Chapter 7
One short sentence, one question: which words should each word pay attention to? Build attention step by step — similarity, softmax, weighted sum, then queries and keys.
Step through a real forward pass of one GPT-style Transformer block — embeddings, positions, multi-head attention, residuals, the MLP and the output softmax — with the tensor shape at every stage.
Chapter 8
Type anything and watch the real GPT-2 and GPT-4 tokenizers split it into tokens and IDs: common words, rare words, numbers, code and other scripts.
Learn byte-pair encoding by hand: merge the most frequent pair, again and again, and watch an unseen word get spelled from learned pieces.
Turn the temperature, top-k and top-p dials on a model's next-word probabilities, build a sentence word by word, and compare whole generations.
Chapter 9
Run the deduplication method web-scale datasets use (shingles, MinHash and banded hashing) on a dozen made-up web pages, and tune what counts as a copy.
Add up the memory a GPU needs to train a real model: weights, gradients, optimizer states and activations. Then shard and recompute until it fits in 80 GB.
Split a fixed number of FLOPs between model size and training tokens with a published scaling law, place real models on the map, and see how serving costs change the answer.
Chapter 10
Select training targets, change their probabilities and see exactly what a loss mask removes.
Judge candidate summaries and fit a small reward model. Change the rubric and watch the ranking change.
Optimize a three-answer policy and discover why more reward can mean less truth.
Follow chosen and rejected sequence probabilities through a reference-relative preference loss.
Chapter 11
Serve real Llama models to many users at once: add up weights and KV cache against GPU memory, change the number of key/value heads, and see the memory-bandwidth limit on tokens per second.
Round a row of weights to 8, 4, 3 or 2 bits, add one outlier, and see why a shared scale fails and per-group scales rescue it.
Run speculative decoding's accept-or-resample rule thousands of times and watch the output keep the large model's distribution, then trade acceptance rate, draft length and draft cost for speed.
Chapter 12
Search this site's own concept pages three ways (keywords with BM25, meaning with real embeddings, and both fused) and see where each wins, then score all three on 44 labelled queries.
Cluster the real chunk embeddings into 32 lists and search only the nearest few: watch recall rise as you scan more of the index.
Pick a question, a chunk size, overlap, how many chunks and whether to rerank; see what is retrieved, whether it holds the answer, the exact prompt and what it costs.
A toy model writes a weather-tool call token by token. Sample freely and some calls break; mask invalid tokens and none do, but a required field can force the model to invent a value.
Chapter 13
Watch three agents attack the same bug (one checks its work, one trusts itself, one gets stuck) while the budget drains and the context grows; turn off the runtime's evidence check and see a broken fix ship. Or drive the loop yourself.
Simulate a hundred multi-step tasks and watch small per-step failure rates compound; add retries, then make retries repeat the same mistake and see the textbook formula overstate success.
A planted line in a bug report tells the agent to leak a secret. Choose the runtime's rules, approve or deny writes as the run pauses for you, and see what leaked, what got fixed and what changed that shouldn't have.
Chapter 14
Grow a real arithmetic search tree. Change its width and move budget, inspect discarded states, and discover why the nearest-looking path can fail.
Sample a batch, watch answers accumulate, and compare a vote with a noisy verifier. Correlate the attempts to see agreement stop being evidence.
Train a four-response policy with real gradient updates. Reward outcomes, valid steps or length, and watch what becomes more likely.
Chapter 15
Cut a chart, a scene or a receipt into patches, then send them as raw numbers or as codebook entries. See the token count, the attention cost and which details survive.
Train a tiny CLIP in your browser with the real contrastive loss. Watch the similarity grid's diagonal form, then classify pictures zero-shot with labels it never trained on.
Run real DDIM and DDPM sampling with an exact denoiser. Change the steps and the guidance scale, and watch static become a ring, or collapse when pushed too hard.
Chapter 16
Two simulated models take the same benchmark. Change its size, rerun it on fresh questions, and compare unpaired and paired error bars to see when a lead is more than luck.
Build a leaderboard with a simulated LLM judge that favours the first and the longer answer. Watch a padded assistant climb to the top, then fix it with swapped orders and length control.
A toy model answers 1,000 questions with stated confidences. Read its reliability diagram, fix overconfidence with temperature scaling, and choose when it should say 'I don't know' under different penalties for wrong answers.
Train the toy model of superposition live: five features through two hidden neurons. Make the features rarer and watch the model go from keeping two features to packing all five into a pentagon.
Next: Chapter 3 · Machine Learning, Chapter 4 · Neural Networks, Chapter 5 · Vision, Speech & Reinforcement Learning