mindspore.mint.nn.Hardshrink
- class mindspore.mint.nn.Hardshrink(lambd=0.5)
Applies Hard Shrink activation function element-wise.
The formula is defined as follows:
Hardshrink Activation Function Graph:
- Parameters
lambd (number, optional) – The threshold
defined by the Hard Shrink formula. Default:0.5
.
- Inputs:
input (Tensor) - The input of Hard Shrink. Supported dtypes:
Ascend: float16, float32, bfloat16.
- Outputs:
Tensor, the same shape and data type as the input.
- Raises
- Supported Platforms:
Ascend
Examples
>>> import mindspore >>> from mindspore import Tensor, mint >>> import numpy as np >>> input = Tensor(np.array([[0.5, 1, 2.0], [0.0533, 0.0776, -2.1233]]), mindspore.float32) >>> hshrink = mint.nn.Hardshrink() >>> output = hshrink(input) >>> print(output) [[ 0. 1. 2. ] [ 0. 0. -2.1233]]