Simple Algorithm
Machine Learning · Descent · 24 min

Backpropagation

The chain rule, organized: every gradient in one backward sweep.

A network with a billion weights needs a billion partial derivatives at every training step. Computing them one at a time would take a billion forward passes; backpropagation gets all of them for the price of about two more. This lesson derives the algorithm on computational graphs and in matrix form, counts its cost in time and memory, shows how to test an implementation against finite differences, and explains why gradients in deep networks tend to vanish or explode.

What you’ll learn

  • Compute gradients on a computational graph with the reverse sweep, including the rule that contributions arriving along different paths add up.
  • Derive the backpropagation equations for an MLP, δ(l)=(W(l+1)⊤δ(l+1))⊙φ′(z(l))\boldsymbol\delta^{(l)}=\big(W^{(l+1)\top}\boldsymbol\delta^{(l+1)}\big)\odot\varphi'(\mathbf z^{(l)}) and ∂ℓ/∂W(l)=δ(l)h(l−1)⊤\partial\ell/\partial W^{(l)}=\boldsymbol\delta^{(l)}\mathbf h^{(l-1)\top}, and implement them for a mini-batch.
  • Count the time and memory of a backward pass, and explain why it costs about twice the forward pass.
  • Check gradients with central differences, choosing the step size and tolerance soundly, and trace vanishing and exploding gradients to long products of Jacobians.

Computational graphs and the chain rule

Any computation of a loss can be written as a computational graph: a directed acyclic graph whose nodes are intermediate values v1,…,vKv_1,\dots,v_K, each computed from its parents by an elementary operation, ending with the loss L=vKL=v_K. Define each node's adjoint vˉk=∂L/∂vk\bar v_k=\partial L/\partial v_k. A node influences LL only through its children, so the multivariable chain rule gives

vˉk=∑c ∈ children(k)vˉc ∂vc∂vk,vˉK=1.\bar v_k=\sum_{c\,\in\,\text{children}(k)}\bar v_c\,\frac{\partial v_c}{\partial v_k},\qquad\bar v_K=1.

Visit the nodes in reverse topological order: when a node is reached, all its children are done, so its adjoint is complete. One forward sweep computes and stores the values; one backward sweep computes every adjoint. This is reverse-mode automatic differentiation, and backpropagation is its application to neural networks.

NodeForward valueLocal derivativesAdjoint (backward sweep, bottom row first)
xx22inputxˉ=uˉ⋅1+zˉ⋅y=16+48=64\bar x=\bar u\cdot1+\bar z\cdot y=16+48=64
yy33inputyˉ=zˉ⋅x=32\bar y=\bar z\cdot x=32
z=xyz=xy66∂z/∂x=y=3\partial z/\partial x=y=3,  ∂z/∂y=x=2\ \partial z/\partial y=x=2zˉ=uˉ⋅1=16\bar z=\bar u\cdot1=16
u=z+xu=z+x88∂u/∂z=1\partial u/\partial z=1,  ∂u/∂x=1\ \partial u/\partial x=1uˉ=Lˉ⋅2u=16\bar u=\bar L\cdot2u=16
L=u2L=u^26464∂L/∂u=2u=16\partial L/\partial u=2u=16Lˉ=1\bar L=1
L=(xy+x)2L=(xy+x)^2 at x=2x=2, y=3y=3. The input xx feeds two nodes, so its adjoint adds the two contributions. Check: ∂L/∂x=2(xy+x)(y+1)=2⋅8⋅4=64\partial L/\partial x=2(xy+x)(y+1)=2\cdot8\cdot4=64 and ∂L/∂y=2(xy+x) x=32\partial L/\partial y=2(xy+x)\,x=32.
Check your understanding

A weight ww is used in two places in a network (shared weights, as in a convolution applied at two positions). The backward sweep computes g1=∂L/∂(first use)g_1=\partial L/\partial(\text{first use}) and g2=∂L/∂(second use)g_2=\partial L/\partial(\text{second use}). What is ∂L/∂w\partial L/\partial w?

  1. g1g2g_1g_2
  2. max⁡(g1,g2)\max(g_1,g_2)
  3. (g1+g2)/2(g_1+g_2)/2
  4. g1+g2g_1+g_2
Show the answer

D. g1+g2g_1+g_2

ww is a node with two children, and the chain rule sums over children: wˉ=g1+g2\bar w=g_1+g_2. Convolutional and recurrent networks rely on this: a shared filter or recurrent matrix accumulates gradient from every position or time step where it is used.

