fn

tanh

Tensor
tanh(input: Tensor)
source

Element-wise hyperbolic tangent.

Saturating activation mapping the real line into (1,1)(-1, 1).

Parameters

inputTensor
Input tensor.

Returns

Tensor

Element-wise result with the same shape as input.

Notes

Mathematical definition:

outi=tanh(xi)=exiexiexi+exi\text{out}_i = \tanh(x_i) = \frac{e^{x_i} - e^{-x_i}}{e^{x_i} + e^{-x_i}}

Gradient: 1tanh2(x)1 - \tanh^{2}(x). Common activation in RNNs.

Examples

>>> import lucid
>>> x = lucid.tensor([1.0, 2.0, 3.0])
>>> lucid.tanh(x)
Tensor([...])