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













