mindspore.nn.Tanhshrink
- class mindspore.nn.Tanhshrink[source]
Applies Tanhshrink activation function element-wise and returns a new tensor.
Tanh function is defined as:
where
is an element of the input Tensor.- Inputs:
x (Tensor) - Tensor of any dimension.
- Outputs:
Tensor, with the same shape as the x.
- Raises
TypeError – If x is not a Tensor.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore as ms >>> from mindspore import Tensor, nn >>> import numpy as np >>> x = Tensor(np.array([1, 2, 3, 2, 1]), ms.float16) >>> tanhshrink = nn.Tanhshrink() >>> output = tanhshrink(x) >>> print(output) [0.2383 1.036 2.004 1.036 0.2383]