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

Sigmoid vs Tanh

This comparison note puts sigmoid and tanh side by side directly โ€” useful both for interviews and for the concrete decision of which to use inside an LSTM/GRU gate, where both still appear regularly.

Side-by-Side Comparison

SigmoidTanh
Formula\(\sigma(z)=\frac{1}{1+e^{-z}}\)\(\tanh(z)=2\sigma(2z)-1\)
Range(0, 1)(-1, 1)
Zero-centered?No โ€” always positiveYes
Value at \(z=0\)0.50
Max derivative0.251.0
Saturates for large \(|z|\)?YesYes
Typical use todayBinary classification output; LSTM/GRU gates (values interpreted as "how much to let through," 0 to 1)LSTM/GRU candidate values (a bounded, signed update)

Why Both Still Appear Inside LSTM/GRU Cells

Both survive specifically because their bounded ranges are semantically meaningful there, not because they avoid vanishing gradients (they don't, within a single cell's internal computation) โ€” sigmoid's (0,1) range is exactly right for a "gate" controlling how much information to keep or discard, and tanh's (-1,1) range is exactly right for a candidate value that can push a cell's memory in either direction. This is covered in full in the LSTM & GRU category.

Code โ€” Plotting the Difference

import numpy as np

def sigmoid(z): return 1 / (1 + np.exp(-z))
def tanh(z): return np.tanh(z)

z = np.linspace(-5, 5, 5)
print("sigmoid:", sigmoid(z))
print("tanh:   ", tanh(z))
# sigmoid stays entirely positive; tanh is symmetric around 0

Common Mistakes

  • Assuming tanh solves vanishing gradients because it's zero-centered โ€” it saturates just as severely as sigmoid for large \(|z|\); zero-centering only addresses a separate, secondary optimization issue.
  • Using sigmoid for a hidden layer "because it's simpler to reason about" in a deep feedforward network โ€” for hidden layers, ReLU (or a variant) is virtually always the better modern default for both of these reasons.

Interview Relevance

Q: "If both sigmoid and tanh suffer from vanishing gradients, why does an LSTM still use both internally?" Their bounded ranges carry specific semantic meaning inside a gated cell: sigmoid's (0,1) output is used directly as a "how much to let through" gate value, and tanh's (-1,1) output is used as a signed candidate update. The vanishing-gradient concern is mitigated in LSTMs by a separate mechanism โ€” the cell state's largely additive update path โ€” not by avoiding these activations.

Practice Question

For \(z=3\), compute both \(\sigma(3)\) and \(\tanh(3)\). Which one is closer to its respective saturation bound?

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

Sigmoid vs Tanh โ€“ FAQs

Quick answers about learning Sigmoid vs Tanh in Deep Learning.

This free note from CodingNow 2.0 explains Sigmoid vs Tanh 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 Sigmoid vs Tanh, is 100% free with no signup required.
With focused practice, most students grasp Sigmoid vs Tanh 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