Skip to main content

Layer L0

Math and CS foundations

The layer

What this layer is about

This is the most "mathematical" layer on the site, and the one most likely to scare people off, so first let's be clear about what it is not: it is not a math course you have to finish from the beginning. It is a toolbox. As you climb the layers, whenever a step stops you, come back here and take out one tool.

So what does it actually give you? Three abilities. First, you no longer skip the formulas when reading papers: when you see QKᵀ/√d in the Transformer, you can say it computes "how related every pair of words is", and why it divides by √d. Second, when you see a loss value in a training log, you know it is not an abstract score but "how low a probability the model gave the correct answer". Third, when training code runs into numerical trouble (the loss turns into NaN, or goes up instead of down), you know where to look.

This layer has just two finish lines: you can derive the gradient of softmax plus cross-entropy on paper, and you can read the formula sections of any L2 paper without skipping a line.

The map of this layer

First, picture the smallest neural network in your head: a list of numbers goes in, passes through a few layers of computation, and out comes a set of "how confident it is in each answer". That is compared with the correct answer to work out how wrong it was, and then the weights are adjusted backwards. Every node in this layer is one piece of that picture.

The entry node is Math: learn it when you need it. It explains which step in that picture uses which piece of math, and then sends you to four subtopics:

  • Linear algebra: what one layer of a network computes. A layer does many "multiply by coefficients and add up" at once, and written together that is one matrix multiplication. What you practice is looking at an operation and saying how the shape of the data changes. Attention, too, is nothing more than a few matrix multiplications plus one softmax.
  • Probability and statistics: why the model's output is a table of "how likely each answer is" (a distribution), and why the training goal is "make the answer that actually occurred as probable as possible" (maximum likelihood). It also explains what "temperature" adjusts when generating text.
  • Information theory: how to measure "how wrong". The negative log of the likelihood is cross-entropy, the exponential of cross-entropy is perplexity, and the constraint in post-training that says "don't drift too far from the original model" is measured with KL divergence.
  • Optimization: once you know it's wrong, how to fix it. The gradient tells each weight which way to move so the loss goes down, backpropagation is an efficient algorithm for the chain rule, and the optimizer decides how big each step is.

There is no strict order among the four nodes; the real order is "whatever you can't read up above, come back and fill in". In practice, linear algebra comes up most often; probability and information theory are a pair and are best read together; optimization connects most tightly with L1's Loss and backpropagation, and reads most smoothly just before you learn backpropagation.

What you can skip for now

These aren't useless; they're just not worth your time until you reach the step that needs them:

  • Reading any math book "from the beginning". Both "Mathematics for Machine Learning" and Chan's "Introduction to Probability for Data Science" can be read by chapter; read only the chapters the nodes point to.
  • Determinants and proofs about abstract vector spaces in linear algebra. All you need is intuition for matrix multiplication, transposes, norms and eigendecomposition.
  • Measure theory and hypothesis testing in probability. All you need is random variables, conditional probability, expectation and maximum likelihood.
  • Convex optimization theory. It studies bowl-shaped problems with a single lowest point, while a neural network's loss surface is full of bumps and pits and is not convex.
  • Most of information theory. You only need three ideas, entropy, cross-entropy and KL, which is one article's worth.
  • Algorithmic complexity. This layer has no node for it: the part interviews test is in L6, and why attention's compute grows with the square of the length is covered in Transformer.

Top picks

In reading order; each pick links to its node below.

  1. 1

    But what is a neural network? — 3Blue1Brown free

    First watch an animation of what one layer of a network computes; after that, all the math you learn has something to hang on → Math: learn it when you need it

  2. 2

    Essence of linear algebra free

    See matrix multiplication as a geometric move that reshapes vectors, and from then on you can read every Transformer architecture diagram → Linear algebra

  3. 3

    Mathematics for Machine Learning — Deisenroth, Faisal and Ong free

    A free textbook with a chapter each on linear algebra, vector calculus and probability. Look up whichever chapter you're missing → Math: learn it when you need it

  4. 4

    The Matrix Calculus You Need For Deep Learning free

    Covers only the small piece of matrix calculus deep learning uses. Afterwards you can trace the gradient from the loss back to every weight yourself → Math: learn it when you need it

  5. 5

    Introduction to Probability for Data Science free

    Goes from "the probability of two things happening together" to maximum likelihood, and has you derive "cross-entropy is negative log-likelihood" yourself → Probability and statistics

  6. 6

    Visual Information Theory free

    One hour of area diagrams that make entropy, cross-entropy and KL clear. From then on, the values of loss and perplexity mean something to you → Information theory

  7. 7

    An overview of gradient descent optimization algorithms free

    From SGD to Adam, see which flaw of the previous optimizer each one fixed. The lr and betas in training code stop being magic numbers → Optimization

