๐Ÿ”ฅLimited Offer: Get 50% OFFon AI & Full Stack Courses๐Ÿ”ฅ
Back to Deep Learning Notes
Topic #70

Leaky ReLU

Leaky ReLU is ReLU with one small but important change: instead of outputting exactly 0 for negative inputs, it outputs a small negative slope. That tiny change is enough to prevent neurons from dying permanently.

Formula

\[ \text{LeakyReLU}(z) = \begin{cases}z & z \ge 0\\\alpha z & z < 0\end{cases} \]

\(\alpha\) is a small constant, commonly 0.01, fixed before training (a hyperparameter, not learned).

Derivative

\[ \text{LeakyReLU}'(z) = \begin{cases}1 & z > 0\\\alpha & z < 0\end{cases} \]

Graph

A shallow negative slope (exaggerated here for visibility) instead of a flat zero for negative inputs.

Why This Fixes Dying ReLU

Because the derivative for negative inputs is \(\alpha\) (a small but non-zero number) instead of exactly 0, a neuron with a persistently negative weighted sum still receives a (small) gradient signal and can still update its weights, potentially recovering into a useful state. This directly resolves the dying ReLU problem from ReLU, at the cost of one extra hyperparameter (\(\alpha\)) to set.

Numerical Example

\[ \alpha = 0.01: \quad \text{LeakyReLU}(-5) = -0.05, \qquad \text{LeakyReLU}(5) = 5 \]

Code

import numpy as np
import torch.nn as nn
import torch

def leaky_relu(z, alpha=0.01):
    return np.where(z >= 0, z, alpha * z)

print(leaky_relu(np.array([-5, 0, 5])))   # [-0.05  0.    5.  ]

layer = nn.LeakyReLU(negative_slope=0.01)
print(layer(torch.tensor([-5.0, 0.0, 5.0])))

Common Mistakes

  • Assuming Leaky ReLU always outperforms plain ReLU โ€” in practice the difference is often small, and ReLU's simplicity/speed still makes it a reasonable default; Leaky ReLU is worth trying specifically if dying neurons are observed to be a real problem.
  • Setting \(\alpha\) too large โ€” if \(\alpha\) approaches 1, the function approaches a plain linear activation, losing the non-linearity a network needs (see Linear Transformations).

Interview Relevance

Q: "How does Leaky ReLU solve the dying ReLU problem?" By giving negative inputs a small non-zero slope (\(\alpha\), typically 0.01) instead of flattening them to exactly 0. This means a neuron with a negative weighted sum still has a non-zero gradient and can continue to update its weights during training, instead of getting permanently stuck outputting zero.

Practice Question

With \(\alpha=0.1\), compute Leaky ReLU's output and derivative at \(z=-4\).

Want to go beyond the notes?

Join CodingNow 2.0's Deep Learning course โ€” live mentorship, real projects, and 100% placement support.

Enroll Now โ€” Free Demo Available

Leaky ReLU โ€“ FAQs

Quick answers about learning Leaky ReLU in Deep Learning.

This free note from CodingNow 2.0 explains Leaky ReLU in Deep Learning โ€” concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Deep Learning topic on CodingNow 2.0, including Leaky ReLU, is 100% free with no signup required.
With focused practice, most students grasp Leaky ReLU in 1โ€“3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) โ€” expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now