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) – 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.9, -0.2, 0.1, 0.8]) >>> out = F.softshrink(x) >>> print(out) Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True, [-0.39999998, 0. , 0. , 0.30000001])