The nodes

Math: learn it when you need it

layer N⋮layer 1weights × vectorThecatsatbecauseitwastiredAttention: “it” looks back, mostly at “cat”

The math you need for AI is less than you think, and more concrete than you think. This node is the entrance to the math layer: first it shows you which pieces of math a neural network actually uses, and at which step each one comes in, then it sends you on to four small nodes. The most important advice comes first: don't finish learning the math before you start. Using models (calling APIs, writing prompts) needs almost no math; changing models, training them and reading papers is where it comes in. The right way to learn is to keep moving forward, and when you hit a step where you can't follow the formulas, come back and fill in that piece.

Where the math is in a neural network

First put the smallest possible model in your head. The input is a list of numbers (say, the brightness of each pixel in a small image), and the output is ten numbers (how confident it is that the image is each digit from 0 to 9). In between are a few layers. What a layer does is plain: multiply each input number by a coefficient and add them all up to get one new number; do this a few hundred times with different coefficients and you get a few hundred new numbers, which go to the next layer. These coefficients are called weights, and they are everything the model learns from the data; a so-called large model is one with billions or hundreds of billions of weights.

In this picture, math shows up in four places:

  • Linear algebra: what a layer computes. Write a few hundred "multiply by coefficients and add up" operations together and you have one matrix multiplication. See Linear algebra.
  • Probability: what the output is. In the end the model does not give one answer; it gives how confident it is in each possible answer. See Probability and statistics.
  • Information theory: how wrong it was. Compare the model's confidence with the correct answer and you get a number for "how badly it went", called the loss; the most common kind is called cross-entropy. See Information theory.
  • Calculus and optimization: how to change it. For each weight, ask: if it moves up a little, does the loss get bigger or smaller? This "which way to move so the loss drops" direction is called the gradient; move a small step along it, repeat millions of times, and that is training. See Optimization.

Why learn it in pieces instead of reading a math book

Of a complete linear algebra or probability textbook, perhaps only a fifth to a third is what deep learning commonly uses: from linear algebra you need matrix multiplication and shapes, not proofs about determinants; from probability you need conditional probability and maximum likelihood, not measure theory. Chew through a book from cover to cover and most of your time goes to things you won't use, and it is easy to give up before you have written your first model. Each of the four subnodes marks out only the part you need.

The cost is that the knowledge comes in scattered pieces, without the complete thread a book gives you. The picks here make up for that, three things each covering one stretch: first watch some animations, to see with your own eyes what a network layer computes; then take a free textbook you can read chapter by chapter, and look up whichever chapter you are missing; finally read a long article that covers only the matrix calculus deep learning uses, and get a full grasp of "how the gradient travels from the loss all the way back to every weight".

How much is enough

There is a concrete test: take a small two-layer network and one example, work out the gradient of every weight on paper, then let PyTorch compute them automatically, and check that the two sets of numbers match. That is this node's project. Once you can do this, when Loss and backpropagation covers backpropagation and Transformer covers attention, the formulas will describe something you have done with your own hands, not a string of symbols.

Leads to
Loss and backpropagation · Classical machine learning: learning from examples · GPU basics: why it's used, and where the bottleneck is · PyTorch: train a network yourself
On the routes
Foundations (How the models work)
  • But what is a neural network? — 3Blue1Brown free

    video · 19 minutes — The linear algebra of a network seen rather than derived: the picture of what a layer computes that the rest of the map builds on.

  • Mathematics for Machine Learning — Deisenroth, Faisal and Ong free

    book · about 20 hours · only ch. 2–6 — Free, and written to be read in parts: linear algebra, vector calculus and probability, each chapter usable alone when a step asks for it.

  • The Matrix Calculus You Need For Deep Learning free

    article · 3 hours — Only the slice of matrix calculus deep learning uses — Jacobians and the chain rule over vectors; by the end you can take a two-layer network's gradients by hand, this step's project.

