hardshrink¶
- paddle.nn.functional. hardshrink ( x, threshold=0.5, name=None ) [source]
-
hard shrinkage activation
\[\begin{split}hardshrink(x)= \left\{ \begin{array}{rcl} x,& &if \ {x > threshold} \\ x,& &if \ {x < -threshold} \\ 0,& &if \ {others} & \end{array} \right.\end{split}\]- Parameters
-
x (Tensor) – The input Tensor with data type float32, float64.
threshold (float, optional) – The value of threshold for hardthrink. Default is 0.5.
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([-1, 0.3, 2.5]) >>> out = F.hardshrink(x) >>> print(out) Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True, [-1. , 0. , 2.50000000])