Notes

Skip Connection (Residual)

A very deep network can be hard to train not because its layers are incapable, but because information and learning signals must survive a long journey through them. A skip connection gives both a shortcut: it lets a layer block refine what it receives instead of forcing it to rebuild everything from scratch.

How the shortcut works

In a residual block, the input x follows two paths. One passes through ordinary layers that compute a transformation F(x; θ); the other bypasses them. Their outputs are added:

  • y = F(x; θ) + x

The block therefore learns the residual: the change needed to improve its input. If no useful change is needed, it can drive F toward zero and behave close to an identity mapping. Addition requires matching tensor shapes. When the number of features or spatial resolution changes, the shortcut uses a learned projection, such as Wsx, commonly implemented with a 1×1 convolution or linear layer.

Why gradients reach deep layers

During backpropagation, the addition creates a direct route from a block’s output to its input. The gradient includes an identity contribution rather than being forced through every weight matrix and activation in the residual branch. This makes vanishing gradients far less destructive and lets networks such as ResNet train at depths that plain stacked networks struggle to reach. Transformer blocks use the same principle: each attention or feed-forward sublayer is wrapped as a residual addition, typically alongside LayerNorm.

What it changes in practice

Residual connections add little compute beyond an elementwise addition, though training still stores activations for backpropagation and projection shortcuts add parameters. They do not rescue a badly chosen learning rate: a loss curve that suddenly explodes can still signal unstable updates. But when a deep plain model plateaus because early layers receive weak gradients, residual blocks usually make optimization substantially more reliable by preserving both useful representations and a path for correction.

A skip connection, or residual connection, routes a layer’s input directly to a later output, typically by adding it to the transformed output: y = F(x) + x. This lets layers learn residual changes rather than complete mappings. Skip connections preserve gradient flow through deep networks, reducing vanishing gradients and making very deep models easier to optimize.

Imagine editing a photo through many filters. Normally, each filter must pass along a changed version of the image. A skip connection adds a shortcut: it lets the earlier image travel around one or more filters and rejoin the result later.

In a learning network, this means later parts can keep useful original information instead of having to rebuild it from scratch. The network can focus on making small improvements—such as sharpening an edge or noticing a word’s context—rather than replacing everything it already knows. Also called a residual connection, this shortcut helps very deep networks learn reliably without losing important signals along the way.