Free · no signup

Play with the ideas behind AI

Every Math to Machine lesson has a demo you can poke. Here are 20 of them — drag the sliders, press the buttons, build the intuition. This is what “learn by doing” actually looks like.

Gradient descent

Foundations

The algorithm that trains every model. Press Step and watch it roll downhill — crank the learning rate and watch it overshoot.

Set a learning rate, then Step downhill

Loss surface

Step 0

loss = 6.25

x = -2.5, gradient = -5 · One minimum at x = 0. Convex — descent always finds it.

Full explainer + how it works →

Function explorer

Foundations

Drag the coefficients and see how lines, parabolas, exponentials and sine waves reshape — the vocabulary of everything ahead.

Pick a family · drag the sliders

y = 1·e^(1x)

Growth (b>0) explodes; decay (b<0) melts toward 0. Never negative if a>0.

Vectors & the dot product

Foundations

Add, subtract and project 2-D vectors. The dot product becomes 'how similar are these two things?' for embeddings later.

Drag the components

Show

uv

Dot · angle

u·v = 6

|u| = 3.16, |v| = 3.16 · angle ≈ 53.1°

Matrix transforms

Foundations

Watch a 2×2 matrix rotate, scale, shear and flip space. Every neural-net layer is, at heart, a matrix reshaping data.

Drag the matrix entries

Determinant (area scale)

det = 2

area grows by this factor

The derivative

Foundations

Drag a point along a curve and shrink the gap — watch the secant close in on the tangent. That limit is the derivative.

Drag the point (x) and shrink the gap (h)

Function

Tangent slope = f′(x)

3

f′(x) = 2x

Secant slope (gap h)

4.5

As h → 0, this closes in on 3. That limit IS the derivative.

Full explainer + how it works →

Real Python, in your browser

Foundations

Actual CPython compiled to WebAssembly. Edit the code, press Run — nothing installed, nothing sent to a server.

Run Python — right here, no install

Output

Press Run to execute.

Real CPython, compiled to WebAssembly, running in your browser. Nothing is sent to a server.

Linear regression by hand

Classical ML

Drag the line to fit the dots and watch the error shrink. 'Snap to best fit' shows the mathematically optimal line.

Drag the line to fit the dots

Mean squared error

0.444

best possible is 0.116 — the amber misses are what MSE squares and averages

Full explainer + how it works →

Precision vs recall

Classical ML

Slide the decision threshold and watch precision and recall pull against each other — why one accuracy number is never enough.

Slide the threshold — watch precision vs recall fight

True Positive

5

False Positive

2

False Negative

2

True Negative

5

top row = predicted positive · left column = actually positive

Precision · Recall

71% · 71%

of flagged, how many right · of real, how many caught

Accuracy · F1

71% · 0.71

F1 balances precision and recall in one number

k-means clustering

Classical ML

Step through assign → update and watch clumsy starting centroids snap to the real clusters, then converge.

Step through assign → update

Iteration 0

keep stepping

Each ✕ chases the middle of the points that chose it.

Notice: k-means never sees the "true" clusters — it only ever minimises distance to the nearest ✕. 12 points, 3 centroids.

Full explainer + how it works →

A single neuron

Deep Learning

Inputs × weights + bias → activation. The atom of every neural network, made draggable.

Drag inputs, weights & bias

Activation

10.5w₁=0.8w₂=-0.5Σz=0.75f0.68

z → output

0.75 → 0.68

green edges = positive weights, red = negative. Thicker = stronger. The activation squashes z into the output.

Full explainer + how it works →

Backpropagation

Deep Learning

Forward values flow in; gradients flow back through the chain rule. The one idea that makes deep learning work.

Forward computes the loss — then backprop the gradients

×+a2b3c1u=a·b6z=u+c7L1

Loss (target = 8)

1

Prediction z should hit the target. Now press Run backward to see how to fix it.

Full explainer + how it works →

Convolution

Deep Learning

Slide a kernel over an image grid and watch the feature map light up — how CNNs see edges and shapes.

Slide the kernel across the image

Kernel

input 5×5feature map3

Window (1,1)

3

sum of the 9 overlapping cells × the kernel weights

The edge kernel gives ~0 on flat areas and a big value right at the light/dark boundary — it has detected an edge.

Step 1 / 9
Full explainer + how it works →

Attention

Deep Learning

Click a token and see how much it draws from every other token. The mechanism at the heart of every transformer.

Click a query token (a row)

Thecatsatonthematkeys (attended to)Thecatsatonthematqueries

"sat" attends most to

"cat" (44%)

Each row is a softmax — the query's attention split across all tokens, summing to 100%. Content words matter; filler doesn't.

Darker cell = stronger attention. This one mechanism, run in parallel across many "heads", is what replaced RNNs.

Full explainer + how it works →

Tokenization

Generative AI

Watch text split into the tokens an LLM actually reads — and why the model bills and thinks per token.

See text split into tokens

Example text

transformers are unbelievably powerful!

transform#201##ers#18are#15un#21##believ#202##ably#16power#203##ful#17!#6

Token count

9 tokens

Amber chips (##) are sub-word continuations of the previous piece — one word can cost several tokens.

Models bill and remember in tokens, not words. That's why prompt length, context windows and costs are all measured this way.

Full explainer + how it works →

Next-token prediction

Generative AI

A probability bar chart over candidate next words. Slide the temperature from careful to wild.

Turn the temperature — reshape the odds

The cat sat on the ___

mat
73%
floor
13%
rug
9%
table
sofa
moon

Top token probability

73%

Balanced: usually sensible, with room to vary.

Full explainer + how it works →

Embeddings

Generative AI

Click a word to rank the rest by meaning. The semantic search behind every RAG system.

Click a word to find its nearest meanings

kingqueenprincedogcathorseapplebananamango

Closest to "king"

queen, prince

cosine similarity 1 & 1 — nearly 1 means same direction = same kind of thing.

Real embeddings do this in hundreds of dimensions, but the rule is identical: to find related text, compare vector directions.

Full explainer + how it works →

Diffusion

Generative AI

Scrub an image into pure noise and back — the forward-and-reverse process behind Stable Diffusion and DALL·E.

Scrub the noise level (forward ⇄ reverse)

Noised 40%

in between

Each real step adds/removes just a little noise; there are hundreds of them.

Full explainer + how it works →

Retrieval-augmented generation

Generative AI

Step through query → retrieve → augment → generate — how you give an LLM private, current, citable knowledge.

Step through the RAG pipeline

Query: What's the refund window?

Document store

Refunds: a full refund is available within 7 days of purchase.
Subscriptions renew monthly or yearly until cancelled.
Reach support at support@mathtomachine.com any time.
The 7-day refund window is measured from checkout.

1 · Query

The user asks a question.

Step 1 / 5

The agent loop

Agentic AI

Thought → Action → Observation, repeated. Watch an agent refuse to guess and call tools instead.

Step through the agent's think–act–observe loop

💭 ThoughtI need France's population, then double it. I don't know it exactly — I'll look it up.

The model can't multiply reliably or know live facts — so instead of guessing, it acts (calls a tool), observes the result, and reasons on. Loop until it can answer.

Step 1 / 8

The MLOps loop

Production

Data → train → evaluate → deploy → monitor → back to data. Shipping a model is the start of its life, not the end.

Step around the MLOps loop

🗄️ Data

Collect, clean and version the data. Garbage in, garbage out — most real effort lives here.

Step 1 / 5

Liked poking at these? Try a full lesson.

Every one of the 234 lessons wraps a demo like these in predict-then-reveal teaching, worked examples, and a boss check. The first five are free.