hard_shrink

paddle.fluid.layers.ops. hard_shrink ( x, threshold=None ) [source]

HardShrink activation operator

\[\begin{split}out = \begin{cases} x, \text{if } x > \lambda \\ x, \text{if } x < -\lambda \\ 0, \text{otherwise} \end{cases}\end{split}\]
Parameters
  • x (Tensor) – Input of HardShrink operator

  • threshold (FLOAT) – The value of threshold for HardShrink. [default: 0.5]

  • with_quant_attr (BOOLEAN) – Whether the operator has attributes used by quantization.

Returns

Output of HardShrink operator

Return type

out (Tensor)

Examples

>>> import paddle.fluid as fluid
>>> data = fluid.layers.data(name="input", shape=[784])
>>> result = fluid.layers.hard_shrink(x=data, threshold=0.3)