liveBook · Manning

Vanishing gradient problem

As explained in Deep Learning with R, Third Edition

A vanishing gradient is a training condition in which gradients become extremely small as they propagate through a deep network, slowing or preventing parameter updates in earlier layers.

A deeper network can reuse features and build more abstract ones, but adding layers eventually makes training difficult. During backpropagation, the error signal must travel backward through every layer. If it becomes too weak along the way, earlier layers cannot be adjusted effectively: this is the vanishing gradient problem. section 9.1 section 9.2

A message passed down a chain

Imagine adjusting the first function in y = f4(f3(f2(f1(x)))) using an error measured at the output. The error information must pass through f4, f3, and f2 to reach f1. Like a message repeatedly relayed through a noisy channel, it can lose useful information. A residual connection gives it a shortcut: save a block’s input, process the block, then add the saved input to its output. section 9.2

Listing 9.2 Target block that changes the number of output filters
inputs <- keras_input(shape = c(32, 32, 3))
x <- inputs |> layer_conv_2d(32, 3, activation = "relu")
residual <- x  #1
x <- x |> layer_conv_2d(64, 3, activation = "relu", padding = "same")  #2
residual <- residual |> layer_conv_2d(64, 1) #3
x <- layer_add(c(x, residual))  #4

This R/Keras example adds a convolutional block’s input back to its output. Because the block changes the number of filters, a 1 × 1 convolution first projects the saved input to the required shape; only then can layer_add combine the two paths. section 9.2

The problem also appears across timesteps. A SimpleRNN may theoretically retain an old input, yet struggle to learn dependencies over many timesteps. LSTM and GRU were designed to address this difficulty; an LSTM carries information forward so older signals need not gradually disappear. section 13.3.2

How Deep Learning with R, Third Edition covers it

How deep it goes
Explains the failure through a backpropagation analogy and shows residual shape matching, without deriving gradient equations.
Examples
Uses a chain of functions, R/Keras convolutional residual blocks, and recurrent layers processing sequences.
What it assumes
Introduces the backpropagation failure with a function-chain analogy before using R/Keras layer operations.
What you can do after
Apply it via R/Keras residual connections, including projections when a block changes feature-map shape.
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 R, Third Edition. The section links point to the parts of the book it draws on.