ElemedexA pocket encyclopedia of AI architectures

Glossary (TM) › Architectural parts

TM104

Residual connection

Also: skip connection, shortcut connection

In Spanish: Conexión residual

A shortcut that adds a layer's input to its output, so the layer only learns a correction; it makes networks with hundreds of layers trainable.

A residual connection replaces "the layer's output is F(x)" with

output = x + F(x)

The layer no longer has to rebuild the whole representation: it only learns what should be added to it, the "residual". If it has nothing useful to contribute, it can push F toward zero and let x pass through untouched. The idea became famous with the ResNets of He et al. (2016), vision networks of up to 152 layers that won the 2015 ImageNet competition (3.6% top-5 error, per the table in (Witten et al., 2017, p. 439)).

What problem it solves. In a deep network, the error signal that backpropagation carries back to the first layers is multiplied by many factors and tends to fade (see vanishing gradient). The sum offers a direct route: the derivative of x + F(x) with respect to x is 1 + F′(x), and that "1" ensures the gradient gets through. Chollet (2021) lists residual connections among the 2014–2016 innovations that improved gradient propagation and made it possible to train models of almost arbitrary depth from scratch (2021, sec. 1.3.3; see also sec. 9.3.2).

In transformers. Every sublayer of the Transformer is wrapped in a residual connection: LayerNorm(x + Sublayer(x)) (Vaswani et al., 2017, sec. 3.1). This is what allows GPT-3's 96 blocks to be stacked and, at the same time, what gives rise to the picture of the residual stream: one vector per token that runs through the whole network, with each layer adding its contribution (Elhage et al., 2021). In BERT's diagram they appear as "Add & normalize".

An analogy. It is the difference between rewriting a draft from scratch every round and correcting it with notes in the margin: the second is more stable, and the original text is never entirely lost.

Sources

  • Chollet, F. (2021). Deep learning with Python (2nd ed.). Manning Publications. §
  • Elhage, N., Nanda, N., Olsson, C., Henighan, T., Joseph, N., Mann, B., Askell, A., Bai, Y., Chen, A., Conerly, T., DasSarma, N., Drain, D., Ganguli, D., Hatfield-Dodds, Z., Hernandez, D., Jones, A., Kernion, J., Lovitt, L., Ndousse, K., . . . Olah, C. (2021). A mathematical framework for transformer circuits. Transformer Circuits Thread. https://transformer-circuits.pub/2021/framework/index.html §
  • He, K., Zhang, X., Ren, S., & Sun, J. (2016). Deep residual learning for image recognition. In Proceedings of the 2016 IEEE Conference on Computer Vision and Pattern Recognition (CVPR) (pp. 770–778). IEEE. https://doi.org/10.1109/CVPR.2016.90 §
  • Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., Kaiser, Ł., & Polosukhin, I. (2017). Attention is all you need. In Advances in Neural Information Processing Systems (Vol. 30). Curran Associates. https://proceedings.neurips.cc/paper_files/paper/2017/hash/3f5ee243547dee91fbd053c1c4a845aa-Abstract.html §
  • Witten, I. H., Frank, E., Hall, M. A., & Pal, C. J. (2017). Data mining: Practical machine learning tools and techniques (4th ed.). Morgan Kaufmann. https://doi.org/10.1016/C2015-0-02071-8 §