Residual connections: how skip paths make very deep networks trainable
10 questions on skip connections, residual blocks, shattered gradients, smoother error surfaces, placement of the addition and very deep networks.
- 10 questions
- Stopwatch
- Instant feedback
Sample questions
Play now ↑Answers stay hidden. Start the quiz to play them.
Sample 1
A residual block's inner function outputs exactly 0 for every input. What does the block return when its input is 5?
- 0
- 5
- 10
How it works
- One question per screen. An answer is final once sent.
- You see right away whether you were right, with a short explanation.
- The stopwatch runs: on equal scores, the faster player ranks first.
- Only your best attempt counts, so replaying is never risky.
About this quiz
For years, adding layers to a network was a gamble. A few more layers might help, but past a certain depth, training became erratic and results got worse, even with careful initialisation and normalisation. Then a small change to the architecture made networks hundreds of layers deep trainable: add the input of each block back onto its output. That is all a residual connection does. It looks too simple to matter, yet it reshaped the design of image, language and many other models, and understanding why it works says a good deal about what makes deep networks hard to train.
This quiz covers the idea and the explanations offered for it. You will see what a residual block computes and why it can so easily behave as the identity, which means that adding a block cannot easily make a network worse than it was. You will see why the name residual fits, since each block learns the difference between what it receives and what is wanted. You will also meet shattered gradients, a phenomenon in which the gradient of a very deep network with ReLU units becomes wildly irregular, and see how skip connections calm it. The result can be seen on a drawing of the error surface, which turns from jagged to smooth.
The questions include small calculations, a design detail about where in a block the addition should happen, and a view of the whole network as a bundle of shorter paths. The aim is to give you a mental model that explains the technique, not just a recipe for applying it.
Typical misunderstandings are worth clearing. Residual connections do not add parameters, they add a path. They do not by themselves replace normalisation, and in practice the two are used together. And depth alone is not the problem: it is the combination of depth and a gradient that varies erratically from one point to the next that defeats the optimisation, which is why a smoother surface helps so much. The idea has also travelled far beyond its origins. Skip paths now appear in image models, in the layers of the networks used for language, and in many architectures for audio and graphs, usually in the same form: a block that adds what it computes to what it received. Anyone reading a modern architecture diagram will meet them constantly, so understanding what they achieve, a protected route for information and gradients through the whole depth of the network, turns an apparently arbitrary arrow into something meaningful. It also explains why removing one can make a previously stable model suddenly hard to train.
The quiz suits learners who have met deep networks and want to see why skip connections are everywhere, and practitioners who use residual blocks without having examined them. It needs only simple arithmetic and pictures. There are 10 questions, each with an explanation, and it takes about four minutes.
Questions and answers
›How long does the quiz take?
About 3 to 4 minutes for 10 questions, at roughly 20 seconds each. After every answer you see an explanation, so you can learn from the ones you miss.
›What is a residual connection?
It is a shortcut that adds the input of a block of layers to the block's output. If the block computes some function of its input, the residual block returns that function plus the input itself. Connections of this type are one form of skip-layer connection, and a network built from a sequence of such blocks is called a residual network.
›Why is the identity easy for a residual block?
Because the shortcut already passes the input through unchanged, the block only has to produce a result close to zero for the output to equal the input. That happens when the parameters inside the block are small. A block that is not needed can therefore effectively switch itself off, so extra depth does not have to hurt.
›Why are they called residual?
If a block's output is the input plus a function of the input, then the function represents what remains once the input has been subtracted from the desired output, a residual. Each block learns this difference between the identity and the target, which can be easier to learn than the whole mapping from scratch.
›What are shattered gradients?
With ReLU activations, the number of linear pieces a network can represent grows exponentially with depth, and so does the number of places where the gradient jumps. In a very deep plain network, tiny changes to early weights can change the gradient a lot, which breaks the assumption of smoothness on which gradient-based optimisation relies and makes training ineffective.
›How do residual connections help the error surface?
Visualisations of error surfaces show that a deep network with residual connections has a much smoother surface than the same network without them. The gradients are less sensitive to the input values, so optimisation behaves better. Together with batch normalisation, residual connections largely remove the difficulties of vanishing, exploding and shattered gradients.
›Where should the addition be placed in a block?
A block usually alternates linear layers with ReLU activations. If the shortcut added the output of a ReLU, everything added would be non-negative, which limits what the sum can represent. The more common arrangement puts the addition at a point where the values can be of either sign, giving the block more freedom.
›Do the input and output of a residual block have to match in size?
Yes, because they are added together, so they must have the same dimension. When the dimension has to change somewhere in the network, a matrix of learnable parameters, which need not be square, can be included in the shortcut path to bring the input to the right size.