liveBook · Manning

Residual connection

As explained in Grokking AI Algorithms, Second Edition

A skip connection is a direct connection that carries an earlier layer's representation to a later corresponding layer, bypassing intervening layers.

A residual connection is a shortcut that carries an earlier representation past some processing and combines it with the later result. Think of keeping the original sketch while adding a new layer of detail: the later layer need not recreate everything from memory. section 11.26

In a Transformer feed-forward block, the shortcut carries the block’s input directly to its output. The processed result is added to that input, so both must have the same size. A project-down layer turns an 8D intermediate vector back into a 4D vector before the addition. This helps stabilize training and lets the model bypass feed-forward calculations that are not useful for a particular token. section 11.26

Following the Transformer shortcut

After projection, one 4D result is [1.6265, -1.3635, -0.2657, 1.9661]. Adding the bias [0.05, -0.1, 0.15, -0.02] gives [1.6765, -1.4635, -0.1157, 1.9461]. The residual step then adds the feed-forward block’s original 4D input to this 4D result, position by position. section 11.26

A U-Net uses a related shortcut for a different job. Downsampling captures what an image contains but loses precise information about where details belong. A skip connection carries an early, high-resolution feature map directly to the corresponding decoder layer. Here the maps are concatenated, not added: an 8×8×8 early tensor joined with a 16×8×8 upsampled tensor becomes a 24×8×8 tensor. The decoder can then use both spatial detail and deeper, abstract information when reconstructing an image. section 12.15 section 12.19

12.42 How skip-connection feature maps are combined with the upsampled feature maps
12_42

Follow the early feature maps across to the decoder and see where they join the upsampled maps. section 12.19

How Grokking AI Algorithms, Second Edition covers it

How deep it goes
Works through matching vector sizes and residual addition, then traces U-Net concatenation with tensor shapes.
Examples
Traces an 8D-to-4D projection and an 8×8×8 feature map concatenated with a 16×8×8 upsampled map.
What you can do after
Build it from scratch by adding matching Transformer vectors or concatenating U-Net feature maps before convolution.
How it connects
Connects residual shortcuts to Transformer feed-forward blocks and skip connections to U-Net encoders, decoders, and upsampling.

Also explained in

Compare how 12 books explain residual connection →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking AI Algorithms, Second Edition. The section links point to the parts of the book it draws on.