Skip to content
Deep Learning

Tanh function squishes values to be between?

-1 and 1

datasciencetrivia.com

Card 1 of 259. Answer: -1 and 1

Created by santiviquez

About · Quizzes · History of AI · To suggest new questions or report an error send me a dm.

The longer answer

Between −1 and 1. The hyperbolic tangent, tanh(x) = (eˣ − e⁻ˣ) / (eˣ + e⁻ˣ), maps any real number into the open interval (−1, 1), approaching 1 for large positive inputs and −1 for large negative ones without reaching either. It is odd, tanh(−x) = −tanh(x), and tanh(0) = 0, so its outputs are zero-centered.

Some values: tanh(1) ≈ 0.76, tanh(2) ≈ 0.96 and tanh(3) ≈ 0.995. The derivative, 1 − tanh²(x), is 1 at the origin, four times sigmoid's peak of 0.25, one reason tanh trained better than sigmoid in hidden layers before ReLU. It still saturates: the derivative is about 0.07 at x = 2 and 0.0099 at x = 3. In 32-bit floats, tanh(10) rounds to exactly 1.0.

Tanh lives on inside LSTMs and GRUs, which squash candidate states to (−1, 1), and in the output layer of image generators such as DCGAN, with pixels scaled to match. LeCun's 1998 "Efficient BackProp" recommended a scaled version, 1.7159 tanh(2x/3), chosen so that f(±1) = ±1.

All questions