Hello! Welcome to the final lesson of our module on the chain rule and backpropagation.
In our last session, we diagnosed a fundamental illness that plagued early deep neural networks: the vanishing and exploding gradient problems. We saw how the chain rule, when applied over many layers, could cause the error signal to either shrink into oblivion or spiral out of control. We identified saturating activation functions, like sigmoid, as a primary cause of vanishing gradients due to their small derivatives.
Today, we transition from diagnosis to treatment. This lesson is all about the cure. We will systematically compare the common activation functions, analyzing how their unique mathematical properties provide solutions to the vanishing gradient problem. You will learn not just what function to use, but why it works, connecting its graphical shape and its derivative directly to the flow of gradients and the success or failure of the training process.
The Old Guard: Sigmoid and Tanh
We begin with the two functions that dominated early neural network research: Sigmoid and Tanh (hyperbolic tangent). As we discovered, the sigmoid function was a major culprit in the vanishing gradient problem.

Let's review the issues and see how Tanh offered a partial improvement.
-
Sigmoid ():
- Output Range: (0, 1). This is not zero-centered. When all activations from a layer are positive, it introduces a bias in the gradient updates for the next layer, leading to inefficient, zig-zagging convergence.
- Gradient: The derivative, , has a maximum value of 0.25. As we saw, multiplying these small values repeatedly across many layers is the recipe for vanishing gradients.
-
Tanh ():
- Output Range: (-1, 1). This is zero-centered, which is a significant improvement over sigmoid. It helps the optimization process by providing more balanced inputs to subsequent layers.
- Gradient: The derivative, , has a maximum value of 1.0. This is four times larger than sigmoid's peak, which means the gradient signal attenuates much more slowly.
While Tanh was a step up from Sigmoid and led to faster training, it did not solve the fundamental problem. Both functions saturate—that is, they flatten out for large positive or negative inputs. In these flat regions, the derivative is nearly zero, effectively stopping the flow of gradients. This "saturation" was the key barrier to training truly deep networks.
The following video does an excellent job of visualizing why this saturation is so problematic.
Why ReLU Is Better Than Other Activation Functions | Tanh Saturating Gradients
This video from DataMListic clearly breaks down the derivatives of Tanh and Sigmoid, visually demonstrating how they "saturate" and stop providing a useful learning signal.
Please watch from the derivative analysis. Pay close attention to the graphs of the derivatives for Tanh and Sigmoid. The key takeaway is that for inputs far from zero, the derivative is essentially zero. Then, watch the summary segment from the explanation of convergence. The video explains how this "saturating non-linearity" forces the network to learn much more slowly compared to a non-saturating function.
The Revolution: ReLU (Rectified Linear Unit)
The solution that finally broke the logjam and enabled the deep learning revolution was almost shockingly simple. The Rectified Linear Unit, or ReLU, was proposed.
Let's analyze why this simple function was so effective.
- Non-saturating: For any positive input, the function is linear. It doesn't flatten out, so it never stops providing a signal.
- Constant, Strong Gradient: The derivative of ReLU is straightforward: This is the crucial insight. For any active neuron (one with a positive input), the gradient flowing back through it is multiplied by exactly 1. The error signal passes through deep networks without attenuation, completely solving the vanishing gradient problem for active neurons.
- Computational Efficiency: Calculating is a trivial operation for a computer, far faster than the exponential calculations required for Sigmoid and Tanh. This leads to significant speedups in training time.
The following article provides an excellent overview of the transition from Sigmoid to ReLU and the profound impact it had.
Activation Functions: ReLU, Sigmoid, and Beyond | Let's Data Science
This article from Let's Data Science gives a clear narrative of the evolution of activation functions, highlighting the specific problems that each new function was designed to solve.
First, read the section on the classic functions, Sigmoid and Tanh. This will reinforce what we've just discussed about saturation. Next, read the section on ReLU. Focus on how its constant gradient of 1 is the key to making deep networks trainable.
The Catch: The Dying ReLU Problem
ReLU seems like a perfect solution, but it has its own failure mode. What happens if a neuron's input, the weighted sum , is consistently negative for all inputs in your training data?
The ReLU unit will always output 0. Consequently, the gradient for that neuron will also always be 0. The weights and bias for that neuron will never receive an update. The neuron is effectively "dead" and will never participate in the network again. This is known as the Dying ReLU problem. A large learning rate or a poor choice of initial weights can accidentally push a neuron into this dead state, from which it can't recover.
The following short video provides a great animated intuition for this specific failure mode.
Activation Functions - EXPLAINED!
This CodeEmporium video uses simple animations to illustrate the core concepts, including the failure mode of ReLU.
First, watch the brief segment explaining the Dying ReLU problem. Then, for a more detailed look at the mechanism, watch from the deeper explanation.
The Modern Family: Fixing the Flaws
The Dying ReLU problem spurred the development of a family of related activation functions designed to keep the benefits of ReLU while mitigating its risks.
Activation Functions: ReLU, Sigmoid, and Beyond | Let's Data Science
Let's return to the same article to explore the modern solutions.
First, read the section on the problem, which explains the cause and gives a practical diagnostic tip. Then, read about the solutions in the section ReLU Variants. Pay attention to the simple but clever fix introduced by Leaky ReLU, and how PReLU and ELU build on that idea.
Here's a quick summary of these variants:
- Leaky ReLU: Instead of outputting 0 for negative inputs, it outputs a small, pre-defined linear function, like where . This ensures there is always a small, non-zero gradient, preventing neurons from dying completely.
- Parametric ReLU (PReLU): This is the same as Leaky ReLU, but instead of being a fixed hyperparameter, is a learnable parameter that is optimized during training.
- Exponential Linear Unit (ELU): This uses an exponential curve for negative inputs, which has some beneficial properties, like pushing the mean activations closer to zero, which can speed up learning.
Beyond ReLU: The New Standard for Transformers
Your interest in models like AlphaFold touches on transformer architectures, which have become dominant in many areas of AI, from natural language processing to computational biology. These models have largely converged on even more advanced activation functions like GELU and SiLU (also known as Swish).
Activation Functions: ReLU, Sigmoid, and Beyond | Let's Data Science
This last reading gives a glimpse into the current state of the art, which is particularly relevant for the advanced models you're interested in.
Read the sections on GELU and SiLU/SwiGLU. You don't need to memorize the complex formulas. The key takeaway is the conceptual shift: these functions act as smooth, "probabilistic" gates rather than the hard on/off switch of ReLU, which has proven more effective for the types of data distributions found inside transformer models. Finally, read How Activation Choice Affects Training for a nice summary of the three key ways activations influence training.
Diagnosing the Problem in Practice
How would you know if your network is suffering from vanishing gradients? You don't have to guess. The problem manifests in observable ways during training.

