Interactive figures
Every figure in the track. Each one is a small experiment: drag, slide, and watch the numbers. The link under each figure takes you to the lesson that explains it.
Lesson 1 · Derivatives in one variable
Press Play h → 0, or drag the orange point towards the violet one. The secant turns into the tangent line, and the table shows its slope approaching . Then choose ReLU with : from the right the slopes are all 1, from the left all 0, so the limit does not exist.
Press Play zoom. The right panel shows the window around the point, rescaled to a fixed size. The graph straightens into the tangent line, and the ratio in the readout goes to 0. Now choose ReLU or |x|: at the kink the picture looks the same at every zoom, and stays 1.
Raise the order from 0 to 4. The Taylor polynomial hugs the graph on a wider and wider band (error below 0.01). The readout shows the error at and : their ratio is close to . Drag the point to expand somewhere else. Try : its order-2 polynomial at is just the tangent line, because .
Predict, then move the step size . On the readout shows the factor that multiplies at every step; the right panel plots against . Cross (the steps start to jump over 0) and then (they diverge). On the non-convex quartic, drag the start point: it decides which minimum you reach.
Lesson 2 · Partial derivatives and the gradient
Move and , and rotate the figure. The orange slice keeps fixed; the slope of its dashed tangent is . The yellow slice keeps fixed; its slope is . The gradient combines both numbers into one arrow. Notice that it lies in the flat input plane , under the point, not on the surface.
Drag the point. The contour lines are computed from alone; the gradient is computed from the two partial derivatives. Still, the arrow always crosses the line at a right angle (the dashed tangent is the direction of the contour). Turn on the gradient field, and try the saddle, Rosenbrock and the logistic loss of a tiny classifier. The orange arrow is the direction that gradient descent takes.
Predict first: at which angle of does the curve on the right have its peak? Then drag the tip of around the circle. The slope follows a cosine. Its peak is at the direction of the gradient (blue line), its lowest value at the opposite direction (orange line), and it is 0 along the contour. The limit check computes with a small and agrees with . The dashed segment drops from the gradient tip onto the line of : the part of along is .
Use the presets, then the sliders. The path of gradient descent starts at the violet point. Its first step follows the blue arrow , which misses the dashed straight line to the minimum. With round bowl the path is straight. With stretched it zig-zags across the valley, and with η too large the -coordinate grows at every step. Compare the step counts.
Lesson 3 · Jacobians, Hessians and Taylor
Make the square smaller with the δ slider. The image of the square under (solid) and its image under the linear map (dashed) become the same shape. The right panel is magnified so that the image always fills it. Drag the point and try the other maps. For polar coordinates, move to : becomes 0, and the parallelogram becomes flat.
Switch between the tangent plane and the quadratic model, and move . The tangent plane (order 1) and the quadratic model (order 2) touch the surface at . The magenta segments show the error at the corners of the patch. Halve the patch size (from 0.6 to 0.3): the largest error falls by about 4 for the plane and by about 8 for the quadratic model. On the bump, find a point where the model is a dome and one where it is a saddle; on the cubic, find a bowl.
Press "One step" a few times, then switch to the cubic. On the stretched bowl, the Newton step (dashed arrow) goes straight to the minimum, and gradient descent zig-zags. Change above : gradient descent diverges along . On the cubic, drag the start point near the saddle at (for example to ): Newton goes to the saddle, not to the minimum. The readout says when is indefinite.
Move the eigenvalue sliders through 0. The contours are solid where is above and dashed where it is below. The arrows are the eigenvectors of . A minimum has only solid contours, a saddle has both kinds. Choose "λ₂ = 0" and then each extra term along : the Hessian is the same, but you get a minimum, a saddle, or neither. This is why the test cannot decide.
Switch the gradient to "buggy", then the direction to . With the correct gradient, has slope 2 and has slope 3. With the buggy gradient, has slope 1. With the bug is invisible, because the error is orthogonal to . At small all curves stop at the rounding level of ; switch to float32 to see this floor rise.
Lesson 4 · Chain rule and computational graphs
Move the Δx slider toward 0. A small step on the line becomes a step on the line and then on the line. The violet bars are the true changes; the dashed blue bars are the linear predictions and . The magenta gap shrinks faster than , so tends to the product . Try the other presets: the rates are now different at every point.
Make the square smaller with the ε slider. The violet square around is mapped by (a rotation and scaling near each point) and then by (a shear). The true images are slightly curved. The dashed blue parallelograms are the Jacobian predictions and ; for small they match the true images. Press show wrong order: the magenta parallelogram does not match, even for tiny squares. Each panel is zoomed around its point.
Press Next step and predict each number before it appears. The first 7 steps compute the values (first number under each node). Then the backward run fills the orange adjoints from right to left. Watch and : each is used twice, so it receives two contributions, and the second one is added (magenta). At the end, and are the two partial derivatives. Switch to forward (tangents) to get one directional derivative instead.
Drag the violet point along the curve. Here feeds two branches, and depends on both. The bars show the path-1 and path-2 products and their sum. Only the tangent with the summed slope touches the curve; the magenta lines use one path only. Try residual: the identity path always contributes 1. Try shared weight: one parameter is used in two places.
Lesson 5 · Forward and reverse mode autodiff
Press Next step and predict each blue number. Each step computes a value and its tangent together, from left to right. With the seed the output tangent is . Change the seed to and run again to get : one forward pass gives one directional derivative, so two inputs need two passes. With you get in one pass.
Press Next step and predict the blue ε part before it appears. The input is . Each line applies one rule (shown on the right) to dual numbers; removes the second-order term. At the end the ε part equals the derivative from the formula, to all printed digits. Try loop (Horner): the program runs a loop three times, and AD still gives the exact derivative.
Step through both phases. In the forward run, each step writes one line of the tape (the table): the operation and its value. In the backward run, the tape is read from the bottom up. Each step sends times the local derivative to the parents. The local derivatives use stored values: needs the value of from the forward run. Contributions to and add because both fan out.
One pass at a time. Press One pass: forward mode fills one column of the Jacobian per pass, reverse mode one row. For the simulator shape , forward mode needs 3 passes and reverse mode 12. Switch the shape to loss and count again. (This figure is from linear algebra lesson 15.)
Press backward step several times. The forward run kept only the orange checkpoints. When the backward run enters a segment, it recomputes that segment's activations (blue), uses them, and frees them. Watch the count of stored activations. Then move the interval : the chart shows the peak memory and the recomputed layers for every ; the peak memory is lowest near .
Compare the three bars (log scale). For the loss shape , the output side needs multiplications and the input side : about 92 times more. Switch to simulator and the input side wins. Try bottleneck (): both ends cost about , but the best order needs only . Move the width sliders and predict which bar is shortest before you look.
Lesson 6 · Backprop: MLPs, losses, layers
Step through one training step. Press Next step. The forward pass fills the nodes with values (blue); the backward pass fills them with error signals (orange). A grey hidden unit is "off" (ReLU with ): its slope is 0, so no error passes through it, and its row of is zero. Move with the sliders to switch units on and off, and switch to the softmax loss to see .
Move the logits and watch the gradient. The bars show the probabilities (blue) and the gradient (orange). The gradient entries always sum to 0 and stay in . Then move the shift slider: adding the same number to every logit changes nothing in , but the naive formula (magenta) breaks once a logit passes about 710, while log-sum-exp stays correct.
Drag the weight vector or press Run gradient descent. The aqua lines are level sets of the logistic loss in the plane of weights; the blue arrow is one gradient-descent step with the step of 3.5. The inset shows the data and the decision line . On the data that are not separable, the level sets are closed curves around one minimizer . Switch to separable: the level sets open up, gradient descent runs off along a ray, the loss decreases slowly towards 0, and the Hessian eigenvalues (readout) shrink towards 0.
Compare the full backward pass with a naive one. The grey bars are , which is what you get (times ) if you treat and as constants. The orange bars are the true gradient, times . The true one always sums to 0, and it is orthogonal to while the row variance is much larger than . Move the scale slider down until the variance is close to and watch the cosine readout.
Change the depth, the activation and the weight scale. The orange line is the norm of the error signal at each layer of a random MLP of width 64, on a log scale; the backward pass starts at the right with . With tanh and scale 1 the norm decreases slowly; with scale 0.5 it vanishes fast. With ReLU, scale (He initialization) keeps it nearly flat, and scale 2 explodes. The sigmoid vanishes even at scale 1.
Lesson 7 · Finite differences and gradient checks
Press "Halve h" a few times. The forward secant turns toward the tangent slowly: its error halves at each step (first order). The central secant is almost parallel to the tangent already: its error falls by 4 at each step (second order). Drag the point to a place where the curve bends strongly: the forward error grows, because it is proportional to the curvature .
Move the probe from right to left. On the right arm the error falls as falls. At the dashed lines (the optimal steps predicted in section 3) the forward and central errors turn around. Left of them, the digits of and in the readout are mostly the same: the subtraction cancels the grey digits and keeps only the pink ones, which are rounding noise. Below , rounds to and the difference is 0. The complex step subtracts nothing and stays at full accuracy. Switch to float32: the V moves up and to the right.
Make the step smaller than the distance to the kink. While , the points and lie on different sides of 0, and the central secant mixes the two slopes: the check fails although the analytic derivative is correct. As soon as , the check passes. Only the ratio matters, so the axes are in units of the step (for example ).
Lesson 8 · Hessian-vector products
Drag the violet point and the violet direction handle . Left: the contour lines of , the dashed line and the gradient arrows along it. Right: the path of the gradient's tip as moves. Its tangent at is the exact ; the secant through the two points at is the finite-difference estimate. Move the slider and watch the error chart: large gives truncation error, tiny gives rounding error. For the cubic preset the gradient is quadratic in , so the secant is exact up to rounding.
Move the slider . A one-parameter model is fitted to 12 points. Top: the loss with two quadratic models at : the Newton model (uses the true second derivative ) and the Gauss-Newton model (uses ). Bottom: residual term. Notice that everywhere, while is negative between the valleys. There the Newton model opens downward and its step goes uphill. Set the noise to 0: at the best fit the residuals vanish and .
Step through the trace of at . Rows 1–6 are the forward pass, rows 7–12 the backward pass that computes . In forward-over-reverse, every row also carries a tangent (the dot). The tangents of are . In reverse-over-reverse, a third sweep goes back up through all 12 rows and fills the second adjoints; the values at are . Notice that this third sweep needs all 12 rows stored. Choose to get the first column of .
Press "New probes" a few times. The lines are running averages of for a fixed symmetric matrix: Rademacher and Gaussian probes. The dashed curves are one standard deviation from the variance formula; they shrink like . This matrix is diagonal-heavy, so the Rademacher band is narrow and the Gaussian band is wide. Switch to the off-diagonal-heavy matrix: both bands are wide and almost equal. For the diagonal matrix, every Rademacher probe gives the exact trace.
Lesson 9 · Implicit differentiation
Drag the violet point along the curve (horizontal axis , vertical axis ). The blue line has the implicit slope . The orange secant joins the solutions at , found by Newton's method from the current . They agree everywhere except near a fold, where , the tangent turns vertical and the secant has no second point. Try the S-shaped cubic: it has three solutions for some , and each branch has its own derivative.
Move and watch the cobweb. The iteration walks between the curve and the diagonal , and stops at the fixed point. The dashed curve is : its fixed point moved by about . The readout compares this implicit slope with the derivative of the -step iteration (unrolled). For , the upper fixed point repels the iteration, but the implicit formula still gives its slope.
Move (the number of solver iterations) and the contraction. The chart shows three errors on a log scale: the forward error (grey), the error of the unrolled gradient (backprop through steps) and the error of the implicit gradient evaluated at . Both gradients improve geometrically; the implicit one is about as accurate as the forward solve. The bars show the memory: unrolling stores iterates, the implicit gradient stores one point.
Drag with the slider. Top: the validation loss against with the tangent line whose slope is the hypergradient from one linear solve. Bottom: the weights and the norm . Notice that always falls as grows, but a single weight can rise. Press Hypergradient step to take gradient-descent steps on .
Lesson 10 · Integrals and change of variables
Change and the method, and watch the error chart. The shaded strips are the Riemann sum; the black curve is . In the log-log chart, each line is the error of one method against : left sum, midpoint, trapezoid and the typical Monte Carlo error. The left sum has slope (error ). The midpoint and trapezoid rules have slope (error ). Monte Carlo has slope : it is the slowest in 1-D.
Drag the violet point, then make the square small. Left: the small square in the -coordinates. Right: its image under and, dashed, the image under the linear map . The readout compares the ratio of the two areas with ; they agree better as the side shrinks. In the polar map, and : the same square gives a bigger image far from the origin. With "linear, det < 0" the map flips the orientation, and the area factor is still the absolute value.
Move the violet strip and compare the two violet areas. Top: samples of and its density. Bottom: the same samples after the map, , with the formula on top. The violet strip holds the same probability in both charts, so where its image is wider, it is lower. Then choose a wrong formula in the menu: it no longer fits the histogram, and its integral is not 1. Try with "one branch" and , where the density piles up near 0 and 1.
Drag the violet corner of the cell, and change and . The cell has a radial side and an arc . Compare its exact area with and with . For a small cell, the first ratio is close to 1 everywhere. The second ratio is close to : it is wrong except at .
Add layers with the slider, then drag the violet point . The shading is the exact density , computed by inverting the layers. The dots are samples of the base Gaussian pushed through the layers. The dashed path goes back from through the layers to the base point . The readout lists each layer's and subtracts their sum from . The sum of times the cell area stays close to 1: the layers move probability, they do not create it.
Lesson 11 · Gaussian integrals and Laplace
Drag the violet point to choose a ring, then increase the number of rings . Top: the bump seen from above (darker = higher) and the selected ring. Bottom: each bar is the volume of one ring, divided by ; the black curve is . With more rings the bars fill the area under the curve. The sum tends to (the figure stops at ), so .
Change , and the angle, then drag the violet peak. The shading is the bump , with level sets at 1, 2 and 3 "widths". The arrows are the eigenvectors scaled to the widths: and . The readout splits into a width part and a height part , and compares with a grid sum. Notice: the angle does not change ; dragging the peak changes only the height part. Try the preset "λ₂ < 0": then the integral is infinite.
Increase , then switch to the zoomed axis. The black curve is the integrand (scaled to peak 1); its shaded area is the exact integral. The dashed curve is the Laplace Gaussian. In the zoomed axis the Gaussian stays fixed and the true curve moves onto it. The lower chart shows the relative error against , with the slope prediction . Try the four functions: "" is exact for every ; "Bernoulli" puts Gaussian mass outside ; "" has two minima, and the error does not go to 0.
Increase and switch between the functions. Top: (black), the shape of the density of , and the nodes ; a bigger dot means a bigger weight. Bottom: the Gauss–Hermite error against , and the typical Monte Carlo error for the same number of evaluations. Notice: for the error is exactly 0 from on (); for it reaches rounding level near ; for ReLU it falls slowly.
Move the total count and the number of windows ; then try "no events". Poisson counts in time windows with total and the prior . The black curve is the exact posterior (a Gamma density). The orange dashed curve is the Laplace approximation in ; the blue dashed curve is the Laplace approximation in , drawn as a density in . Notice: with little data the orange Gaussian is too narrow, is centred at the mode, and puts mass at . The evidence ratio depends only on . With the mode is on the boundary, and only the version works.
Lesson 12 · Gradients of expectations
Move θ. The density of (aqua) slides under the fixed function (black). The lower chart shows and its tangent. Choose the step function : its slope is everywhere except at the jump, but still has a positive slope. The slope of comes from the moving density, not from the slope of .
Two pictures of the same samples. In "move the points", each sample is with fixed noise : change or and every sample slides along its own path (grey dots: the positions at , ). In "reweight the points", the samples stay where they were drawn at , , and their weights change. The derivative of the weight at is the score. Notice that far from a few weights become very large.
Where does the probability go? When grows by , the density on goes down (magenta: the change of the weights, which the score sees) and a new strip gets probability (blue: the boundary term, which the score misses). Compare the two Monte Carlo estimates with the exact slope. Try : the true slope is , but the score-function estimate is .
Three estimators of the same gradient. Each histogram shows 4000 estimates of for , : pathwise, score function and score function with baseline . All three have the same mean, the true value (black line), but the score-function histograms are wide and skewed. Move and find the narrowest violet histogram; the button sets . Increase : every histogram gets narrower by a factor and more symmetric, but the order stays.
Lesson 13 · Calculus of variations
Change N in both views. For and a fixed function , the raw gradient gets smaller as the grid gets finer. Switch to "": the dots now lie on the curve (black). For the minimizer the gradient is zero at every grid point.
Drag the violet handle. It moves a smooth bump (dashed) along the curve and changes . The functional is with and . The chart shows , a parabola, and its tangent at . For the slope at is not zero, so is not a minimizer. Switch to : the slope is for every bump you try.
Move k to the right. Plain gradient descent on the energy loss and on the residual loss of the same discrete Poisson problem, each with the step of its Hessian. Both start at and have the same solution (dashed). The right chart shows the error against the number of steps. Change : grows like and like .
Press Play. Each step is one gradient-descent step on the discretized Dirichlet energy, with step size . The curve becomes smooth: the fast wiggles disappear first, the slow bump last. Now set slightly above , press Reset and Play: the fastest mode grows at every step. This is the stability limit .