Library · CC BY-SA 4.0

Alice's Adventures in aDifferentiable Wonderland

Alice's Adventures in a Differentiable Wonderland, Volume I: A Tour of the Land

Cover illustration of the book

Choose your version

The same text, told at every level, in every language and look shown here. Pick, then listen or download.

Listen and watch

The same player the product gives for your own book: the voice, the drawings as they are drawn, the text.

A modern textbook on how neural networks really work, from tensors and gradients to transformers. Chapter 6 shows how a program finds its own gradients: automatic differentiation, the reverse walk behind every trained model.

This is a sample: 1 of 13 chapters.

From the lectures

Two grids side by side: on the left a 2 by 3 grid labelled input Jacobian, on the right a 2 by 6 grid labelled weight Jacobian, each with its rows marked as outputs.
A Program Made of Small Steps

The Two Jacobians of a Layer

The only thing assumed about each primitive is that we know how to compute its partial derivatives with respect to its two arguments. The first is the input Jacobian, ∂ₓ[f(𝐱, 𝐰)] ∼ (c′, c): how each output moves when each input is nudged.

Two primitive boxes f1 and f2 in a row, then a 2 by 4 grid times a 4 by 3 grid equals a 2 by 3 grid, the shapes labelled 2×4, 4×3 and 2×3.
Three Ways to Get a Derivative

Chain Rule as a Table Product

Now the third way, starting from the chain rule. Take two primitives in a row, 𝐡 = f₁(𝐱), 𝐲 = f₂(𝐡). The chain rule of Jacobians says ∂ₓ𝐲 = ∂_𝐡𝐲 · ∂ₓ𝐡.

The chain 2, times 3, times 5 gives 6 and 30; red arrows then run back from the end carrying 1, 5 and 15, handing out gradients 6 for w2 and 10 for w1.
Turning the Chain Around

Backwards on the Calculator

Take the calculator chain from the last part again: x is 2, multiplied by w₁ equal to 3, then by w₂ equal to 5. Run it forward and write down what you see: 6 after the first step, 30 after the second. Now start backwards with h̃ equal to 1.

A column v holding 1 and minus 1 times a row x holding 1 and 2 makes a 2 by 2 table with rows 1, 2 and minus 1, minus 2, each entry v i times x j.
The Backward Step of a Layer

The Weight VJP Is an Outer Product

The weight VJP turns out to be an outer product, with no rank-3 tensor anywhere: vjp_f,𝐰(𝐯) = 𝐯𝐱ᵀ. An outer product of two vectors is the table whose entry in row i and column j is the i-th entry of the first times the j-th entry of the second.

The S-shaped sigmoid climbing from 0 to 1, and under it its derivative as a low hump that peaks at 0.25 at s equal to 0.
Frameworks, and Why the ReLU Wins

The Sigmoid's Slope Peaks at a Quarter

Now the sigmoid, the S-shaped curve σ(s) that was popular in the past as a soft version of the step function. Its derivative is σ′(s) = σ(s)(1 − σ(s)). In words: the slope is the value times what is left to reach 1.

Three boxes labelled ReLU, ReLU2 and ReLU3 each with an arrow to the value its backward pass returns at zero: 0, 1 and 0.5.
The Corner of the ReLU

Same Function, Three Answers

The full story is trickier. For functions that are not convex, a subgradient need not exist, and one turns to generalizations that relax the definition to a small neighbourhood of x, such as the Clarke subdifferential.

How it was made

Examples for: a curious adult with school maths who uses AI apps every day; add one modern instance per idea, such as how a chat assistant or a phone's photo app is trained

The source

The lectures retell the English text of arXiv 2404.17625 (version 3, 2025) by Simone Scardapane, published under an open licence that allows retelling and translation. The retelling, the drawings and the voice are made by AI and checked against the book by a second model. How AI is used.

The lectures adapt the original and are released under the same licence, free to share and adapt with credit to the author and a link to this page: CC BY-SA 4.0

Your own hard book, the same way

Upload a textbook or any difficult book. The first five minutes are free.

Upload a book