This free softplus activation function calculator evaluates softplus(x) = ln(1 + ex), its sigmoid derivative and ReLU for any input, with adjustable sharpness and a live graph.
softplus, its derivative and ReLU for each x
| x | softplus(x) | derivative | ReLU(x) |
|---|
What is the softplus activation function?
The softplus activation function is a smooth version of ReLU: \( \mathrm{softplus}(x) = \ln(1 + e^x) \). For large positive x it is almost exactly x, for large negative x it is almost exactly 0, and in between it curves smoothly instead of having ReLU’s sharp corner at 0. Its output is always positive, which makes it the standard way to force a network output to be greater than zero.
Because the softplus activation function is differentiable everywhere, it is a natural choice wherever a smooth, positive output is needed. The calculator above evaluates softplus, its derivative and ReLU for any input, with an adjustable sharpness \( \beta \), and draws all three.
Softplus activation function formula and derivative
With the sharpness parameter used by PyTorch’s nn.Softplus:
\[ \mathrm{softplus}_\beta(x) = \frac{1}{\beta} \ln\left(1 + e^{\beta x}\right), \qquad \frac{d}{dx}\,\mathrm{softplus}_\beta(x) = \sigma(\beta x) = \frac{1}{1 + e^{-\beta x}} \]
The derivative of softplus is exactly the sigmoid function. That is the key fact: the slope is always between 0 and 1 and never exactly 0, so a softplus unit can always pass some gradient back during backpropagation. Larger \( \beta \) makes the curve hug ReLU more tightly; as \( \beta \to \infty \), softplus becomes ReLU.
A few values with \( \beta = 1 \):
- \( \mathrm{softplus}(0) = \ln 2 \approx 0.6931 \), where ReLU gives 0.
- \( \mathrm{softplus}(2) \approx 2.1269 \), close to ReLU’s 2.
- \( \mathrm{softplus}(-2) \approx 0.1269 \), small but positive, where ReLU gives exactly 0.
Softplus activation function vs ReLU
| ReLU | Softplus | |
|---|---|---|
| Formula | \( \max(0, x) \) | \( \ln(1 + e^x) \) |
| Output range | \( [0, \infty) \) | \( (0, \infty) \), never exactly 0 |
| Smooth at 0 | No (a kink) | Yes, differentiable everywhere |
| Gradient for x < 0 | 0, so units can “die” | Small but positive |
| Cost | Very cheap | Needs exp and log |
| Typical use | Hidden layers | Outputs that must be positive |
In practice ReLU and its variants such as leaky ReLU remain the default for hidden layers, because they are cheaper and train well. Softplus wins where smoothness or strict positivity matters.
Where the softplus activation function is used
- Positive outputs. When a network predicts a standard deviation, a variance, a rate or a price, softplus keeps the value above zero while staying smooth.
- Probabilistic models. Variational autoencoders and models that output Gaussian or Poisson parameters often pass the scale through softplus.
- Inside other activations. The Mish activation is \( x \tanh(\mathrm{softplus}(x)) \), so softplus is a building block of newer smooth functions like Swish and GELU.
- A smooth hinge. \( \ln(1 + e^{-z}) \), softplus of a negated margin, is exactly the logistic loss, a smooth relative of the hinge loss.
Compare it with other smooth curves in our guide to activation functions, or with ELU, which is smooth on the negative side but allows negative outputs.
The softplus activation function in PyTorch and Keras
Both major frameworks ship the softplus activation function, so you rarely need to write it yourself:
# PyTorch
import torch.nn as nn
scale_head = nn.Sequential(nn.Linear(64, 1), nn.Softplus(beta=1.0, threshold=20.0))
# Keras / TensorFlow
from tensorflow import keras
scale_head = keras.layers.Dense(1, activation="softplus")
A typical pattern is a final layer that predicts a standard deviation: the linear layer can output any real number, and softplus maps it to a positive scale. Many models also add a small constant such as \( 10^{-6} \) afterwards, so the scale can never collapse to exactly zero during training.
Computing softplus without overflow
Coded naively, \( \ln(1 + e^x) \) overflows for large x, because \( e^{1000} \) is infinite in floating point. The stable form, used by this calculator, is:
\[ \mathrm{softplus}(x) = \max(x, 0) + \ln\left(1 + e^{-|x|}\right) \]
PyTorch goes further with a threshold argument (default 20): above it, it simply returns x, since the difference is far below floating-point precision. NumPy users can call np.logaddexp(0, x), which computes \( \ln(e^0 + e^x) \) safely. More detail is in the softplus article on Wikipedia.
Frequently asked questions
What is the derivative of softplus? It is the sigmoid function: \( \frac{d}{dx}\ln(1 + e^x) = \frac{1}{1 + e^{-x}} \).
What is softplus(0)? \( \ln 2 \approx 0.693 \) when \( \beta = 1 \), or \( \ln 2 / \beta \) in general.
Is softplus better than ReLU? Not in general. It is smoother and never has a zero gradient, but it is slower to compute, and ReLU usually trains just as well in hidden layers. Use softplus where a positive, smooth output is required.
Can softplus output a negative number? No. Its output is always strictly greater than 0.
Related: Mish Activation Function: Formula, Derivative, Calculator