Hands-on project: Backpropagation by hand, then checked — Work out the gradients of a two-layer network for one example on paper, then compare them with PyTorch's autograd.

Not picked (3)
  • Gilbert Strang, MIT 18.06 — A full-semester linear algebra course. Here you only need to see what one layer computes; look it up as needed in the linear algebra node.
  • Goodfellow 等《Deep Learning》ch. 2–4 — The math is written densely; Deisenroth's MML is just as free and easier to read chapter by chapter.
  • Khan Academy 多元微积分 — Broad coverage but no matrix form; the Parr & Howard piece fills exactly that gap.

Linear algebra

linear-algebratransformerno prerequisite

Linear algebra is the math of "computing lots of numbers together". For neural networks, it is enough to remember its two main characters first: a vector is a list of numbers (for example, a word inside a model is represented as a few hundred numbers), and a matrix is a table of numbers (for example, all the weights of one network layer).

Matrix multiplication: many weighted sums at once

Picture yourself computing students' overall grades. Each student has three scores, homework, midterm and final, and overall = 0.2 × homework + 0.3 × midterm + 0.5 × final. That is one weighted sum. Now the school wants three measures at once (overall, theory and practice), each with its own set of weights. Lay the three sets of weights out as a table and a student's three scores as a list, and a single matrix multiplication gives all three results at once. One layer of a neural network does exactly this, except the input has hundreds or thousands of numbers, and there are hundreds or thousands of "measures" to compute.

That is why you will often hear that a network layer is "multiply by a matrix, add a vector, then pass through a nonlinear function". Multiplying by the matrix is the weighted sum; adding the vector adds one more constant to each result (called the bias); the nonlinear function is a simple bend, such as "turn every negative number into 0". That last step cannot be skipped: without it, any number of stacked matrix multiplications is equivalent to just one.

Shapes: the skill you use most

Matrix multiplication has one hard rule: the number of columns in the left table must equal the number of rows in the right table, and the result has the shape "rows of the left × columns of the right". It sounds like a grade-school rule, yet it is one of the most common sources of errors when you write model code. The thing most worth practicing in linear algebra is this: look at an operation and say how the shape of every tensor (multi-dimensional array) changes.

A few more words you will meet again and again

  • Transpose: swap a table's rows and columns. The superscript T in the attention formula QKᵀ is this.
  • Dot product: multiply two equally long lists of numbers position by position, then add up. The closer two vectors point in the same direction, the bigger their dot product, so it is often used as "similarity": in attention, "how alike a query and a key are" is computed with a dot product. The longer the vectors, the bigger the dot product tends to be, so attention divides the scores by √d (d is the length of the vectors) to pull them back into a stable range.
  • Norm: how "long" a vector is, that is, how large its values are overall. When training keeps weights from growing too large and gradients from exploding, this is what it measures.
  • Eigendecomposition, SVD: break a matrix into a few simpler parts, to see which directions it mainly stretches things in. At this layer you only need to know what they are for; you will meet the idea again in Fine-tuning: teach it your task, with LoRA, which "approximates one big matrix with two small ones".

Where to stop

Don't go on to abstract vector spaces and proofs: that is the math department's linear algebra, and it doesn't line up with how you use it when writing models. This node has two standards: see matrix multiplication as an action (turning one vector into another), and be able to match shapes. It is the most used of the four subtopics of Math: learn it when you need it: deriving gradients in Loss and backpropagation depends on it, and every structure diagram of the Transformer is made of it. The fastest way to learn it is to first watch a set of animations that draw matrix multiplication as geometric transformations, then do this node's project: write attention by hand in numpy once, writing down the shape at every step.

Leads to
Transformer
  • Essence of linear algebra free

    video · 16 episodes, about 3 hours — Draws matrix multiplication, change of basis, determinants and eigenvectors as geometric moves. After it, QKᵀ and projections in attention read as pictures, not symbols.

Hands-on project: Write attention by hand in numpy — Given a 4×8 input matrix (4 tokens, each represented by 8 numbers), write by hand the three projections Q, K and V (each a multiplication by a weight matrix), QKᵀ/√d (a similarity score for every pair of tokens), softmax (turning the scores into weights that add up to 1) and the weighted sum, writing down the shape at every step; then check that your result matches PyTorch's built-in torch.nn.functional.scaled_dot_product_attention.

