softshrink¶
- paddle.nn.functional. softshrink ( x, threshold=0.5, name=None ) [source]
-
softshrink activation
\[\begin{split}softshrink(x)= \left\{ \begin{array}{rcl} x - threshold,& & \text{if } x > threshold \\ x + threshold,& & \text{if } x < -threshold \\ 0,& & \text{otherwise} \end{array} \right.\end{split}\]- Parameters
-
x (Tensor) – The input Tensor with data type float32, float64.
threshold (float, optional) – The value of threshold(must be no less than zero) for softplus. Default is 0.5
name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.
- Returns
-
A Tensor with the same data type and shape as
x
.
Examples
import paddle import paddle.nn.functional as F import numpy as np x = paddle.to_tensor(np.array([-0.9, -0.2, 0.1, 0.8])) out = F.softshrink(x) # [-0.4, 0, 0, 0.3]