The layer-by-layer equations

Use the notation of From Perceptrons to Deep Networks: z(l)=W(l)h(l−1)+b(l)\mathbf z^{(l)}=W^{(l)}\mathbf h^{(l-1)}+\mathbf b^{(l)}, h(l)=φ(z(l))\mathbf h^{(l)}=\varphi(\mathbf z^{(l)}) for l=1,…,Ll=1,\dots,L, logits z(L+1)\mathbf z^{(L+1)}, and a per-example loss ℓ(z(L+1),y)\ell(\mathbf z^{(L+1)},\mathbf y). The quantity that flows backward is the error signal of each layer's pre-activations, δ(l)=∂ℓ/∂z(l)\boldsymbol\delta^{(l)}=\partial\ell/\partial\mathbf z^{(l)}, a vector the size of the layer.

DerivationError signals and weight gradients, derived
  1. δ(L+1)=∂ℓ∂z(L+1)=p−y\boldsymbol\delta^{(L+1)}=\frac{\partial\ell}{\partial\mathbf z^{(L+1)}}=\mathbf p-\mathbf y

    Output layer. For softmax with cross-entropy (or sigmoid with log loss) the gradient with respect to the logits is prediction minus target; for an identity output with the squared loss 12∥z(L+1)−y∥2\tfrac12\norm{\mathbf z^{(L+1)}-\mathbf y}^2 it is z(L+1)−y\mathbf z^{(L+1)}-\mathbf y (without the 12\tfrac12, twice that):

  2. δj(l)=∑kδk(l+1) Wkj(l+1) φ′(zj(l))⟺δ(l)=(W(l+1)⊤δ(l+1))⊙φ′(z(l))\delta^{(l)}_j=\sum_k\delta^{(l+1)}_k\,W^{(l+1)}_{kj}\,\varphi'\big(z^{(l)}_j\big)\quad\Longleftrightarrow\quad\boldsymbol\delta^{(l)}=\big(W^{(l+1)\top}\boldsymbol\delta^{(l+1)}\big)\odot\varphi'\big(\mathbf z^{(l)}\big)

    Recursion. zj(l)z^{(l)}_j affects the loss only through hj(l)=φ(zj(l))h^{(l)}_j=\varphi(z^{(l)}_j), which feeds every zk(l+1)=∑jWkj(l+1)hj(l)+bk(l+1)z^{(l+1)}_k=\sum_jW^{(l+1)}_{kj}h^{(l)}_j+b^{(l+1)}_k. Sum over the children kk:

  3. ∂ℓ∂Wjk(l)=δj(l) hk(l−1)⟺∂ℓ∂W(l)=δ(l)h(l−1)⊤,∂ℓ∂b(l)=δ(l)\frac{\partial\ell}{\partial W^{(l)}_{jk}}=\delta^{(l)}_j\,h^{(l-1)}_k\quad\Longleftrightarrow\quad\frac{\partial\ell}{\partial W^{(l)}}=\boldsymbol\delta^{(l)}\mathbf h^{(l-1)\top},\qquad\frac{\partial\ell}{\partial\mathbf b^{(l)}}=\boldsymbol\delta^{(l)}

    Parameters. Wjk(l)W^{(l)}_{jk} appears only in zj(l)z^{(l)}_j, with coefficient hk(l−1)h^{(l-1)}_k, so each weight's gradient is the error at its output times the activation at its input: an outer product.

  4. Δ(l)=(Δ(l+1)W(l+1))⊙φ′(Z(l)),∇W(l)L=1B Δ(l)⊤H(l−1),∇b(l)L=1B Δ(l)⊤1\Delta^{(l)}=\big(\Delta^{(l+1)}W^{(l+1)}\big)\odot\varphi'\big(Z^{(l)}\big),\qquad\nabla_{W^{(l)}}\mathcal L=\frac1B\,\Delta^{(l)\top}H^{(l-1)},\qquad\nabla_{\mathbf b^{(l)}}\mathcal L=\frac1B\,\Delta^{(l)\top}\mathbf 1

    Mini-batch. Stack the BB examples' error signals as rows of Δ(l)∈RB×nl\Delta^{(l)}\in\R^{B\times n_l} and activations as rows of H(l)H^{(l)}. The recursion becomes a matrix product and the gradient of the average loss a sum of outer products:

