A structural design in deep neural networks where the input to a block of layers is added directly to its output, allowing gradients to bypass layers and flow smoothly during backpropagation.
A shortcut for data inside an AI. Instead of forcing information to pass through every single complex layer sequentially, a skip connection lets the original data “jump” over a few layers and rejoin the process later. This prevents the AI from forgetting the original input as it gets deeper.
As neural networks get deeper, they suffer from the vanishing gradient problem, where the error signal becomes too small to update the early layers. Residual connections solve this by learning a “residual” (the difference between the input and the desired output) rather than the full transformation. Mathematically, instead of learning $H(x)$, the network learns $F(x) = H(x) - x$, and the output becomes $F(x) + x$. This creates a direct highway for gradients to flow backward.
A corporate hierarchy. In a strict hierarchy, a message from the CEO gets distorted by the time it reaches the bottom. A skip connection is like a direct hotline or an open-door policy that allows the original message to bypass middle management and reach the ground floor perfectly intact.
# Conceptual: Residual Connection in a PyTorch Transformer Block
import torch
import torch.nn as nn
class ResidualBlock(nn.Module):
def __init__(self):
super().__init__()
self.layer_norm = nn.LayerNorm(512)
self.feed_forward = nn.Linear(512, 512)
def forward(self, x):
# The residual connection: add the original input 'x' to the processed output
return x + self.feed_forward(self.layer_norm(x))