3Blue1Brown Derives Backpropagation Gradients via Chain-Rule Sums

Backpropagation calculus | Deep Learning Chapter 4 — 3Blue1Brown

3Blue1Brown

Backpropagation calculates parameter updates by multiplying upstream neuron activations with downstream error sensitivities, requiring a sum across all outgoing pathways to propagate corrections recursively through earlier layers.

AI-assisted summary of Backpropagation calculus | Deep Learning Chapter 4 — original source. Check the original for full context.

Source published:

Key ideas

  • Backpropagation formalizes the intuitive adjustment of weights and biases through the calculus chain rule, calculating how sensitive the final cost is to small nudges in each parameter along the computational pipeline. (0:38)
  • The derivative of the cost with respect to a weight depends directly on the activation of the preceding neuron (∂z/∂w = a^(L-1)), mirroring the Hebbian learning principle that connections between active neurons undergo stronger updates. (3:56)
  • Extending backpropagation to multi-neuron layers requires summing partial derivatives across all downstream neurons, because each neuron in a preceding layer influences the final cost through multiple simultaneous paths. (6:42)
  • Evaluating cost sensitivity with respect to prior-layer activations (∂C₀/∂a^(L-1)) provides the necessary recursive bridge to propagate gradients backwards through the entire depth of the network. (5:39)

Detailed notes

## Background Published by 3Blue1Brown on YouTube on November 3, 2017, this video is the fourth chapter in the Deep Learning series. According to the page description, it offers a symbol-heavy, formal representation of the intuition behind backpropagation presented in part three, connecting conceptual animations to standard equations and codebase implementations.

## TL;DR Grant Sanderson derives the calculus of the backpropagation algorithm using a toy neural network where each layer contains a single neuron. By viewing the chain rule as a sequence of sensitivity ratios along a computational pipeline, he shows how to calculate the cost function's sensitivity with respect to weights, biases, and previous activations. He reveals that computing a single weight derivative constitutes most of the work, with prior neuron activations and prediction errors dictating weight adjustments in a manner mirroring Hebbian learning. Finally, he scales the formulation to multi-neuron architectures, showing that tracking indices and summing across parallel branching pathways enables identical equations to propagate recursively through the entire network.

## Atmosphere & style The presentation is patient, pedagogical, and calm, characterized by Grant Sanderson's trademark gentle and encouraging delivery. Despite tackling intimidating layers of subscripts and nested derivatives, the tone remains reassuring as viewers are urged to pause, ponder, and let the formalisms settle. It feels like an illuminating bridge between visual intuition and rigorous mathematical mechanics, culminating in a quiet sense of triumph upon uncovering the computational engine powering deep learning.

## Bulletin - [00:38](https://www.youtube.com/watch?v=tIeHLnjs5U8&t=38s) Backpropagation formalizes the intuitive adjustment of weights and biases through the calculus chain rule, calculating how sensitive the final cost is to small nudges in each parameter along the computational pipeline. - [03:56](https://www.youtube.com/watch?v=tIeHLnjs5U8&t=236s) The derivative of the cost with respect to a weight depends directly on the activation of the preceding neuron (∂z/∂w = a^(L-1)), mirroring the Hebbian learning principle that connections between active neurons undergo stronger updates. - [06:42](https://www.youtube.com/watch?v=tIeHLnjs5U8&t=402s) Extending backpropagation to multi-neuron layers requires summing partial derivatives across all downstream neurons, because each neuron in a preceding layer influences the final cost through multiple simultaneous paths. - [05:39](https://www.youtube.com/watch?v=tIeHLnjs5U8&t=339s) Evaluating cost sensitivity with respect to prior-layer activations (∂C₀/∂a^(L-1)) provides the necessary recursive bridge to propagate gradients backwards through the entire depth of the network.

