Tanh

Activation · node type · Tanh

Squashes any number into the range −1 to 1, centered at zero.

Also called Hyperbolic tangent

Move the input and compare activation functions. The gradient is what training sees: where it is flat, learning stalls.
-4-224-22

f(1.00) = 0.762

Figure 1. Try it: every number is computed in your browser from the formula below.

What it does

Tanh has the same S shape as the sigmoid but runs from −1 to 1 and passes through the origin. Zero-centered outputs make it a natural choice for signed quantities: the candidate values written into an LSTM cell, pixel values of generated images scaled to [−1, 1], or a continuous control command that must stay within limits. Small reinforcement-learning policies, such as the PPO agents in the catalog, also use it in their hidden layers.

Formula

tanh(x) = (ex − e−x) / (ex + e−x)tanh(x) = 2·σ(2x) − 1

Shapes and parameters

Shapes
Any shape in, the same shape out.
Parameters
None. An activation is a fixed function applied to every element, so it adds no parameters.
Used for
Hidden layers of the CartPole and Acrobot policies, the torque output of the Pendulum controller, GAN generator outputs, and the cell update inside LSTM and GRU.

Figure 2. Tanh inside Gas turbine monitor, a real model in WeightSpace. The outlined node is Tanh; select any node for its shapes and parameters.

Figure 3. The typed ports of Tanh, in the same format as every model drawing. Letters such as N or C stand for any size.

In WeightSpace

Read-only in WeightSpace today: there is nothing learned inside it. When an edit moves a bias in the layer before it, this function decides how much of that shift reaches the next layer, so its shape explains why some edits flip an answer and others barely move it.