tanhshrink

paddle.nn.functional. tanhshrink ( x, name=None ) [source]

tanhshrink activation

\[tanhshrink(x) = x - tanh(x)\]
Parameters
  • x (Tensor) – The input Tensor with data type float32, float64.

  • name (str, optional) – For details, please refer to Name. Generally, no setting is required. Default: None.

Returns

A Tensor with the same data type and shape as x .

Examples

>>> import paddle
>>> import paddle.nn.functional as F

>>> x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
>>> out = F.tanhshrink(x)
>>> print(out)
Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True,
[-0.02005100, -0.00262472,  0.00033201,  0.00868741])