python
import numpy as np

def forward_backward(params, X, Y):
    """X: (B, d) inputs, Y: (B, k) one-hot targets, params: [(W, b), ...]."""
    Hs, Zs = [X], []
    for W, b in params[:-1]:                 # forward pass: cache Z and H
        Zs.append(Hs[-1] @ W.T + b)
        Hs.append(np.maximum(0.0, Zs[-1]))   # ReLU
    W, b = params[-1]
    logits = Hs[-1] @ W.T + b
    logits -= logits.max(axis=1, keepdims=True)
    logP = logits - np.log(np.exp(logits).sum(axis=1, keepdims=True))
    B = X.shape[0]
    loss = -np.sum(Y * logP) / B
    D = (np.exp(logP) - Y) / B               # output deltas: (p - y) / B
    grads = []
    for l in range(len(params) - 1, -1, -1):  # backward pass
        W, b = params[l]
        grads.append((D.T @ Hs[l], D.sum(axis=0)))
        if l > 0:
            D = (D @ W) * (Zs[l - 1] > 0)    # times ReLU'(z) of the layer below
    return loss, grads[::-1]

Forward and backward passes for the ReLU network of From Perceptrons to Deep Networks, with a numerically stable log-softmax. Each backward iteration is the matrix equations above: one product for the weight gradient, one to pass the error signal down.

What it costs

Time. For a dense layer and a mini-batch of BB examples, the forward product H(l−1)W(l)⊤H^{(l-1)}W^{(l)\top} costs 2Bnl−1nl2Bn_{l-1}n_l floating-point operations: a multiply and an add per weight per example. The backward pass needs two products of the same size: Δ(l)W(l)\Delta^{(l)}W^{(l)} to send the error signal down, and Δ(l)⊤H(l−1)\Delta^{(l)\top}H^{(l-1)} for the weight gradient. Activations and their derivatives add only O(Bnl)\order{Bn_l}. So a backward pass takes about two forward passes' worth of arithmetic, and a whole gradient about three, however many parameters there are. This is the cheap-gradient principle, and it is not specific to networks: Baur & Strassen (1983) proved that all partial derivatives of a rational function cost at most a small constant times evaluating the function (Autodiff in Depth).

Memory. The backward pass needs every layer's cached Z(l)Z^{(l)} or H(l)H^{(l)}: about B∑lnlB\sum_ln_l numbers, growing with depth and with batch size, and for large models often more than the weights themselves. Inference keeps only the current layer. Gradient checkpointing stores a few layers and recomputes the others during the backward pass, trading computation for memory.

Predict before you look

A dense layer maps 1,000 units to 1,000 units for a mini-batch of 100 examples, and its forward product costs 2×1082\times10^8 flops. How many flops does its backward pass cost, in units of 10810^8?

Show the answer

4 × 10⁸ flops

Two products, each 2⋅100⋅1000⋅1000=2×1082\cdot100\cdot1000\cdot1000=2\times10^8 flops: ΔW\Delta W for the error signal and Δ⊤H\Delta^\top H for the weight gradient, 4×1084\times10^8 in total. Estimating the same gradient by finite differences would take one forward pass per parameter, over 10610^6 passes for this layer's weights alone.

Checking gradients

Backpropagation code fails silently: a wrong gradient often still lowers the loss, just badly. The standard test compares it with a finite difference. Use the central difference, along a coordinate or along a random unit direction v\mathbf v (one check then covers every parameter at once):

