hardshrink

paddle.nn.functional. hardshrink ( x, threshold=0.5, name=None ) [source]

hard shrinkage activation

\[\begin{split}hardshrink(x)= \\left\\{ \\begin{aligned} &x, & & if \\ x > threshold \\\\ &x, & & if \\ x < -threshold \\\\ &0, & & if \\ others \\end{aligned} \\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) – 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

x = paddle.to_tensor([-1, 0.3, 2.5])
out = F.hardshrink(x) # [-1., 0., 2.5]