- Loss Plateauing: The most obvious sign. The training loss decreases for a few epochs and then flatlines, even with a small learning rate. This suggests the gradients are too small to produce meaningful weight updates.
- Gradient Histograms: Plotting a histogram of the gradient values across all layers. If the histogram is sharply peaked at zero, it's a strong sign of vanishing gradients.
- Layer-wise Gradient Norms: This is a powerful diagnostic. You compute the norm (magnitude) of the gradients for each layer and plot it against the layer number. In a network with vanishing gradients, you will see a steep drop-off, with layers closer to the input having much smaller gradient norms than layers closer to the output. This is the smoking gun for a signal that dies as it propagates backward.
Conclusion
We have journeyed from the historical activation functions that were plagued by vanishing gradients to the modern, sophisticated functions that enable today's state-of-the-art models. The evolution of these simple, neuron-level components has been a critical driver of progress in the entire field of deep learning.
Key Takeaways:
- Saturating Functions (Sigmoid, Tanh) cause vanishing gradients because their derivatives approach zero for large inputs, progressively killing the error signal during backpropagation.
- ReLU was a revolution because its constant, non-zero gradient (for positive inputs) allows the error signal to propagate through very deep networks without vanishing.
- ReLU's primary weakness is the Dying ReLU problem, where neurons can get stuck in an inactive state with a zero gradient.
- Leaky ReLU, PReLU, and ELU are simple and effective fixes for the dying neuron problem, ensuring a small gradient always exists.
- Modern architectures, especially transformers, often use even more advanced functions like GELU and SiLU/SwiGLU, which provide smoother, non-monotonic activation that is empirically more effective for those systems.
- The choice of activation function is a critical design decision that has a direct and profound impact on gradient flow, training speed, and ultimate model performance.
In our next module, we will shift our focus. We've seen how backpropagation works and how to ensure the gradient signal can flow. But what if the landscape it's trying to navigate is itself treacherous? We will begin our final module by exploring the concept of conditioning, and see how the very structure of our data can create poorly shaped loss surfaces that dramatically slow down or stall gradient-based optimization, regardless of our choice of activation function.