Tanh shrinkage activation.
Behaves like a smooth high-pass filter: subtracts the tanh-saturated component of the input, leaving small linear residuals near zero and near-linear behaviour for large magnitudes.
Parameters
Input tensor of any shape; activation is element-wise.
Returns
TensorActivated tensor with the same shape as x.
Notes
For , , so — small signals are cubically suppressed. For , saturates to so the output behaves like . -smooth and monotonic.
Examples
>>> import lucid
>>> from lucid.nn.functional import tanhshrink
>>> x = lucid.tensor([-2.0, -0.5, 0.0, 0.5, 2.0])
>>> tanhshrink(x)
tensor([-1.036, -0.03788, 0., 0.03788, 1.036])