## Key takeaways - [00:00](https://www.youtube.com/watch?v=tIeHLnjs5U8&t=0s) Chapter 4 aims to translate the high-level intuition of backpropagation from previous lessons into formal calculus and standard mathematical notation. - [00:38](https://www.youtube.com/watch?v=tIeHLnjs5U8&t=38s) Machine learning practitioners interpret the chain rule as a sequence of sensitivity ratios tracking how small nudges propagate through intermediate variables to the final cost. - [01:15](https://www.youtube.com/watch?v=tIeHLnjs5U8&t=75s) In a simplified single-neuron-per-layer network, superscripts are reserved for layer indexing, keeping subscripts available for individual neuron indexing in larger models. - [02:58](https://www.youtube.com/watch?v=tIeHLnjs5U8&t=178s) The chain rule expands the sensitivity of cost C₀ to weight w^(L) into three distinct factors: ∂z/∂w, ∂a/∂z, and ∂C₀/∂a. - [03:56](https://www.youtube.com/watch?v=tIeHLnjs5U8&t=236s) The derivative ∂C₀/∂a^(L) equals 2(a^(L) - y), scaling proportionally with the prediction error so larger mistakes induce stronger corrective updates. - [04:45](https://www.youtube.com/watch?v=tIeHLnjs5U8&t=285s) The derivative ∂z^(L)/∂w^(L) equals the activation of the preceding neuron a^(L-1), reflecting Hebbian learning where active inputs cause greater weight adjustments. - [05:15](https://www.youtube.com/watch?v=tIeHLnjs5U8&t=315s) The gradient for the overall network requires averaging individual cost derivatives across the entire training dataset or mini-batch. - [05:39](https://www.youtube.com/watch?v=tIeHLnjs5U8&t=339s) Deriving cost sensitivity with respect to a bias b^(L) uses the exact same chain structure, replacing the input factor with ∂z/∂b = 1. - [06:12](https://www.youtube.com/watch?v=tIeHLnjs5U8&t=372s) Computing the derivative of the cost with respect to preceding activation a^(L-1) is essential for recursively repeating the chain rule into earlier layers. - [06:42](https://www.youtube.com/watch?v=tIeHLnjs5U8&t=402s) Weight indexing uses w_jk^(L), listing the destination neuron j first and source neuron k second to align naturally with standard matrix-vector multiplication. - [08:25](https://www.youtube.com/watch?v=tIeHLnjs5U8&t=505s) In multi-neuron networks, a neuron's activation feeds forward into multiple destinations, requiring a summation across all connected neurons in the next layer to capture total cost sensitivity. - [09:13](https://www.youtube.com/watch?v=tIeHLnjs5U8&t=553s) Together, these iterative calculus expressions assemble the full gradient vector that guides gradient descent steps to minimize network error.

## Detailed walkthrough ### [00:00](https://www.youtube.com/watch?v=tIeHLnjs5U8&t=0s) Setting Up the Simple Network and the Chain Rule

Grant Sanderson begins by noting that this walkthrough assumes the viewer has watched chapter 3, which established the intuitive picture of the backpropagation algorithm. The purpose here is to formalize that intuition through calculus and notation, bridging the conceptual animations with the standard equations found in textbooks and code. He acknowledges that this material is dense and symbol-heavy: “It's normal for this to be at least a little confusing, so the mantra to regularly pause and ponder certainly applies as much here as anywhere else.” The perspective ML practitioners adopt toward the chain rule feels distinct from introductory calculus courses, viewing it as a sequence of sensitivity ratios along a computational pipeline.

```mermaid flowchart LR accTitle: Single Neuron Computational Flow accDescr: Computational pipeline showing how inputs, weights, and bias determine the intermediate value z, activation a, and cost C. subgraph LayerInputs["Inputs & Parameters"] A["a^(L-1)"] W["w^(L)"] B["b^(L)"] end subgraph ForwardPass["Forward Evaluation"] Z["z^(L)"] AL["a^(L)"] end subgraph LossEval["Evaluation"] Y["y (target)"] C["C_0 (Cost)"] end

A --> Z W --> Z B --> Z Z --> AL AL --> C Y --> C ```

To make the mechanics manageable, Sanderson strips the architecture down to a minimal toy model: a network where every layer contains exactly one neuron. Such a network with three hidden layers is governed by three weights and three biases. The goal is to see how sensitive the final cost is to adjustments in these parameters so the network can alter them to efficiently minimize error. Isolating the connection between the final two layers, the activation of the final neuron is labeled $a^{(L)}$ and the activation of the penultimate neuron is labeled $a^{(L-1)}$. Sanderson emphasizes that superscripts represent layer indices rather than algebraic exponents, keeping subscripts open for neuron indexing later.

For a single training example with desired target value $y$ (such as $0$ or $1$), the squared error cost is defined as $C_0 = (a^{(L)} - y)^2$. The final activation is produced by taking the weighted sum $z^{(L)} = w^{(L)} a^{(L-1)} + b^{(L)}$ and passing it through a non-linear activation function $\sigma$ (such as the sigmoid or ReLU), giving $a^{(L)} = \sigma(z^{(L)})$. Thinking of every variable as having its own number line, Sanderson traces the causal chain: a small nudge $\partial w^{(L)}$ causes an intermediate nudge $\partial z^{(L)}$, which triggers a nudge $\partial a^{(L)}$, which finally nudges $C_0$. Applying the chain rule translates this sequence into a product of three localized derivatives:

$$\frac{\partial C_0}{\partial w^{(L)}} = \frac{\partial z^{(L)}}{\partial w^{(L)}} \frac{\partial a^{(L)}}{\partial z^{(L)}} \frac{\partial C_0}{\partial a^{(L)}}$$

- **Target notation**: $y$ represents the ideal output value for a given training example. - **Cost expression**: $C_0 = (a^{(L)} - y)^2$ evaluates performance on that single example. - **Weighted input**: $z^{(L)} = w^{(L)} a^{(L-1)} + b^{(L)}$ bundles the linear combination before activation.

---

