Lably
Skip to content

Residual neural network

Type of artificial neural network

  • 7 min read
  • 4 chapters

Related on Lably

Through Deep learning, Computer vision and Feedforward neural network

As a point of terminology, "residual connection" refers to the specific architectural motif of x↦f(x)+x, where f is an arbitrary neural network module. The motif had been used previously (see §History for details). However, the publication of ResNet made it widely popular for feedforward networks, appearing in neural networks that are seemingly unrelated to ResNet.

The residual connection stabilizes the training and convergence of deep neural networks with hundreds of layers, and is a common motif in deep neural networks, such as transformer models (e.g., BERT, and GPT models such as ChatGPT), the AlphaGo Zero system, the AlphaStar system, and the AlphaFold system.

Mathematics

Residual connection

In a multilayer neural network model, consider a (non-residual) subnetwork with a certain number of stacked layers (e.g., 2 or 3). Let H(x;α) denote the subnetwork, where x is the input and α is the set of parameters. Suppose H∗ is the desired optimal output of this subnetwork. Residual learning simply adds x directly to the output, such that the optimal learned output now becomes H∗−x, which is interpreted as a "residual" with respect to x.

The operation of "adding x" is implemented via a "skip connection" that performs an identity mapping to connect the input of the subnetwork with its output. This connection is referred to as a "residual connection" in later work.

Let F(x;α)=H(x;α)+x. The function F is often represented by matrix multiplication interlaced with activation functions and normalization operations (e.g., batch normalization or layer normalization). As a whole, one of these subnetworks is referred to as a "residual block". A deep residual network is constructed by simply stacking these blocks.

Long short-term memory (LSTM) has a memory mechanism that serves as a residual connection. In an LSTM without a forget gate, an input xt is processed by a function F and added to a memory cell ct, resulting in ct+1=ct+F(xt). An LSTM with a forget gate essentially functions as a highway network.

To stabilize the variance of the layers' inputs, it is recommended to replace the residual connections x+f(x) with x/L+f(x), where L is the total number of residual layers.

Projection connection

If the function F is of type F:Rn→Rm where n≠m, then F(x)+x is undefined. To handle this special case, a projection connection is used:

y=F(x)+P(x)

where P is typically a linear projection, defined by P(x)=Mx where M is a m×n matrix. The matrix is trained via backpropagation, as is any other parameter of the model.

Signal propagation

The introduction of identity mappings facilitates signal propagation in both forward and backward paths.

Forward propagation

If the output of the ℓ-th residual block is the input to the (ℓ+1)-th residual block (assuming no activation function between blocks), then the (ℓ+1)-th input is:

xℓ+1=F(xℓ)+xℓ

Applying this formulation recursively, e.g.:

xℓ+2=F(xℓ+1)+xℓ+1=F(xℓ+1)+F(xℓ)+xℓ

yields the general relationship:

xL=xℓ+∑i=ℓL−1F(xi)

where L is the index of a residual block and ℓ is the index of some earlier block. This formulation suggests that there is always a signal that is directly sent from a shallower block ℓ to a deeper block L.

Backward propagation

The residual learning formulation provides the added benefit of mitigating the vanishing gradient problem to some extent. However, it is crucial to acknowledge that the vanishing gradient issue is not the root cause of the degradation problem, which is tackled through the use of normalization. To observe the effect of residual blocks on backpropagation, consider the partial derivative of a loss function E with respect to some residual block input xℓ. Using the equation above from forward propagation for a later residual block L>ℓ:

∂E∂xℓ=∂E∂xL∂xL∂xℓ=∂E∂xL(1+∂∂xℓ∑i=ℓL−1F(xi))=∂E∂xL+∂E∂xL∂∂xℓ∑i=ℓL−1F(xi)

This formulation suggests that the gradient computation of a shallower layer, ∂E∂xℓ, always has a later term ∂E∂xL that is directly added. Even if the gradients of the F(xi) terms are small, the total gradient ∂E∂xℓ resists vanishing due to the added term ∂E∂xL.

Sign in to keep reading

3 more chapters are free with a Lably account.

More in Computing and communication