nn_softshrink function

Softshrink module

Softshrink module

Applies the soft shrinkage function elementwise:

nn_softshrink(lambd = 0.5)

Arguments

  • lambd: the λ\lambda (must be no less than zero) value for the Softshrink formulation. Default: 0.5

Details

\mboxSoftShrinkage(x)={xλ,\mboxifx>λx+λ,\mboxifx<λ0,\mboxotherwise \mbox{SoftShrinkage}(x) =\left\{ \begin{array}{ll}x - \lambda, & \mbox{ if } x > \lambda \\x + \lambda, & \mbox{ if } x < -\lambda \\0, & \mbox{ otherwise }\end{array}\right.

Shape

  • Input: (N,)(N, *) where * means, any number of additional dimensions
  • Output: (N,)(N, *), same shape as the input

Examples

if (torch_is_installed()) { m <- nn_softshrink() input <- torch_randn(2) output <- m(input) }
  • Maintainer: Daniel Falbel
  • License: MIT + file LICENSE
  • Last published: 2025-02-14