ResNet and Identity Mappings
Stacking more layers onto a deep network should only ever help, but past a certain depth it makes training worse. ResNet fixes this with a trick so simple it looks like cheating: let each layer default to changing nothing at all.
Prerequisites: The Multilayer Perceptron, Backpropagation
Take a network that works well at 20 layers and add 15 more, purely by stacking on identity-like layers that in principle could just pass their input straight through unchanged. Common sense says performance can only stay the same or improve — worst case, the new layers learn to do nothing. In practice, before ResNet, it got worse: deeper plain networks had higher training error than their shallow counterparts, not from overfitting but because they became measurably harder to optimize. Gradients flowing back through many stacked layers of matrix multiplies and nonlinearities shrink or explode, and a plain deep stack simply couldn't find the "do nothing extra" solution even though it was sitting right there in its own hypothesis space.
The analogy: a moving walkway with shops along the side
Picture an airport corridor. A moving walkway carries you straight to the far end at a fixed speed, no effort required. Alongside it are optional shops — detours that add something to your day (a coffee, a magazine) but that you only take if they're worth the stop. If a shop is useless, you just skip it and the walkway still gets you there. Compare that to a corridor with no walkway, only a chain of shops you're forced to enter one after another; skipping a bad one means somehow threading through it anyway, and a long chain of forced stops makes the whole trip fragile. A residual network is the corridor with the walkway: each block's default behavior is "pass through unchanged," and the learned layers only need to figure out the extra adjustment on top, not reconstruct the whole signal from scratch.
The maths
A plain network layer computes a direct mapping from input to output:
In words: whatever function the layer's weights represent, that is the entire output — the layer must learn the complete transformation the network needs at that point, including simply preserving if that's the right answer.
A residual block instead computes:
In words: run through a small stack of learned layers to get — the residual, or "correction" — then add the original input back in via a skip connection (also called a shortcut). If the ideal transformation at this depth really is "do nothing," the network only has to learn , which is trivially easy — push the weights toward zero — rather than learning exactly, which requires the layer to reconstruct an identity mapping out of nonlinear pieces, a much harder target to hit by gradient descent.
The payoff shows up in backpropagation. Differentiating with respect to :
In words: the gradient flowing backward through a residual block is whatever the learned layers contribute, plus a guaranteed "+1" from the skip connection. Even if shrinks toward zero — the classic vanishing-gradient failure — the gradient signal still has that clean +1 path straight through, so it doesn't die as it's chained back through dozens or hundreds of blocks.
Worked example 1: gradient flow through 3 blocks, plain vs residual
Suppose each weight layer's local gradient, , happens to be a modest at every block (a plausible value once activations pass through repeated nonlinearities). Chain three plain layers by multiplying:
Only 6.4% of the original gradient signal survives three layers back. Now chain three residual blocks, where each local derivative is :
The residual gradient doesn't vanish — it doesn't even shrink. In a real 50- or 100-layer network the effect compounds: a plain stack's gradient decays toward zero roughly geometrically, while the residual version's floor is anchored by the chain of +1's, so early layers keep receiving a usable training signal no matter how deep the stack goes.
Worked example 2: a numeric forward pass
Let and suppose the block's two weight layers, before training has done anything useful, compute (a stand-in for whatever the learned layers currently express). Then:
Compare a plain layer that had to learn the whole mapping from scratch with the same starting weights: it would just output , badly wrong if the target really was close to 2. The residual block's output, 2.3, stays anchored near the input even while is still random and untrained — the network starts from a sensible baseline and only has to nudge away from it, rather than starting from an arbitrary point and having to find the entire right answer through training.
Try a very steep, narrow loss surface and watch how a poorly conditioned landscape makes it easy for steps to overshoot or crawl. That's the optimization difficulty ResNet's identity shortcuts sidestep — they reshape the loss surface near "do nothing" into something flatter and easier for gradient descent to navigate at extreme depth.
A residual block reframes what a layer has to learn: not the full output, but the correction on top of the input. Since "no correction" is achievable by driving weights to zero, depth stops being a liability — the network can always fall back to something at least as good as a shallower version, which is exactly the property plain deep stacks lacked.
What this means in practice
Skip connections are now the default in almost every deep architecture that goes beyond a handful of layers, including transformers (every attention and feed-forward sub-block has one) and U-Nets. For a quant training a deep network on tick-level order-book features or a long price history, "just add skip connections" is close to a free way to make a deeper network actually trainable — it costs one extra addition per block and no extra parameters. It's also why architecture ablations that report "removing skip connections drops accuracy by double digits" aren't overselling; the shortcuts aren't a minor refinement, they're what makes the optimization tractable at all past a certain depth.
The trap: assuming skip connections fix underfitting or bad data, when what they actually fix is optimization difficulty at depth. Adding residual blocks to a shallow, already-well-trained 4-layer network does essentially nothing — the vanishing-gradient problem they solve doesn't bite until you're stacking dozens of layers. A second, sneakier trap: the addition requires and to have matching shapes. When a block changes the number of channels or the spatial size, the skip path itself needs a small learned projection (usually a convolution) to match dimensions — forgetting this is a common source of shape-mismatch errors when implementing ResNet blocks by hand.
Related concepts
Practice in interviews
Further reading
- He, Zhang, Ren & Sun, Deep Residual Learning for Image Recognition (2015)
- Goodfellow, Bengio & Courville, Deep Learning, ch. 8