Not picked (3)
  • Gilbert Strang, MIT 18.06 — A full semester course. Too much for an engineer; go back for proofs when needed.
  • Mathematics for Machine Learning ch. 2–4 — Already the introductory pick for Math: learn it when you need it, so not repeated here.
  • Linear Algebra Done Right (Axler) — Leans on proofs and skips matrix computation, which does not match how ML uses it.

Probability and statistics

probabilitydecoding-and-inferenceno prerequisite

Probability is the language for describing "not certain yet". You can't do without it in AI, because a model never gives just one answer. After reading "The weather today is very", a language model gives you a table: "nice" 0.4, "hot" 0.2, "cold" 0.1, and so on. This table of "how likely each possible outcome is" is called a distribution.

A few words you must know

  • Random variable: a quantity whose outcome is not settled yet, such as "what the next token is".
  • Conditional probability: the probability of one thing once you know another, written P(next word | previous words); the vertical bar reads "given". A language model, from start to finish, is estimating exactly this one thing.
  • Expectation and variance: what a random quantity is on average, and how much it wobbles around that average. The loss during training is the average over a batch of examples, which is essentially an estimate of an expectation.
  • Common distributions: the normal distribution is the bell curve, often used to initialize weights; the categorical distribution is "pick one of several options, each with its own probability", and that is exactly what a language model outputs.

Maximum likelihood: where the training goal comes from

Likelihood asks: if the model were right, how likely is it that we would see the data we actually saw? For example: you toss a coin ten times and get seven heads. What do you guess its probability of heads is? Intuition says 0.7. That is maximum likelihood estimation: among all possible values, pick the one that makes "seven heads in ten tosses" most likely to happen.

Training a language model is the same thing, scaled up billions of times: adjust the weights so that every next token that really appears in the training text gets as high a probability as possible in the model's distribution. Take the negative log of this goal (the log turns a long chain of multiplied probabilities into a sum, and the minus sign flips "bigger is better" into "smaller is better"), and what you get is the cross-entropy loss. Information theory describes the same number from another angle; both sides are talking about one thing.

Where it shows up later

  • Loss functions: Loss and backpropagation uses cross-entropy for classification and mean squared error for predicting numbers, because each matches an assumption about the data (a categorical distribution, a normal distribution), and under its own assumption, minimizing each one is the same as doing maximum likelihood.
  • Generating text: once the model gives a distribution, it still has to pick one token from it. Temperature changes how peaked or flat the distribution is: at a low temperature the high-probability options dominate more and the output is stable; at a high temperature rare options get a chance too and the output is more varied. top-p picks only from the small group of options at the top of the cumulative probability. The details are in Decoding and inference.

Where to stop

Skip measure theory and hypothesis testing; what you need is random variables, conditional probability, expectation and maximum likelihood, enough to explain why the loss looks the way it does. It is one of the four subtopics of Math: learn it when you need it, and it pairs with Information theory. This node's project connects the two: write down the likelihood of a classification task, take the negative log, and watch it turn into cross-entropy.

Leads to
Decoding and inference
  • Introduction to Probability for Data Science free

    book · about 25 hours · only ch. 2–5 — Free probability text with Python code. Its likelihood chapters show why cross-entropy is negative log-likelihood; by chapter 8 you can derive the softmax + cross-entropy gradient.

Hands-on project: Derive cross-entropy from maximum likelihood — Write the likelihood for a classification task, take the negative log, and show it is cross-entropy. Then differentiate with respect to the softmax input to get p − y, and check it with PyTorch autograd.

Not picked (3)
  • Blitzstein & Hwang, Introduction to Probability (Stat 110) — A classic, but written for statistics majors. Too long and too many exercises for an engineer, and I found no independent endorsement strong enough.
  • Seeing Theory(Brown) — Great visuals, but it stops at intuition. You can't derive the likelihood or the gradient from it.
  • Mathematics for Machine Learning ch. 6 — Already among the picks in the intro of Math: fill in as needed.

Information theory

information-theorybackprop-and-losspretraining-and-scalingno prerequisite

Information theory was originally about "the fewest bits needed to send a message". In AI, it gives us a ruler for measuring "how well the model guesses".

Entropy: how hard something is to guess

Start with a game. I think of something, and you can only ask yes / no questions to guess it. If there are just two equally likely options, one question is enough: that is 1 bit. If there are eight equally likely options, you need three questions: 3 bits. If some options are especially common, you ask about the most common ones first, and the average number of questions drops. Entropy is "the average number of questions you need": the harder the outcome is to predict, the higher the entropy.

