ReLU Activation Function hero
Lesson 2Hidden Layers & Depth

ReLU Activation Function

Why Sigmoid saturation limits hidden layers, and how the ReLU activation function sets negative scores to zero while passing positive scores forward.

At the end of Lesson 1, we wrote the linear step for both layers of our network:

z(1)=W(1)x+b(1)⏟Layer 1 Linear Step→Activation (?)a(1)⟶z(2)=W(2)a(1)+b(2)⏟Layer 2 Linear Step\underbrace{z^{(1)} = W^{(1)}x + b^{(1)}}_{\text{Layer 1 Linear Step}} \quad \xrightarrow{\text{Activation } (?)} \quad a^{(1)} \quad \longrightarrow \quad \underbrace{z^{(2)} = W^{(2)}a^{(1)} + b^{(2)}}_{\text{Layer 2 Linear Step}}

Before we can compute Layer 2, we need the activation step that completes Layer 1 (z(1)→a(1)z^{(1)} \to a^{(1)}) and provides the output for Layer 2 to compute on.

In Topic 3, we passed Layer 1's linear scores through the Sigmoid function (σ\sigma) because those three neurons were the final outputs of our model—we needed each score compressed into a human-readable probability between 00 and 11 (0%0\% to 100%100\%).

Now that Layer 1 is a Hidden Layer whose only job is to pass intermediate scores forward to Layer 2, should we keep using Sigmoid—or does a hidden layer need a different activation function?


The Problem With Sigmoid Inside a Hidden Layer

A human is no longer the audience of the hidden layer's output—the audience is Layer 2. Look at what happens when we pass 'Die Hard in Space''s three linear scores from Topic 3 (z(1)z^{(1)}) through Sigmoid:

z(1)=[+7.5−8.5+10.0]→σ(z(1))[0.9990.00020.9999]≈[1.00.01.0](Hit)(Oscar)(Intl)z^{(1)} = \begin{bmatrix} +7.5 \\ -8.5 \\ +10.0 \end{bmatrix} \quad \xrightarrow{\quad \sigma\left(z^{(1)}\right) \quad} \quad \begin{bmatrix} 0.999 \\ 0.0002 \\ 0.9999 \end{bmatrix} \approx \begin{bmatrix} \mathbf{1.0} \\ \mathbf{0.0} \\ \mathbf{1.0} \end{bmatrix} \begin{matrix} \text{(Hit)} \\ \text{(Oscar)} \\ \text{(Intl)} \end{matrix}

Compare what Sigmoid does on each side of zero:

1. Below Zero (z≤0z \le 0): The 0.00.0 Floor Works

'Die Hard in Space' scored poorly on the Oscar neuron (zOscar(1)=−8.5z_{\text{Oscar}}^{(1)} = -8.5).

For 'Die Hard in Space', having Oscar potential is just an added bonus—not the main goal of the movie. But if the Oscar neuron passed raw −8.5-8.5 into Layer 2, lacking awards buzz would actively drag down the movie's greenlight score despite its strong commercial and international scores.

When a hidden neuron's score is negative (z≤0z \le 0), we want it to output 0.00.0 so it simply stays inactive—just as Sigmoid pushed −8.5-8.5 down to ≈0.0\approx 0.0.

2. Above Zero (z>0z > 0): The 1.01.0 Ceiling Destroys Positive Strength

'Die Hard in Space' scored strongly on Hit (+7.5+7.5) and even higher on International (+10.0+10.0).

Passing both through Sigmoid squashes them flat against the 1.01.0 probability ceiling (0.9990.999 and 0.99990.9999). To Layer 2, +7.5+7.5 and +10.0+10.0 now look virtually identical (≈1.0\approx 1.0)—erasing the difference in how strongly those two neurons scored.

The Goal of Hidden Layer Activation

Inside a hidden layer, the goal is clear: keep the 0.00.0 floor that zeroes out negative scores (z≤0)(z \le 0), but remove the 1.01.0 ceiling so positive scores (z>0)(z > 0) pass through unchanged.


The ReLU Activation Function

To create this one-way gate, modern neural networks use the ReLU activation function—short for Rectified Linear Unit. It simply replaces any negative score with 00 and keeps positive scores at their actual values—written mathematically as max⁡(0,z)\max(0, z) ("keep whichever is larger between 00 and zz"):

