Hardshrink

class paddle.nn. Hardshrink ( threshold=0.5, name=None ) [源代码]

Hardshrink激活层

\[\begin{split}Hardshrink(x)= \left\{ \begin{aligned} &x, & & if \ x > threshold \\ &x, & & if \ x < -threshold \\ &0, & & if \ others \end{aligned} \right.\end{split}\]

其中,\(x\) 为输入的 Tensor

参数

  • threshold (float, 可选) - Hardshrink激活计算公式中的threshold值。默认值为0.5。

  • name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 Name

形状:
  • input: 任意形状的Tensor。

  • output: 和input具有相同形状的Tensor。

代码示例

import paddle

x = paddle.to_tensor([-1, 0.3, 2.5])
m = paddle.nn.Hardshrink()
out = m(x) # [-1., 0., 2.5]