Skip to content
class

Softplus

extendsModule
Softplus(beta: float = 1.0, threshold: float = 20.0)

Implementing kernel

C++ engine symbols that back this Python API.

Softplus activation function.

Applies element-wise:

Softplus(x)=1βln⁡ ⁣(1+eβx)\text{Softplus}(x) = \frac{1}{\beta} \ln\!\bigl(1 + e^{\beta x}\bigr)

For numerical stability the output falls back to the identity when βx>threshold\beta x > \text{threshold}, avoiding overflow in the exponential. Softplus is a smooth, everywhere-differentiable approximation of ReLU, and is useful as the positivity-enforcing transformation in probabilistic models (e.g. predicting variances or scale parameters).

Parameters

betafloat= 1.0
Sharpness parameter β\beta controlling how closely the curve approximates a hard hinge. Larger values approach ReLU. Default: 1.0.
thresholdfloat= 20.0
Above this value of βx\beta x the function falls back to the identity to prevent overflow. Default: 20.0.

Notes

  • Input: (∗)(*) — any shape.
  • Output: (∗)(*) — same shape as input.

Setting beta=1 recovers the standard log-sum-exp formulation. For very large beta the function becomes numerically equivalent to ReLU almost everywhere.

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> m = nn.Softplus()
>>> x = lucid.tensor([-2.0, -1.0, 0.0, 1.0, 2.0])
>>> m(x)
tensor([0.1269, 0.3133, 0.6931, 1.313, 2.127])
>>> # Sharper approximation with beta=5
>>> m_sharp = nn.Softplus(beta=5.0)
>>> x = lucid.randn(3, 64)
>>> out = m_sharp(x)
>>> out.shape
(3, 64)

Used by 1

Constructors

1
dunder

__init__

→None
__init__(beta: float = 1.0, threshold: float = 20.0)

Initialise the Softplus module. See the class docstring for parameter semantics.

Instance methods

2
fn

extra_repr

→str
extra_repr()

Return a string representation of the layer's configuration.

fn

forward

→Tensor
forward(input: Tensor)

Apply the activation function element-wise.

Parameters

inputTensor
Input tensor of arbitrary shape.

Returns

Tensor

Output tensor of the same shape as input.