DerivationChoosing the step size
  1. L(θ+hv)−L(θ−hv)2h=∇L(θ)⊤v+h26 ∇3L(θ)[v,v,v]+O(h4)\frac{L(\boldsymbol\theta+h\mathbf v)-L(\boldsymbol\theta-h\mathbf v)}{2h}=\nabla L(\boldsymbol\theta)^\top\mathbf v+\frac{h^2}6\,\nabla^3L(\boldsymbol\theta)[\mathbf v,\mathbf v,\mathbf v]+\order{h^4}

    Expand both evaluations around θ\boldsymbol\theta. The even-order terms cancel, so the truncation error is O(h2)\order{h^2}; the one-sided difference (L(θ+hv)−L(θ))/h(L(\boldsymbol\theta+h\mathbf v)-L(\boldsymbol\theta))/h keeps the curvature term and is only O(h)\order h.

  2. error(h) ≈ C h2+ε ∣L∣h⟹h⋆∝ε1/3,error(h⋆)∝ε2/3\text{error}(h)\ \approx\ C\,h^2+\frac{\varepsilon\,\abs L}h\qquad\Longrightarrow\qquad h^\star\propto\varepsilon^{1/3},\quad\text{error}(h^\star)\propto\varepsilon^{2/3}

    Each evaluation of LL carries a rounding error of about ε∣L∣\varepsilon\abs L, where ε\varepsilon is the machine epsilon, and the difference quotient divides it by 2h2h. The total error is smallest where the two terms balance:

  3. ε64≈2.2×10−16: ε1/3≈6×10−6, ε2/3≈4×10−11;ε32≈1.2×10−7: ε2/3≈2×10−5\varepsilon_{64}\approx2.2\times10^{-16}:\ \varepsilon^{1/3}\approx6\times10^{-6},\ \varepsilon^{2/3}\approx4\times10^{-11};\qquad\varepsilon_{32}\approx1.2\times10^{-7}:\ \varepsilon^{2/3}\approx2\times10^{-5}

    In double precision this suggests hh around 10−510^{-5} to 10−610^{-6} and errors of order 10−1010^{-10} (times problem-dependent constants); in single precision the best achievable error is only about 10−510^{-5}, too coarse to catch subtle bugs. Run gradient checks in float64, and do not shrink hh below the optimum: the error grows again.

python
import numpy as np

def grad_check(loss_fn, grad_fn, theta, h=1e-6, seed=0):
    """Relative error between the analytic and the numerical directional derivative.
    theta is a flat float64 vector; grad_fn(theta) returns a flat gradient."""
    v = np.random.default_rng(seed).normal(size=theta.shape)
    v /= np.linalg.norm(v)                       # random unit direction
    numeric = (loss_fn(theta + h * v) - loss_fn(theta - h * v)) / (2 * h)
    analytic = grad_fn(theta) @ v
    return abs(numeric - analytic) / max(abs(numeric), abs(analytic), 1e-12)

In one run on a small ReLU network in double precision, this check gave relative errors of about 10−510^{-5} at h=10−2h=10^{-2}, 10−1010^{-10} at h=10−6h=10^{-6}, and 10−510^{-5} again at h=10−10h=10^{-10}: the U shape the derivation predicts. (At large hh the step can also cross ReLU kinks, so the error there varies a lot from run to run.) A correct implementation typically scores far below 10−610^{-6}; a bug usually shows up as an error of order 10−210^{-2} or worse.

Common false alarms and real traps:

  • Kinks. ReLU, max-pooling and absolute values are not differentiable everywhere. If a perturbation moves some pre-activation across 0, the difference quotient mixes two linear pieces and the check fails for that point only. Check at points away from kinks, or temporarily swap in a smooth activation.
  • Randomness. Dropout masks, data augmentation and random sampling must be frozen, or the two evaluations compute different functions.
  • Missing terms. Weight decay and auxiliary losses must be in both the analytic and the numerical loss. Normalization layers must see the same mini-batch in both evaluations.
Check your understanding

A gradient check on a ReLU network gives relative errors near 10−910^{-9} for most coordinates you test, but 0.40.4 for one particular first-layer weight. What is the most likely explanation?

  1. The backward pass is wrong for every weight
  2. hh is too small for double precision
  3. The learning rate is too large
  4. For some training example, that weight's unit has a pre-activation within about hh of 0, so the finite difference straddles the ReLU's kink
Show the answer

D. For some training example, that weight's unit has a pre-activation within about hh of 0, so the finite difference straddles the ReLU's kink

A single bad coordinate among many good ones points to a local non-smoothness, not a systematic bug. If a perturbation of size hh flips a unit between on and off, the numerical derivative averages two different slopes. Re-check at a slightly different θ\boldsymbol\theta or input, or confirm that some pre-activation is near zero.

Vanishing and exploding gradients