Cross-entropy: how much extra you pay with the wrong map

Now suppose your estimate of "which options are common" is wrong: you think option X is the most common, when really option Y is. If you still ask questions based on your own estimate, you will need more questions on average. The average cost of guessing "what is really true" using "your estimate" is called cross-entropy.

In training, "what is really true" is the answer that actually appears in the training data, and "your estimate" is the distribution the model gives, so cross-entropy boils down to one sentence: how low a probability the model gives the correct answer. When the model is 100% sure of the correct answer, cross-entropy is 0; the lower the probability it gives, the bigger it gets. This is the loss that most classification models and language models train on (Loss and backpropagation). So the loss value is not an abstract score; it has a meaning: how much information, on average, is still missing per token to pin it down (counting in bits or in another unit called nats differs only by a fixed factor).

KL divergence and perplexity

  • KL divergence: cross-entropy minus entropy, that is, "the extra part you pay because you had the wrong map". It measures how far apart two distributions are, but it is not symmetric: measuring Q against P is not the same as measuring P against Q. Post-training (RLHF, DPO) always requires the new model's distribution not to drift too far from the original model's, and that constraint is measured with KL (Post-training: shaping with rewards).
  • perplexity: take the exponential of cross-entropy, which turns it back into "number of options" terms. A perplexity of 10 roughly means that at every step the model is guessing as if among 10 equally likely options. It is the ruler people watch most during pretraining (Pretraining and scaling). Note that it is computed per token: if two models split text into tokens differently (Tokenizer), you cannot compare their perplexity directly.

Where to stop

You only need three concepts, entropy, cross-entropy and KL, plus one conversion for perplexity: about one long article's worth. It builds on Probability and statistics (cross-entropy is just another name for "negative log-likelihood" on the probability side) and is one of the four subtopics of Math: learn it when you need it. The fastest way to learn it is to read the article in the picks that draws these quantities as area diagrams, then do this node's project: compute the entropy of a piece of text by hand.

Leads to
Loss and backpropagation · Pretraining and scaling
  • Visual Information Theory free

    article · 1 hour — Area charts draw entropy, cross-entropy and KL. You can then say: cross-entropy is the cost of coding with the wrong distribution. Prerequisite for deriving it, perplexity, and DPO's KL term.

Hands-on project: Compute the entropy of a corpus — Count how often each character and each word appears in a piece of text (a unigram distribution, which only looks at how common each character or word is on its own) and compute the entropy; then compute a small language model's cross-entropy and perplexity = exp(cross-entropy) on the same text, and explain why you cannot compare perplexity directly between models that split text into tokens differently, and must convert to average cross-entropy per character or per byte before comparing.

Not picked (2)
  • MacKay, Information Theory, Inference, and Learning Algorithms — A classic full-length book. Only the first few chapters are useful for ML; look up when needed.
  • Cover & Thomas, Elements of Information Theory — Aimed at communication theory; the proof density is more than this layer needs.

Optimization

optimizationbackprop-and-lossno prerequisite

Optimization is about training itself: how to adjust the weights bit by bit so the loss gets smaller.

A walking-downhill analogy

Imagine you are standing blindfolded somewhere in hilly country, and you need to reach the lowest point. You can't see the whole landscape; you can only feel with your feet which way the ground slopes, take a step downhill, then feel again and step again. In training, the "hilly country" is how the loss changes with all the weights, called the loss surface; "the slope under your feet" is the gradient: for each weight, it tells you "if this weight moves up a little, does the loss go up or down, and how fast?" Taking a small step in the opposite direction of the gradient is gradient descent. How big each step is, is called the learning rate. Too small, and you still won't be off the mountain by nightfall; too large, and one step carries you over the valley floor onto the opposite slope, so you climb higher and higher. This is called divergence.

The analogy is off in one place: a real mountain has only two directions, east–west and north–south, while a model's loss surface has billions of directions, one per weight, and cannot be drawn. But the logic of "feel the slope, take a small step" is exactly the same.

How to get the gradient

A weight's gradient comes from the chain rule: the loss depends on the output of the last layer, the last layer depends on the one before it, and so on, all the way back to this weight; multiply together, link by link, "if this changes a little, how much does the next link change". The backpropagation in Loss and backpropagation is the efficient way to do this from the back to the front, computing all the weights in one go.

