fn
tanh
→Tensortanh(x: Tensor)Hyperbolic tangent activation.
A rescaled, recentred sigmoid that maps the real line to
. Because outputs are zero-centred, tanh is generally
preferred over sigmoid for hidden layers in shallow networks
and is the canonical squashing function in RNN cells.
Parameters
xTensorInput tensor of any shape; activation is element-wise.
Returns
TensorActivated tensor with the same shape as x, values in
.
Notes
Derivative , maximum value at the origin. Saturates for ; in deep networks this leads to vanishing gradients, so modern feed-forward stacks prefer ReLU-family activations.
Examples
>>> import lucid
>>> from lucid.nn.functional import tanh
>>> x = lucid.tensor([-2.0, 0.0, 2.0])
>>> tanh(x)
Tensor([-0.9640, 0.0000, 0.9640])