Unroll the recursion. With D(k)=diag⁡(φ′(z(k)))D^{(k)}=\operatorname{diag}\big(\varphi'(\mathbf z^{(k)})\big), the error signal that reaches layer ll is the output error multiplied by one transposed Jacobian factor per layer above it:

δ(l)=D(l)W(l+1)⊤D(l+1)W(l+2)⊤⋯D(L)W(L+1)⊤ δ(L+1),∥δ(l)∥ ≤ ∏k=l+1L+1∥W(k)∥ ∏k=lLmax⁡j∣φ′(zj(k))∣ ∥δ(L+1)∥\boldsymbol\delta^{(l)}=D^{(l)}W^{(l+1)\top}D^{(l+1)}W^{(l+2)\top}\cdots D^{(L)}W^{(L+1)\top}\,\boldsymbol\delta^{(L+1)},\qquad\norm{\boldsymbol\delta^{(l)}}\ \le\ \prod_{k=l+1}^{L+1}\norm{W^{(k)}}\ \prod_{k=l}^{L}\max_j\abs{\varphi'(z^{(k)}_j)}\ \norm{\boldsymbol\delta^{(L+1)}}
∥W∥\norm{W} is the spectral norm. A product of many factors smaller than 1 shrinks geometrically: vanishing gradients. Factors larger than 1 compound just as fast: exploding gradients.

The sigmoid's slope never exceeds 14\tfrac14, and it is far smaller wherever the unit saturates, so in a deep sigmoid network with moderately sized weights the early layers receive tiny gradients and learn slowly, while the last layers do all the work. Explosions come from large weights, and they are most severe in recurrent networks, where the same matrix is applied at every time step: the gradient from TT steps back behaves roughly like the TT-th power of a per-step factor. Exploded gradients produce huge steps, loss spikes and overflow to NaN.

Predict before you look

In a 10-layer sigmoid network whose weight matrices all have spectral norm 1, the bound above multiplies the output error by ∏max⁡j∣σ′∣\prod\max_j\abs{\sigma'} over the 10 layers. What is log⁡10\log_{10} of the largest value this factor can take?

Show the answer

-6

Each layer contributes at most 14\tfrac14, so the bound is 4−10≈9.5×10−74^{-10}\approx9.5\times10^{-7}, about 10−610^{-6}: even in the best case, the first layer's gradient is a millionth of the size it would have without the activation slopes. Saturated units make it smaller still. ReLU's slope of exactly 1 on active units is a major reason it replaced the sigmoid in hidden layers.

RemedyWhat it does to the product of JacobiansWhere
ReLU-family activationsslope exactly 1 on active units: no saturationFrom Perceptrons to Deep Networks
Variance-preserving initialization (Glorot, He, orthogonal)keeps each layer's factor near 1 at the start of trainingInitialization & Signal Propagation
Normalization layersre-standardize pre-activations, keeping units out of saturationNormalization Layers
Residual connections h+F(h)\mathbf h+F(\mathbf h)each Jacobian becomes I+∂F/∂hI+\partial F/\partial\mathbf h, so an identity path carries the gradientInitialization & Signal Propagation
Gradient clippingrescales g←g min⁡(1,τ/∥g∥)\mathbf g\leftarrow\mathbf g\,\min(1,\tau/\norm{\mathbf g}), capping exploded stepsPascanu, Mikolov & Bengio (2013)
Gated recurrent cells (LSTM, GRU)additive memory updates with learned gates instead of repeated matrix productsInitialization & Signal Propagation

Key takeaways

  • Reverse mode on a computational graph computes vˉk=∑cvˉc ∂vc/∂vk\bar v_k=\sum_c\bar v_c\,\partial v_c/\partial v_k in reverse topological order; contributions along different paths add, which is how shared weights accumulate gradient.
  • For an MLP: δ(L+1)=p−y\boldsymbol\delta^{(L+1)}=\mathbf p-\mathbf y, δ(l)=(W(l+1)⊤δ(l+1))⊙φ′(z(l))\boldsymbol\delta^{(l)}=(W^{(l+1)\top}\boldsymbol\delta^{(l+1)})\odot\varphi'(\mathbf z^{(l)}), ∂ℓ/∂W(l)=δ(l)h(l−1)⊤\partial\ell/\partial W^{(l)}=\boldsymbol\delta^{(l)}\mathbf h^{(l-1)\top}; over a mini-batch these are matrix products.
  • A backward pass costs about two forward passes, whatever the number of parameters, but it needs every cached activation: memory grows with depth times batch size.
  • Check gradients with central differences in float64 with hh near 10−610^{-6} along random directions; expect relative errors far below 10−610^{-6}, and watch for kinks, frozen randomness and missing loss terms.
  • The error signal is a product of Jacobians, so it vanishes or explodes geometrically with depth or time; activations, initialization, normalization, residual paths, clipping and gating keep the product near 1.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

Layer ll has δ(l)∈R64\boldsymbol\delta^{(l)}\in\R^{64}, and its input is h(l−1)∈R128\mathbf h^{(l-1)}\in\R^{128}. What is ∂ℓ/∂W(l)\partial\ell/\partial W^{(l)}?

  1. A 128×64128\times64 matrix, h(l−1)δ(l)⊤\mathbf h^{(l-1)}\boldsymbol\delta^{(l)\top}
  2. A 64×12864\times128 matrix, δ(l)h(l−1)⊤\boldsymbol\delta^{(l)}\mathbf h^{(l-1)\top}
  3. A vector of length 64, equal to δ(l)\boldsymbol\delta^{(l)}
  4. The scalar δ(l)⊤W(l)h(l−1)\boldsymbol\delta^{(l)\top}W^{(l)}\mathbf h^{(l-1)}
Show the answer

B. A 64×12864\times128 matrix, δ(l)h(l−1)⊤\boldsymbol\delta^{(l)}\mathbf h^{(l-1)\top}

W(l)W^{(l)} maps 128 inputs to 64 units, so it is 64×12864\times128, and so is its gradient. Entry (j,k)(j,k) is δj(l)hk(l−1)\delta^{(l)}_jh^{(l-1)}_k: the error at the weight's output times the activation at its input, an outer product.

Question 2

Why does the backward pass through a dense layer cost about twice its forward pass?

  1. It needs two matrix products of the same size as the forward one: one to pass the error signal down, one for the weight gradient
  2. It runs the forward pass a second time
  3. Derivatives of activation functions are expensive
  4. It must invert each weight matrix
Show the answer

A. It needs two matrix products of the same size as the forward one: one to pass the error signal down, one for the weight gradient

Δ(l)W(l)\Delta^{(l)}W^{(l)} and Δ(l)⊤H(l−1)\Delta^{(l)\top}H^{(l-1)} each cost 2Bnl−1nl2Bn_{l-1}n_l flops, like the forward product. The elementwise φ′\varphi' is negligible. No inverse is ever needed: backpropagation only multiplies by transposes.

Question 3

You double both the batch size and the depth of a network (same width). Roughly how does the memory needed for the cached activations change?

  1. It stays the same
  2. It doubles
  3. It grows about fourfold
  4. It grows exponentially
Show the answer

C. It grows about fourfold

Cached activations take about B∑lnlB\sum_ln_l numbers: twice the batch times twice as many layers is four times the memory. This is why activation memory, not weights, often limits training, and why checkpointing exists.

Question 4

In a central-difference gradient check you halve hh from 10−310^{-3} to 5×10−45\times10^{-4}, still far above the rounding-error regime. How does the truncation error change?

  1. It halves
  2. It is unchanged
  3. It doubles
  4. It falls to about a quarter
Show the answer

D. It falls to about a quarter

The central difference's leading error term is h26∇3L[v,v,v]\tfrac{h^2}6\nabla^3L[\mathbf v,\mathbf v,\mathbf v], so halving hh divides it by 4. A one-sided difference has an O(h)\order h error and would only halve.

Question 5

In a recurrent network the error signal is multiplied at each time step by a Jacobian of norm about 0.90.9. Roughly how much of the gradient from an input 50 steps back survives?

  1. About 0.9×50=450.9\times50=45 times the original
  2. About 0.5%0.5\%
  3. All of it, because the weights are shared across time
  4. About 10%10\%
Show the answer

B. About 0.5%0.5\%

0.950≈0.0050.9^{50}\approx0.005: the contribution of distant inputs vanishes geometrically, so gradient descent barely learns long-range dependencies. With a norm of 1.11.1 the factor would be 1.150≈1171.1^{50}\approx117: an explosion. Gated cells and clipping address the two cases.

Go deeper

Further reading

  • D. E. Rumelhart, G. E. Hinton & R. J. Williams, "Learning representations by back-propagating errors," Nature 323, 533–536 (1986).
  • I. Goodfellow, Y. Bengio & A. Courville, Deep Learning (MIT Press, 2016), section 6.5.
  • A. G. Baydin, B. A. Pearlmutter, A. A. Radul & J. M. Siskind, "Automatic differentiation in machine learning: a survey," Journal of Machine Learning Research 18(153), 1–43 (2018).
  • Y. Bengio, P. Simard & P. Frasconi, "Learning long-term dependencies with gradient descent is difficult," IEEE Transactions on Neural Networks 5(2), 157–166 (1994).