Skip to content
StackDecode
AI & ML Atlas
Neural NetworkstechniqueInteractive simulation

Residual Learning

Layers learn the change to make to their input rather than the whole output.

The idea

Instead of asking a block to learn H(x) directly, ask it to learn the residual F(x) = H(x) − x and output x + F(x). If the best thing to do is nothing, the block only has to push F toward zero, which is easy. The identity shortcut also lets gradients flow directly to early layers.

y = F(x, {W}) + x

Watch it run

This is a real computation, not a drawing. Pause, step, change the settings, or try new random data.

Plain deep networkWith skip connections (ResNet)out12345678910111213141516171819in
  • plain
  • with skip connections

The learning signal (gradient) starts at the output and travels backwards through 20 layers. Bar height shows its size at each layer on a log scale.

layers back:
0
1/7

A residual block computes x + F(x). The "+ x" is a shortcut the gradient can travel along.

Step by step

  1. 1Pass the input through a few layers to get F(x).
  2. 2Add the original input back: y = x + F(x).
  3. 3Apply the activation.
  4. 4Stack many such blocks.

Where it is used

ResNets, transformers, and almost every deep architecture.

Watch out for

Shapes must match for the addition, otherwise a projection is needed.

Related