class
Sigmoid
extends
ModuleSigmoid()Sigmoid (logistic) activation function.
Applies element-wise:
Maps all real inputs to the open interval . Commonly used in the output layer of binary classifiers and as a gating function in recurrent architectures (LSTM, GRU).
Notes
- Input: — any shape.
- Output: — same shape as input, values in .
Sigmoid saturates for large absolute inputs, causing vanishing gradients in deep networks. For hidden layers, ReLU or GELU are generally preferred.
Examples
>>> import lucid
>>> import lucid.nn as nn
>>> m = nn.Sigmoid()
>>> x = lucid.tensor([-2.0, -1.0, 0.0, 1.0, 2.0])
>>> m(x)
tensor([0.1192, 0.2689, 0.5 , 0.7311, 0.8808])
>>> # Binary classification output layer
>>> x = lucid.randn(16, 1)
>>> probs = m(x) # probabilities in (0, 1)
>>> probs.shape
(16, 1)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.