liveBook · Manning

Tanh

As explained in Grokking Machine Learning

A smooth S-shaped activation function that maps real-valued inputs to values between negative one and one.

tanh, or the hyperbolic tangent, is a smooth S-shaped activation function that squishes any real-valued input into the interval from −1 to 1. In a neural network, it helps transform layer outputs so the model can build more complex decision boundaries. section 10.2 section 10.6

tanh is useful, but it has important trade-offs:

  • It is less flat than sigmoid, so it often works better in practice. section 10.2
  • It still has flat regions and can contribute to the vanishing-gradient problem during training. section 10.2 section 10.6
  • It contrasts with ReLU, which turns negative inputs into zero and is used more widely to reduce vanishing gradients. section 10.2

Compare activation-function shapes

Visualize sigmoid, tanh, and ReLU side by side: tanh occupies the middle position, showing its S-shaped curve and output range between −1 and 1.

How Grokking Machine Learning covers it

How deep it goes
Explains tanh’s output range, shape, sigmoid comparison, and vanishing-gradient limitation without deriving its formula.
Examples
Compares tanh visually with sigmoid and ReLU in a three-function activation plot.
What you can do after
Evaluate tanh against sigmoid and ReLU when selecting activation functions for neural-network training.
How it connects
Connects tanh to activation functions, sigmoid, ReLU, neural networks, perceptrons, and vanishing gradients.

Also explained in

Compare how 4 books explain tanh →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Machine Learning. The section links point to the parts of the book it draws on.