[03:56](https://www.youtube.com/watch?v=tIeHLnjs5U8&t=236s) Computing Derivatives and Their Intuitive Meaning

Sanderson breaks down each individual factor of the chain rule product to reveal what the algebra actually computes. Evaluating from the output backward: 1. The derivative of the cost with respect to the final activation is $\frac{\partial C_0}{\partial a^{(L)}} = 2(a^{(L)} - y)$. Its magnitude scales directly with the gap between the actual output and the desired target, meaning severe prediction errors produce large derivatives that exert strong corrective pressure. 2. The derivative of the activation with respect to the pre-activation input is $\frac{\partial a^{(L)}}{\partial z^{(L)}} = \sigma'(z^{(L)})$, simply the slope of the chosen activation function evaluated at $z^{(L)}$. 3. The derivative of the weighted sum with respect to the weight is $\frac{\partial z^{(L)}}{\partial w^{(L)}} = a^{(L-1)}$.

Sanderson urges viewers not to lose the big picture in the algebra: “In the case of this last derivative, the amount that the small nudge to the weight influenced the last layer depends on how strong the previous neuron is.” This directly reflects the classic Hebbian learning principle that neurons that fire together wire together: when the feeding neuron $a^{(L-1)}$ has a high activation, changing its connecting weight produces a far more pronounced effect on downstream computations.

He clarifies that this product gives the gradient component of the cost $C_0$ for just one training instance. Because the overall network cost function $C$ is the average of individual costs across all training examples, the true partial derivative with respect to any weight requires averaging that expression over the full dataset (or a mini-batch). This single term forms just one component of the full gradient vector, which packages the partial derivatives of the cost with respect to every single weight and bias across the entire network.

---

[05:39](https://www.youtube.com/watch?v=tIeHLnjs5U8&t=339s) Sensitivity to Biases and Propagating Backward

Even though calculating one weight derivative seems like a tiny fraction of the whole network, Sanderson points out that “even though that's just one of the many partial derivatives we need, it's more than 50% of the work.” Determining sensitivity to the bias $b^{(L)}$ requires swapping only the final term in the chain: replacing $\frac{\partial z^{(L)}}{\partial w^{(L)}}$ with $\frac{\partial z^{(L)}}{\partial b^{(L)}}$. Because $z^{(L)} = w^{(L)} a^{(L-1)} + b^{(L)}$, the partial derivative with respect to $b^{(L)}$ evaluates to $1$:

$$\frac{\partial C_0}{\partial b^{(L)}} = \frac{\partial z^{(L)}}{\partial b^{(L)}} \frac{\partial a^{(L)}}{\partial z^{(L)}} \frac{\partial C_0}{\partial a^{(L)}} = 1 \cdot \sigma'(z^{(L)}) \cdot 2(a^{(L)} - y)$$

```mermaid flowchart TD accTitle: Backpropagation Iteration Cycle accDescr: Flow diagram showing how cost sensitivity flows from Layer L activations back to weights, biases, and the prior layer activations. subgraph LayerL["Layer L Derivatives"] dC_daL["∂C₀ / ∂a^(L)"] dC_dzL["∂C₀ / ∂z^(L) = σ'(z^(L)) · ∂C₀ / ∂a^(L)"] end subgraph LayerLParams["Parameter Updates"] dW["∂C₀ / ∂w^(L) = a^(L-1) · ∂C₀ / ∂z^(L)"] dB["∂C₀ / ∂b^(L) = 1 · ∂C₀ / ∂z^(L)"] end subgraph PriorLayer["Propagation Step"] dC_daLprev["∂C₀ / ∂a^(L-1) = w^(L) · ∂C₀ / ∂z^(L)"] end

dC_daL --> dC_dzL dC_dzL --> dW dC_dzL --> dB dC_dzL --> dC_daLprev ```

Crucially, this framework also reveals how sensitive the cost function is to the activation of the preceding neuron, $\frac{\partial C_0}{\partial a^{(L-1)}}$. Evaluating the initial sensitivity of $z^{(L)}$ to $a^{(L-1)}$ yields the weight itself: $\frac{\partial z^{(L)}}{\partial a^{(L-1)}} = w^{(L)}$. While the network cannot directly tweak an activation value—since activations are determined strictly by earlier layers—computing this sensitivity is essential. It serves as the launchpad for the recursive step: once the sensitivity to $a^{(L-1)}$ is known, the exact same chain rule pattern propagates backwards to assess sensitivity to all preceding weights $w^{(L-1)}$ and biases $b^{(L-1)}$.

---

[06:42](https://www.youtube.com/watch?v=tIeHLnjs5U8&t=402s) Scaling to Layers with Multiple Neurons

Moving from a single-neuron chain to real networks with multiple neurons per layer might seem daunting, but Sanderson reassures the viewer that “honestly, not that much changes when we give the layers multiple neurons, really it's just a few more indices to keep track of.” In a multi-neuron architecture: - Subscript $k$ indexes neurons in the prior layer $L-1$. - Subscript $j$ indexes neurons in the current layer $L$. - The activation of the $j$-th neuron in layer $L$ is written as $a_j^{(L)}$. - The connection strength between neuron $k$ in layer $L-1$ and neuron $j$ in layer $L$ is designated $w_{jk}^{(L)}$.

Sanderson admits that indexing the weight as $w_{jk}^{(L)}$ (destination index first, source index second) can feel backward at first glance, but explains that this convention is deliberate: it matches standard matrix multiplication, where row $j$ of a weight matrix multiplies the activation vector to produce the $j$-th entry of the output.

```mermaid flowchart LR accTitle: Multi-Neuron Branching Influence accDescr: Diagram illustrating how a single neuron in layer L-1 branches out to influence multiple neurons in layer L, requiring a summation in backprop. subgraph LayerPrev["Layer L-1"] ak["a_k^(L-1)"] end subgraph LayerCurr["Layer L"] zj0["z_0^(L)"] --> aj0["a_0^(L)"] zj1["z_1^(L)"] --> aj1["a_1^(L)"] end subgraph FinalCost["Cost Function"] Cost["C_0 = Σ (a_j^(L) - y_j)²"] end

ak -->|"w_0k^(L)"| zj0 ak -->|"w_1k^(L)"| zj1 aj0 --> Cost aj1 --> Cost ```

The overall cost function for a single example sums the squared errors across all output neurons:

$$C_0 = \sum_{j} (a_j^{(L)} - y_j)^2$$

The pre-activation weighted sum for neuron $j$ is $z_j^{(L)} = \sum_k w_{jk}^{(L)} a_k^{(L-1)} + b_j^{(L)}$, followed by $a_j^{(L)} = \sigma(z_j^{(L)})$. The derivative of the cost with respect to an individual weight $w_{jk}^{(L)}$ maintains an identical structure to the single-neuron case:

$$\frac{\partial C_0}{\partial w_{jk}^{(L)}} = \frac{\partial z_j^{(L)}}{\partial w_{jk}^{(L)}} \frac{\partial a_j^{(L)}}{\partial z_j^{(L)}} \frac{\partial C_0}{\partial a_j^{(L)}} = a_k^{(L-1)} \cdot \sigma'(z_j^{(L)}) \cdot 2(a_j^{(L)} - y_j)$$

The key mathematical difference appears when computing the derivative with respect to an activation in the previous layer, $a_k^{(L-1)}$. Because activation $a_k^{(L-1)}$ branches out and feeds into every neuron in layer $L$, it influences the cost function through multiple distinct pathways simultaneously. To capture its total impact, the sensitivities through each pathway must be summed together:

$$\frac{\partial C_0}{\partial a_k^{(L-1)}} = \sum_j \frac{\partial z_j^{(L)}}{\partial a_k^{(L-1)}} \frac{\partial a_j^{(L)}}{\partial z_j^{(L)}} \frac{\partial C_0}{\partial a_j^{(L)}} = \sum_j w_{jk}^{(L)} \cdot \sigma'(z_j^{(L)}) \cdot \frac{\partial C_0}{\partial a_j^{(L)}}$$

Once this aggregated sensitivity for each neuron $k$ in layer $L-1$ is computed, the exact same equations iterate backwards through the entire depth of the network. Sanderson celebrates reaching this milestone: “If all of this makes sense, you have now looked deep into the heart of backpropagation, the workhorse behind how neural networks learn.” These mathematical expressions systematically populate the gradient vector, providing the exact numerical direction needed to minimize cost by repeatedly stepping downhill. He concludes with an encouraging note to let the concepts settle, acknowledging that tracking these nested layers of indices and derivatives takes time to fully digest.

## Notable quotes > [06:42](https://www.youtube.com/watch?v=tIeHLnjs5U8&t=402s) honestly, not that much changes when we give the layers multiple neurons, really it's just a few more indices to keep track of. — Grant Sanderson

## Mentioned 3Blue1Brown, Grant Sanderson, Vincent Rubinetti, Влад Бурмистров, Omer Tuchfeld, ReLU, Sigmoid

## Video description Help fund future projects: https://www.patreon.com/3blue1brown An equally valuable form of support is to share the videos. Special thanks to these supporters: http://3b1b.co/nn3-thanks Written/interactive form of this series: https://www.3blue1brown.com/topics/neural-networks

This one is a bit more symbol-heavy, and that's actually the point. The goal here is to represent in somewhat more formal terms the intuition for how backpropagation works in part 3 of the series, hopefully providing some connection between that video and other texts/code that you come across later.

For more on backpropagation: http://neuralnetworksanddeeplearning.com/chap2.html https://github.com/mnielsen/neural-networks-and-deep-learning http://colah.github.io/posts/2015-08-Backprop/

Music by Vincent Rubinetti: https://vincerubinetti.bandcamp.com/album/the-music-of-3blue1brown

Thanks to these viewers for their contributions to translations Звуковая дорожка на русском языке: Влад Бурмистров. Hebrew: Omer Tuchfeld

------------------ Video timeline 0:00 - Introduction 0:38 - The Chain Rule in networks 3:56 - Computing relevant derivatives 4:45 - What do the derivatives mean? 5:39 - Sensitivity to weights/biases 6:42 - Layers with additional neurons 9:13 - Recap ------------------

3blue1brown is a channel about animating math, in all senses of the word animate. And you know the drill with YouTube, if you want to stay posted on new videos, subscribe, and click the bell to receive notifications (if you're into that): http://3b1b.co/subscribe

If you are new to this channel and want to see more, a good place to start is this playlist: http://3b1b.co/recommended

Various social media stuffs: Website: https://www.3blue1brown.com Twitter: https://twitter.com/3Blue1Brown Patreon: https://patreon.com/3blue1brown Facebook: https://www.facebook.com/3blue1brown Reddit: https://www.reddit.com/r/3Blue1Brown

[Source](https://www.youtube.com/watch?v=tIeHLnjs5U8)

中文简报

3Blue1Brown通过链式法则求和推导反向传播梯度 反向传播通过将上游神经元激活值与下游误差敏感度相乘来计算参数更新,这需要对所有输出路径求和,从而将修正递归传播至更早的层。 Grant Sanderson利用每层仅包含单个神经元的简化神经网络推导了反向传播算法的微积分原理。他将链式法则视为沿计算流水线的一系列敏感度比率,展示了如何计算代价函数对权重、偏置以及前一层激活值的敏感度。他指出,计算单个权重导数就构成了大部分工作,其中前一神经元的激活值和预测误差决定了权重的调整方式,这与赫布学习理论相呼应。最后,他将这一公式扩展至多神经元架构,表明通过追踪索引并在并行分支路径上求和,使得相同的方程能够递归传播至整个网络。 反向传播通过微积分链式法则将权重和偏置的直观调整形式化,计算最终代价对计算流水线中各参数微小变动的敏感程度。 (0:38) 代价对权重的导数直接取决于前一个神经元的激活值(∂z/∂w = a^(L-1)),这呼应了赫布学习原则,即活跃神经元之间的连接会经历更强的更新。 (3:56) 将反向传播扩展到多神经元层需要对所有下游神经元的偏导数求和,因为前一层中的每个神经元都会通过多条并发路径影响最终代价。 (6:42) 评估代价对前一层激活值的敏感度(∂C₀/∂a^(L-1)),提供了将梯度反向递归传播贯穿整个网络深度所需的必要桥梁。 (5:39)

Reading summary

Grant Sanderson formalizes the backpropagation algorithm by framing the chain rule as a sequence of localized sensitivity ratios along a computational pipeline. Using a single-neuron toy model before scaling to full layers, he demonstrates how error signals propagate backward to systematically calculate gradient components for weights and biases. The Chain Rule as Localized Sensitivities (0:00) To formalize the calculus of backpropagation, Sanderson isolates a single-neuron-per-layer network governed by sequential weights and biases. In this model, superscripts denote layer indices, where the penultimate activation is labeled $a^{(L-1)}$ and the final activation is $a^{(L)}$. The linear combination $z^{(L)} = w^{(L)} a^{(L-1)} + b^{(L)}$ is transformed by an activation function $\sigma$ to produce $a^{(L)} = \sigma(z^{(L)})$, while performance on a single training example with target $y$ is measured by the squared error cost $C_0 = (a^{(L)} - y)^2$. Sanderson frames the chain rule not as an abstract algebraic identity, but as a chain of physical nudges traveling through the network. A small adjustment to the weight $\partial w^{(L)}$ perturbs the pre-activation input $\partial z^{(L)}$, which in turn alters the activation $\partial a^{(L)}$ and finally shifts the cost $C_0$. Multiplying the partial derivatives of each intermediate step yields the sensitivity of the cost with respect to that weight: $\frac{\partial C_0}{\partial w^{(L)}} = \frac{\partial z^{(L)}}{\partial w^{(L)}} \frac{\partial a^{(L)}}{\partial z^{(L)}} \frac{\partial C_0}{\partial a^{(L)}}$. Derivative Factors and Hebbian Intuition (3:56) Evaluating the individual terms reveals the mechanical intuition behind parameter updates. The derivative of the cost with respect to the output activation evaluates to $2(a^{(L)} - y)$, scaling the corrective signal directly with the size of the prediction error. The second factor, $\sigma'(z^{(L)})$, measures the slope of the activation function at the current operating point. The final factor evaluates to the prior activation, $\frac{\partial z^{(L)}}{\partial w^{(L)}} = a^{(L-1)}$. Sanderson points out that because the weight derivative scales directly with $a^{(L-1)}$, adjusting a weight has a larger effect when the preceding neuron fires strongly. This mirrors the classic Hebbian rule that neurons that fire together wire together. Furthermore, because $C_0$ reflects only a single training instance, calculating the true partial derivative for the global cost function requires averaging these localized terms across the entire dataset or mini-batch. Bias Derivatives and Recursive Backward Propagation (5:39) Computing sensitivity to the bias requires altering only the final link in the chain rule product. Because $z^{(L)} = w^{(L)} a^{(L-1)} + b^{(L)}$, the partial derivative $\frac{\partial z^{(L)}}{\partial b^{(L)}}$ equals $1$, leaving the remaining derivative chain identical: $\frac{\partial C_0}{\partial b^{(L)}} = 1 \cdot \sigma'(z^{(L)}) \cdot 2(a^{(L)} - y)$. Sanderson notes that mastering the weight derivative effectively completes the majority of the mathematical work needed for other parameters. The same framework determines the cost's sensitivity to the preceding neuron's activation, $\frac{\partial C_0}{\partial a^{(L-1)}}$, where the initial factor evaluates to the weight $w^{(L)}$. While a network cannot directly adjust activation values, establishing this derivative is vital: it serves as the launching point for recursion, enabling the algorithm to step backward and compute parameter sensitivities for all preceding layers $L-1$, $L-2$, and beyond. Scaling to Multi-Neuron Layers (6:42) Transitioning to realistic networks introduces additional indexing without fundamentally altering the underlying calculus. Sanderson uses subscript $j$ for neurons in layer $L$, subscript $k$ for neurons in layer $L-1$, and designates the connecting weight as $w_{jk}^{(L)}$. This destination-first ordering aligns directly with standard matrix multiplication. In this setup, the single-example cost aggregates error across all output units, $C_0 = \sum_j (a_j^{(L)} - y_j)^2$, and the derivative with respect to any individual weight $w_{jk}^{(L)}$ retains the single-neuron product form. The primary structural difference arises when computing sensitivity to a prior activation, $a_k^{(L-1)}$. Because neuron $k$ fans out to influence multiple destination neurons in layer $L$, it affects the final cost through multiple simultaneous computational pathways. Consequently, its total sensitivity requires summing the chain rule products across every connected neuron $j$: $\frac{\partial C_0}{\partial a_k^{(L-1)}} = \sum_j w_{jk}^{(L)} \sigma'(z_j^{(L)}) \frac{\partial C_0}{\partial a_j^{(L)}}$. Sanderson concludes that backpropagation serves as the computational engine of neural network learning by systematically calculating every component of the gradient vector. While acknowledging that tracking dense indices and nested derivatives requires time to absorb, he emphasizes that the entire procedure is simply the repeated application of localized chain-rule evaluations propagating downhill toward minimal cost.

精炼阅读摘要

Grant Sanderson 在 3Blue1Brown 视频中,通过微积分与链式法则将反向传播算法的直观几何认知形式化为严格的数学表达,阐明了损失函数如何通过层层导数敏感度沿着网络计算链逆向传播。 单神经元模型与链式法则敏感度分解 (0:00) Sanderson 首先构建了一个极端简化的单神经元链条模型,其中每层仅包含一个神经元。在单样本情境下,若目标值为 y,二次代价函数定义为 C₀ = (a^(L) - y)²,其中最终激活值 a^(L) 由线性组合 z^(L) = w^(L) a^(L-1) + b^(L) 经非线性激活函数 σ 映射得到。针对特定权重 w^(L) 的微调,通过链式法则被分解为三个局部偏导数的乘积:∂C₀/∂w^(L) = (∂z^(L)/∂w^(L)) · (∂a^(L)/∂z^(L)) · (∂C₀/∂a^(L))。这种表达直观反映了计算链条各环节间的敏感度传递比例。 各阶导数的代数解析与赫布学习直觉 (3:56) 对链式法则中三个导数因子的逐层展开表明:∂C₀/∂a^(L) = 2(a^(L) - y),其幅度直接取决于实际输出与目标之间的偏差,误差越大产生的修正压力越强;∂a^(L)/∂z^(L) = σ'(z^(L)),即所选激活函数在输入点处的斜率;而 ∂z^(L)/∂w^(L) 则等于上一层神经元的激活值 a^(L-1)。Sanderson 指出,末项意味着权重调整对输出的影响取决于前驱神经元的激活强度,这直接呼应了神经元“齐发者同联”(Hebbian learning)的直觉。此外,单样本下的导数仅为整体梯度的一个分量,实际网络总代价函数 C 是全数据集(或小批量)误差的均值,因此最终参数梯度需要跨样本平均。 偏置灵敏度与反向递归的基础构建 (5:39) 计算单个权重的导数看似仅是全网络中的微小一步,但 Sanderson 强调这实际上完成了“超过 50% 的工作”。求取代价函数对偏置 b^(L) 的灵敏度只需将末项替换为 ∂z^(L)/∂b^(L) = 1,其余两项保持不变:∂C₀/∂b^(L) = 1 · σ'(z^(L)) · 2(a^(L) - y)。更关键的是,该链条可直接推导出代价函数对前驱激活值的敏感度 ∂C₀/∂a^(L-1) = w^(L) · σ'(z^(L)) · 2(a^(L) - y)。尽管网络无法直接改写激活值,但这一激活敏感度充当了反向递归的核心接口,使得相同的链式法则能够无缝回退到前一层权重 w^(L-1) 与偏置 b^(L-1) 的计算中。 多神经元网络中的矩阵索引与路径聚合 (6:42) 将架构扩展至包含多个神经元的通用网络时,计算形式本质上并未改变,仅需引入更多下标进行追踪。采用 w_jk^(L) 表示上一层第 k 个神经元到当前层第 j 个神经元的连接权重,这种“目标神经元下标在前、源神经元在后”的约定是为了与标准矩阵乘法规则保持一致。在多神经元场景中,单个样本的代价函数扩展为所有输出单元均方误差之和 C₀ = Σ_j (a_j^(L) - y_j)²,针对特定权重 w_jk^(L) 的偏导结构保持不变。核心差异在于前一层神经元 a_k^(L-1) 同时分叉连接至当前层的多个神经元,其对最终代价的影响通过多条路径同时发生,因此其总敏感度必须对所有输出通道求和:∂C₀/∂a_k^(L-1) = Σ_j w_jk^(L) · σ'(z_j^{(L)}) · (∂C₀/∂a_j^(L))。 通过逐层求和与链式法则的交替迭代,网络得以构建出覆盖所有参数的完整梯度向量,为梯度下降算法提供了精确的数值更新方向。Sanderson 总结指出,理解这种沿分叉路径的反向敏感度聚合便触碰到了反向传播算法的核心,尽管密集的嵌套符号需要时间消化,但其本质是简洁统一的数学递推。

Source quotes

[6:42] Grant Sanderson: honestly, not that much changes when we give the layers multiple neurons, really it's just a few more indices to keep track of.

Original transcript

[0:00] [Submit subtitle corrections at criblate.com] [0:04] The hard assumption here is that you've watched part 3, [0:06] giving an intuitive walkthrough of the backpropagation algorithm. [0:11] Here we get a little more formal and dive into the relevant calculus. [0:14] It's normal for this to be at least a little confusing, [0:17] so the mantra to regularly pause and ponder certainly applies as much here [0:20] as anywhere else. [0:21] Our main goal is to show how people in machine learning commonly think about [0:25] the chain rule from calculus in the context of networks, [0:28] which has a different feel from how most introductory calculus courses [0:32] approach the subject. [0:34] For those of you uncomfortable with the relevant calculus, [0:36] I do have a whole series on the topic. [0:39] Let's start off with an extremely simple network, [0:43] one where each layer has a single neuron in it. [0:46] This network is determined by three weights and three biases, [0:49] and our goal is to understand how sensitive the cost function is to these variables. [0:55] That way, we know which adjustments to those terms will [0:58] cause the most efficient decrease to the cost function. [1:01] And we're just going to focus on the connection between the last two neurons. [1:05] Let's label the activation of that last neuron with a superscript L, [1:10] indicating which layer it's in, so the activation of the previous neuron is a^(L-1). [1:16] These are not exponents, they're just a way of indexing what we're talking about, [1:20] since I want to save subscripts for different indices later on. [1:23] Let's say that the value we want this last activation to be for [1:27] a given training example is y, for example, y might be 0 or 1. [1:32] So the cost of this network for a single training example is a^(L - y) squared. [1:40] We'll denote the cost of that one training example as C0. [1:45] As a reminder, this last activation is determined by a weight, [1:49] which I'm going to call w(L), times the previous neuron's activation plus some bias, [1:55] which I'll call b(L). [1:57] And then you pump that through some special nonlinear function like the sigmoid or ReLU. [2:01] It's actually going to make things easier for us if we give a special name to [2:05] this weighted sum, like z, with the same superscript as the relevant activations. [2:10] This is a lot of terms, and a way you might conceptualize it is that the weight, [2:15] previous action and the bias all together are used to compute z, [2:19] which in turn lets us compute a, which finally, along with a constant y, [2:23] lets us compute the cost. [2:27] And of course a(L-1) is influenced by its own weight and bias and such... [2:32] but we're not going to focus on that right now. [2:35] All of these are just numbers, right? [2:38] And it can be nice to think of each one as having its own little number line. [2:41] Our first goal is to understand how sensitive the [2:45] cost function is to small changes in our weight w(L). [2:49] Or phrased differently, what is the derivative of C with respect to w(L)? [2:55] When you see this del w term, think of it as meaning some tiny nudge to W, [3:00] like a change by 0.01, and think of this del C term as meaning [3:04] whatever the resulting nudge to the cost is. [3:08] What we want is their ratio. [3:11] Conceptually, this tiny nudge to w(L) causes some nudge to z(L), [3:15] which in turn causes some nudge to a(L), which directly influences the cost. [3:23] So we break things up by first looking at the ratio of a tiny change to z(L) to [3:28] this tiny change w(L), that is, the derivative of z(L) with respect to w(L). [3:33] Likewise, you then consider the ratio of the change to a(L) to [3:36] the tiny change in z(L) that caused it, as well as the ratio [3:40] between the final nudge to C and this intermediate nudge to a(L). [3:45] This right here is the chain rule, where multiplying together these [3:50] three ratios gives us the sensitivity of C to small changes in w(L). [3:56] So on screen right now, there's a lot of symbols, [3:59] and take a moment to make sure it's clear what they all are, [4:02] because now we're going to compute the relevant derivatives. [4:07] The derivative of C with respect to a(L) works out to be 2(a(L)-y). [4:13] Notice this means its size is proportional to the difference between the network's [4:18] output and the thing we want it to be, so if that output was very different, [4:22] even slight changes stand to have a big impact on the final cost function. [4:27] The derivative of a(L) with respect to z(L) is just the derivative [4:31] of our sigmoid function, or whatever nonlinearity you choose to use. [4:37] And the derivative of z(L) with respect to w(L)... In this case comes out to be a(L-1). [4:45] Now I don't know about you, but I think it's easy to get stuck head down in the [4:49] formulas without taking a moment to sit back and remind yourself of what they all mean. [4:53] In the case of this last derivative, the amount that the small nudge to the [4:58] weight influenced the last layer depends on how strong the previous neuron is. [5:03] Remember, this is where the neurons-that-fire-together-wire-together idea comes in. [5:09] And all of this is the derivative with respect to w(L) [5:12] only of the cost for a specific single training example. [5:16] Since the full cost function involves averaging together all [5:19] those costs across many different training examples, [5:22] its derivative requires averaging this expression over all training examples. [5:28] And of course, that is just one component of the gradient vector, [5:31] which itself is built up from the partial derivatives of the [5:35] cost function with respect to all those weights and biases. [5:40] But even though that's just one of the many partial derivatives we need, [5:43] it's more than 50% of the work. [5:46] The sensitivity to the bias, for example, is almost identical. [5:50] We just need to change out this del z del w term for a del z del b. [5:58] And if you look at the relevant formula, that derivative comes out to be 1. [6:06] Also, and this is where the idea of propagating backwards comes in, [6:10] you can see how sensitive this cost function is to the activation of the previous layer. [6:15] Namely, this initial derivative in the chain rule expression, [6:19] the sensitivity of z to the previous activation, comes out to be the weight w(L). [6:26] And again, even though we're not going to be able to directly influence [6:30] that previous layer activation, it's helpful to keep track of, [6:33] because now we can just keep iterating this same chain rule idea backwards [6:37] to see how sensitive the cost function is to previous weights and previous biases. [6:43] And you might think this is an overly simple example, since all layers have one neuron, [6:47] and things are going to get exponentially more complicated for a real network. [6:51] But honestly, not that much changes when we give the layers multiple neurons, [6:55] really it's just a few more indices to keep track of. [6:59] Rather than the activation of a given layer simply being a(L), [7:02] it's also going to have a subscript indicating which neuron of that layer it is. [7:07] Let's use the letter k to index the layer L-1, and j to index the layer L. [7:15] For the cost, again we look at what the desired output is, [7:18] but this time we add up the squares of the differences between these last layer [7:23] activations and the desired output. [7:26] That is, you take a sum over a(L)j minus yj squared. [7:33] Since there's a lot more weights, each one has to have a couple more [7:37] indices to keep track of where it is, so let's call the weight of [7:41] the edge connecting this kth neuron to the jth neuron, w(L)_jk. [7:45] Those indices might feel a little backwards at first, [7:48] but it lines up with how you'd index the weight matrix I talked about in [7:52] the part 1 video. [7:53] Just as before, it's still nice to give a name to the relevant weighted sum, [7:57] like z, so that the activation of the last layer is just your special function, [8:02] like the sigmoid, applied to z. [8:04] You can see what I mean, where all of these are essentially the same equations we had [8:08] before in the one-neuron-per-layer case, it's just that it looks a little more [8:13] complicated. [8:15] And indeed, the chain-ruled derivative expression describing how [8:19] sensitive the cost is to a specific weight looks essentially the same. [8:23] I'll leave it to you to pause and think about each of those terms if you want. [8:28] What does change here, though, is the derivative of the cost [8:32] with respect to one of the activations in the layer L-1. [8:37] In this case, the difference is that the neuron influences [8:40] the cost function through multiple different paths. [8:44] That is, on the one hand, it influences a(L)0, which plays a role in the cost function, [8:50] but it also has an influence on a(L)1, which also plays a role in the cost function, [8:55] and you have to add those up. [8:59] And that, well, that's pretty much it. [9:03] Once you know how sensitive the cost function is to the [9:06] activations in this second-to-last layer, you can just repeat [9:09] the process for all the weights and biases feeding into that layer. [9:13] So pat yourself on the back! [9:15] If all of this makes sense, you have now looked deep into the heart of backpropagation, [9:20] the workhorse behind how neural networks learn. [9:23] These chain rule expressions give you the derivatives that determine each component in [9:28] the gradient that helps minimize the cost of the network by repeatedly stepping downhill. [9:34] If you sit back and think about all that, this is a lot of layers of complexity to [9:38] wrap your mind around, so don't worry if it takes time for your mind to digest it all.