ReLU(z)=max⁡(0,z)={zif z>0(Active)0if z≤0(Inactive)\text{ReLU}(z) = \max(0, z) = \begin{cases} z & \text{if } z > 0 \quad \text{(Active)} \\ 0 & \text{if } z \le 0 \quad \text{(Inactive)} \end{cases}
The ReLU Activation Function Curve
The ReLU function sets negative linear scores ($z \le 0$) to $0.0$ while passing positive linear scores ($z > 0$) through unchanged.

Computing the Hidden Layer Activations

In our studio's neural network, Layer 1 uses the exact same weight matrix W(1)W^{(1)} and bias vector b(1)b^{(1)} from Topic 3, but replaces Sigmoid with ReLU to compute the hidden activation vector a(1)a^{(1)}:

z(1)=W(1)x+b(1)⟶a(1)=ReLU ⁣(z(1))z^{(1)} = W^{(1)}x + b^{(1)} \qquad \longrightarrow \qquad a^{(1)} = \text{ReLU}\!\left(z^{(1)}\right)

Just like Sigmoid in Topic 3, ReLU\text{ReLU} is applied element-wise to each value in the linear score vector z(1)z^{(1)}:

a(1)=ReLU ⁣(z(1))=[ReLU ⁣(zHit(1))ReLU ⁣(zOscar(1))ReLU ⁣(zIntl(1))]a^{(1)} = \text{ReLU}\!\left(z^{(1)}\right) = \begin{bmatrix} \text{ReLU}\!\left(z_{\text{Hit}}^{(1)}\right) \\[4pt] \text{ReLU}\!\left(z_{\text{Oscar}}^{(1)}\right) \\[4pt] \text{ReLU}\!\left(z_{\text{Intl}}^{(1)}\right) \end{bmatrix}

Using the linear score vectors z(1)z^{(1)} we already computed in Topic 3, let's calculate the hidden layer activations a(1)a^{(1)} for both scripts.

🎬 'Die Hard in Space': Hidden Layer Activation

Hidden NeuronLinear Score
(z(1) = W(1)x + b(1))
ReLU Rule
(max(0, z(1)))
Activation
(a(1))
Neuron State
Hit+7.5max(0, +7.5)7.5Active
Oscar−8.5max(0, −8.5)0.0Inactive
International+10.0max(0, +10.0)10.0Active

Look at what ReLU hands off to Layer 2:

  • Hit (7.57.5) and International (10.010.0) stay distinct: Both positive scores pass straight through, preserving the fact that International Appeal (10.010.0) scored higher than Commercial Hit (7.57.5).
  • Oscar (0.00.0) is inactive: Instead of passing a damaging negative score (−8.5-8.5) forward, ReLU sets the negative Oscar score to 0.00.0. As far as Layer 2 is concerned, the Oscar neuron contributes nothing for this script.

🎬 'The Notebook 2': Hidden Layer Activation

Hidden NeuronLinear Score
(z(1) = W(1)x + b(1))
ReLU Rule
(max(0, z(1)))
Activation
(a(1))
Neuron State
Hit−3.5max(0, −3.5)0.0Inactive
Oscar+0.5max(0, +0.5)0.5Active
International0.0max(0, 0.0)0.0Inactive

Look at what ReLU hands off to Layer 2:

  • Oscar (0.50.5) passes through: Only the Oscar neuron scored above zero (+0.5+0.5), passing 0.50.5 forward to Layer 2.
  • Hit (0.00.0) and International (0.00.0) are inactive: Whether a neuron scores well below zero like Hit (−3.5-3.5) or lands right on zero like International (0.00.0), ReLU outputs 0.00.0 for both.

Comparing the Scripts After Hidden Layer Activation

aDie Hard(1)=[7.50.010.0](Hit: Active)(Oscar: Inactive)(Intl: Active)aNotebook 2(1)=[0.00.50.0](Hit: Inactive)(Oscar: Active)(Intl: Inactive)a^{(1)}_{\text{Die Hard}} = \begin{bmatrix} \mathbf{7.5} \\ 0.0 \\ \mathbf{10.0} \end{bmatrix} \begin{matrix} \text{(Hit: Active)} \\ \text{(Oscar: Inactive)} \\ \text{(Intl: Active)} \end{matrix} \qquad \qquad a^{(1)}_{\text{Notebook 2}} = \begin{bmatrix} 0.0 \\ \mathbf{0.5} \\ 0.0 \end{bmatrix} \begin{matrix} \text{(Hit: Inactive)} \\ \text{(Oscar: Active)} \\ \text{(Intl: Inactive)} \end{matrix}

Instead of passing every score forward indiscriminately or squashing large positive scores against a ceiling, a ReLU hidden layer acts as a selective filter—setting negative scores to 0.00.0 while passing positive scores forward unchanged.


Previous
Hidden Layers and Output Layers