liveBook · Manning

Vanishing gradient problem

As explained in Deep Learning with Python, Third Edition

A training problem in deep networks where gradient signals become too small to effectively update earlier layers.

Deeper networks can reuse features and build more abstract ones, but adding layers eventually makes training difficult. The vanishing gradient problem occurs when the error signal needed to update early parts of a long chain no longer gets through effectively. section 9.1 section 9.2

A chain that cannot learn at its beginning

Imagine `y = f4(f3(f2(f1(x))))`. Training uses the loss at the output to adjust every function. To adjust `f1`, error information must pass backward through `f4`, `f3`, and `f2`. Extend that chain far enough, and successive steps can overwhelm the useful gradient signal. The early functions then become hard to train. section 9.2

Two practical responses address the problem in different architectures:

  • In a deep ConvNet, use a residual connection: save a block’s input and add it to the block’s output. This shortcut helps information and error gradients pass around blocks that might disrupt them. section 9.2
  • If the input and output shapes differ, project the saved input with a 1 × 1 `Conv2D` layer before adding it. Match downsampling with the projection’s stride when the block includes pooling. section 9.2
  • For long sequences, do not expect `SimpleRNN` to reliably learn dependencies across many timesteps. `LSTM` and `GRU` were designed to address this limitation; an LSTM carries information forward so older signals need not fade during processing. section 13.3.2 section 13.3.2
Listing 9.1 A residual connection in pseudocode
x = ...                                                           #1
residual = x                                                      #2
x = block(x)                                                      #3
x = add([x, residual])                                            #4

The pseudocode shows the essential shortcut: keep `residual = x`, process `x` through a block, then add the saved input back. section 9.2

Rule of thumb: when depth makes a feedforward network hard to train, consider a route around processing blocks; when a simple recurrent network loses distant context, consider a recurrent layer designed to carry information across timesteps. These are related responses to the same training difficulty, not identical implementations. section 9.2 section 13.3.2

How Deep Learning with Python, Third Edition covers it

How deep it goes
Explains the failure through a function-chain analogy and practical remedies, without deriving the gradient behavior mathematically.
Examples
Uses a four-function chain, Keras residual blocks with shape projections, and recurrent-layer examples involving long sequences.
What it assumes
Assumes familiarity with layers and model training while introducing gradient failure through a simple chain of functions.
What you can do after
Build it from scratch with Keras residual blocks, or evaluate/understand why LSTM and GRU are preferable to SimpleRNN for long dependencies.
How it connects
Connects backpropagation, feature hierarchies, residual connections, SimpleRNN, LSTM, and GRU.

Also explained in

Compare how 14 books explain vanishing gradient problem →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with Python, Third Edition. The section links point to the parts of the book it draws on.