Machine Learning Lab
Seventeen interactive pages where machine learning can be touched by hand: turn the knobs, watch training converge and see the formulas at work. Nothing to install — everything is computed right in the browser, and the pages even work offline.
About the language
Every page carries an RU / EN switch, and the language also comes from the address: add
#lang=en to any link. The choice is kept in the URL hash on purpose — the site server drops
query parameters when it redirects .html links, so ?lang=en would be lost.
All seventeen pages are translated — the English version of the lab is complete. Both languages share the same code, so the numbers never differ; only the words change. The visualizations themselves — diagrams, matrices, formulas, numbers — are language-independent in any case.
🧩 Inside neural networks
🧩 Transformer, block by block
The full diagram from “Attention is All You Need”: a breakdown of every block, expandable internals right on the diagram, GPT and BERT modes, and live examples with real numbers.
👀 Attention with real weights
Twelve tokens, four heads and an honest softmax(QKᵀ/√d_k): see who attends to whom, and why the heads end up so different.
🔁 Forward pass and backprop
The signal travels forward through the layers, the error travels back. Each of the 105 connections is coloured by its weight and gradient.
🖼 Convolutions, ReLU and pooling
A 3×3 kernel slides across the image, five filters produce five feature maps, and the live arithmetic of the convolution is shown below.
🧮 How a neural network adds two numbers
A tiny transformer trains itself in your browser and shows every single multiply-add — 39,324 operations for the answer “5”.
🎯 How learning works
⛰ Descent on the loss landscape
A ball rolls down a real loss surface, and you can see where the gradient comes from and why the learning rate cannot be too large.
🏁 The optimizer race
SGD, Momentum and Adam start from the same point and head for the minimum. Watch who cuts the corner and who wanders.
🏞 The ravine: who walks how
Four optimizers — SGD, Momentum, AdaGrad and Adam — in a long narrow valley. SGD bounces wall to wall, Adam arrives first, and they all end in the same point: the paths differ, not the answer.
⚖️ Adam and bias correction
The first ten steps of Adam one by one: the raw moment estimates, their corrected versions, a “with / without correction” switch and a table of numbers.
🐦 A swarm with no gradient
260 particles hunt for the minimum knowing only function values. Three rules of a flock — and the swarm gathers on its own.
⛰ Why not MSE: two loss surfaces
Log-loss gives a single convex bowl, while MSE is non-convex: saddles and flat plateaus with a near-zero gradient. Descent stalls in different places — compare both curves on the chart.
🎯 Supervised learning
🎯 KNN: K nearest neighbours
Two classes of points arranged crosswise. Drag the query point and watch K neighbours vote, while the decision boundary is recomputed honestly on a 200×200 grid — for three metrics and with 1/d weights.
📏 Fit a line by hand
Drag the line across a cloud of points: vertical residuals, live MSE and the “MSE versus slope” parabola with a single minimum. Press A and gradient descent arrives at the same answer as the closed-form solution.
📈 Polynomial degree: overfitting
A degree slider from 1 to 15: on the left the curve bends under every point of noise, on the right the error falls on training data but first falls and then rises on held-out data. The minimum of the test error is the complexity you want.
⚖️ Threshold: where to draw the line
The model's probabilities never change — only the decision does. Move the threshold, watch the boundary slide, and see accuracy, precision, recall and F1 recomputed.
📊 Data and decisions
🔵 Embeddings, PCA and k-means
303 objects in a 16-dimensional space: an honest PCA draws the map, and k-means finds five themes with 98% purity — unsupervised.
🤖 Reinforcement learning
An agent learns to solve a maze from reward alone. The value wave spreads out from the goal and the policy builds itself.
🧭 PCA in 3D: the axis of most variance
A point cloud and a projection axis: turn it by hand and see that the spread peaks on the eigenvector. The panel shows the explained variance share.
✨ Just beautiful
🌌 A galaxy of 100,000 particles
Logarithmic spiral arms, a bulge, a halo and differential rotation. There is a poster mode for downloading a 4K frame.
🌫 A nebula from fbm noise
Domain-warped fractal noise: one formula turns into a cloud you want to keep looking at.
How to use it
- Click any block in a diagram — a breakdown opens next to it or in the side panel: what it is, the formula, why it exists, tensor shapes and the usual pitfalls.
- The “+” badge in the corner of a block expands its internal diagram in place: for attention you can follow
the whole
Q·Kᵀ → ÷√d_k → softmax → ×Vchain. - Live examples appear in the explanation panel: a temperature slider for softmax, a causal-mask checkbox, positional-encoding plots, a counter of values zeroed by ReLU.
- The ← → keys page through the blocks, 1 / 2 / 3 switch the architecture (encoder–decoder → GPT → BERT), and A− / A+ change the diagram size.
- In the KNN, linear-fit and polyfit pages you can also change the language on the spot with the RU / EN
switch — the same thing that
#lang=endoes to a link.
What matters
Everything in the lab is real mathematics, not a hand-drawn animation: convolutions are computed in a shader, k-means runs honest Lloyd iterations, Q-learning updates its table by the Bellman equation, and PSO uses the classical Clerc constants. Wherever something is an illustration rather than a trained model, the page says so explicitly.