How to walk steadily: optimizers

The plainest gradient descent has to go through all the data before each step, which is too slow. So there is a chain of improvements, each generation fixing one flaw in the one before:

  • SGD (stochastic gradient descent): take only a small batch of data each time, estimate a rough slope, and step. The estimate is noisy, but it is much faster.
  • Momentum: like a ball rolling downhill, keep part of the previous step's speed. In directions where you swing back and forth, the swings cancel out; where the direction stays the same, you go faster and faster.
  • Adam: set a separate step size for each weight. Weights whose slope has stayed steep take small steps; weights whose slope has stayed gentle take big ones. It is the default choice for training large models today, and in practice the improved version AdamW is used more: it takes the "keep the weights from growing too large" term out of the gradient and handles it separately. The betas parameter of Adam in training code is how much of the old values each of its two "memories of the past" keeps.
  • Learning rate schedule: the learning rate is not a fixed value. At the very start of training you "warm up" with a very small learning rate (warmup), then lower it step by step (for example, decaying along a cosine curve, cosine decay).

Convex and non-convex

The optimization problems in math class are often convex: like a bowl, there is only one lowest point, and if you keep walking downhill you are sure to reach it. A neural network's loss surface is not convex: it is full of bumps and dips, with many low points. So most of the theory of convex optimization does not apply here; luckily, in practice, the low points a large network finds are usually good enough.

Where it leads

Of the four subtopics of Math: learn it when you need it, this is the one most tightly connected to Loss and backpropagation: backpropagation computes the gradients, and the optimizer decides how those gradients become updates to the weights. After reading this, you should be able to look at lr, momentum and betas in training code and say what each one controls. In Pretraining and scaling, you will see how crucial learning rate warmup and decay are in training large models. This node's project is to write three optimizers by hand on a bowl-shaped function and plot their paths downhill to compare them.

Leads to
Loss and backpropagation
  • An overview of gradient descent optimization algorithms free

    article · 1 hour — From batch gradient descent to SGD, momentum and Adam, one piece shows what each optimizer changed from the last. You'll see what lr, momentum and betas control in training code.

Hands-on project: Write three optimizers by hand — On a two-dimensional bowl-shaped function, write the update rules for SGD, momentum and Adam by hand and plot the three descent paths; then do it again on a long, narrow valley that is very steep in one direction and very flat in the other (this is called ill-conditioning), and explain why Adam moves more steadily on this terrain.

Not picked (3)
  • Boyd & Vandenberghe, Convex Optimization — Deep learning loss surfaces are not convex, so most of this book does not apply.
  • 3Blue1Brown「Gradient descent, how neural networks learn」 — Overlaps with the video series from the same author already imported in Math: learn it when you need it. After the first episode you'll keep watching anyway.
  • Goodfellow 等《Deep Learning》ch. 8 — Solid content, but it doesn't cover optimizer practice after 2016 (AdamW, warmup).

Self-check

  • On paper, I can write the gradient of softmax + cross-entropy with respect to the logits (p − y), and say which chain rule step each line uses. (Hint: the logits are the raw scores before softmax; the result means "push the correct class's score up, push the wrong ones down".)
  • Given an input of shape (batch, seq, d), I can write the tensor shape at every step of single-head attention, and explain why we divide by √d. (Hint: batch is how many sentences in a batch, seq is how many tokens per sentence, d is how many numbers represent each token; the longer the vectors, the larger the dot products.)
  • I can state in one sentence how cross-entropy, KL divergence and perplexity relate. (Hint: KL = cross-entropy − entropy; perplexity = the exponential of cross-entropy.)
  • Reading Adam's update formula, I can say what β₁, β₂ and ε each do, and how AdamW differs from Adam. (Hint: two "memories" of past gradients, and a small number that prevents dividing by zero; the difference is where weight decay goes.)
  • I can open the methods section of any L2 paper and read the formulas through without skipping a line. (Hint: when a line stops you, see which piece of math it belongs to and go back to that node in this layer.)

Hands-on projectTake a small two-layer network and one example, compute the gradient of every weight by hand on paper, then have PyTorch's autograd compute it too, and compare them term by term. When the numbers match on both sides, you've confirmed you really understand how the gradient flows from the loss back to every weight; any term that doesn't match tells you exactly which chain rule step you haven't thought through (attached to Math: learn it when you need it).

Spot a mistake on this page?