class
Hardsigmoid
extends
ModuleHardsigmoid()Hard Sigmoid activation function.
Applies element-wise:
This is a piecewise-linear approximation of the logistic sigmoid that saturates to 0 for and to 1 for , with a linear ramp in between. It avoids the exponential required by the exact sigmoid, making it suitable for resource-constrained deployments.
Notes
- Input: — any shape.
- Output: — same shape as input, values in .
Examples
>>> import lucid
>>> import lucid.nn as nn
>>> m = nn.Hardsigmoid()
>>> x = lucid.tensor([-4.0, -3.0, 0.0, 3.0, 4.0])
>>> m(x)
tensor([0. , 0. , 0.5 , 1. , 1. ])
>>> # Lightweight gating in mobile attention heads
>>> x = lucid.randn(2, 32)
>>> out = m(x)
>>> out.shape
(2, 32)Methods (1)
fn
forward
→Tensorforward(x: Tensor)Apply the activation function element-wise.
Parameters
inputTensorInput tensor of arbitrary shape.
Returns
TensorOutput tensor of the same shape as input.