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) − 1Shapes 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.
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.
Where it appears
- Name the emotion in a sentenceALBERT Base v2 Emotion1312M params
- Track motion between two framesRAFT-Small13990K params
- Detect speech in a recordingSilero VAD4545K params
- Balance a pole on a moving cartStable Baselines3 PPO24.6K params
- Find rows and cells in a tablePaddleOCR SLANet+21.9M params
- Swing a two-link robot upwardStable Baselines3 PPO24.8K params
- Ask a question about a tableGoogle TAPAS Tiny14.5M params
- Balance a swinging pendulumDI-engine Pendulum DDPG14.5K params
- Classify text with your labelsXtremeDistil zero-shot113M params
- Gas turbine monitorWeightSpace health monitor1146 params
- Generate a tiny imageCIFAR-10 Conditional GAN112M params
- Read a phrase aloudKokoro 82M181M params
- Remove background noiseGTCRN148K params
- Rerank search resultsMS MARCO TinyBERT-L214.4M params