Search

Search papers and lessons

Softplus

Level 2 · 8 min read

Softplus is a smooth version of ReLU, ln(1 + e^x), that stays positive everywhere and has a gentle slope instead of a sharp corner at zero.

On this page

  • Colour = topic mix
  • Discrete math
  • Neural network basics
  • Linear algebra
  • Calculus
  • ReadReady to readNot yet

TL;DR

Softplus is the function f(x) = ln(1 + e^x). It takes any real number and returns a positive number, rising smoothly and close to x when x is large and close to 0 when x is very negative. It is a smooth stand-in for ReLU, the bend that outputs zero for negative inputs and the input itself otherwise. Its smoothness means its slope never jumps, which can help when a model needs well-behaved derivatives.

Builds on: Logarithm, Exponential Function, Rectified Linear Unit (ReLU) · Leads to: Activation Function choices in neural networks, and the positive-output parameters of probability models

Where it's used

Neural networks that need a positive output. A variance, a scale or a rate must be greater than zero. A network's last layer can produce any real number, so its output is passed through softplus to make it positive. Many probabilistic models, including some variational autoencoders, use this to keep a standard deviation valid.

Hidden layers that want smooth slopes. Some network designs use softplus as the activation between layers instead of ReLU. Its slope changes gradually, so gradients never jump. Practitioners choose it when a smooth curve matters more than the small speed advantage of ReLU.

Stable probability calculations. In a model that counts events, a rate must stay above zero. Softplus turns an unbounded score into a rate that is positive and changes gently, which keeps the likelihood well-defined.

How it works

Take three inputs and trace them through softplus one at a time. Each step computes e raised to the input, adds 1, and takes the natural logarithm.

  1. Start with the input x = 0. Compute e^0 = 1. Add 1 to get 2. Take the natural logarithm: ln(2) is about 0.693. So softplus(0) = 0.693, which is positive even though the input was zero.
  2. Start with x = 1. Compute e^1, which is about 2.718. Add 1 to get 3.718. Take the logarithm: ln(3.718) is about 1.313. So softplus(1) = 1.313. The output is larger than the input, so the curve climbs above the line y = x.
  3. Start with x = −2. Compute e^(−2), which is about 0.135. Add 1 to get 1.135. Take the logarithm: ln(1.135) is about 0.127. So softplus(−2) = 0.127. The output is small but still positive, where ReLU would output exactly zero.
  4. Look at large inputs. For x = 5, e^5 is about 148.4, so the logarithm of 149.4 is about 5.007. The output is almost the input, which is why softplus behaves like ReLU far from zero.
  5. Put the points together. The curve is flat and small on the left, passes through about 0.693 at zero, and rises almost as a straight line on the right. There is no corner at zero, unlike ReLU.
flowchart LR
  A["Input x"] --> B["Raise e to the power x"]
  B --> C["Add 1"]
  C --> D["Take the natural logarithm"]
  D --> E["Output: positive and smooth"]

The math

Definition: Softplus

The function softplus(x) = ln(1 + e^x), defined for every real number x. Here ln is the natural logarithm and e is about 2.71828.

Step 1 in symbols: the value at zero

softplus(0) = ln(1 + e^0) = ln(1 + 1) = ln(2) ≈ 0.6931.

Step 2 in symbols: the value at one

softplus(1) = ln(1 + e) ≈ ln(3.7183) ≈ 1.3133.

Step 3 in symbols: the value for a negative input

softplus(−2) = ln(1 + e^(−2)) ≈ ln(1.1353) ≈ 0.1269. This is always above zero, since 1 + e^x is always above 1 and its logarithm is therefore positive.

Step 4 in symbols: the large-input limit

For large x, e^x dominates the 1, so ln(1 + e^x) ≈ ln(e^x) = x. This is why softplus approaches the identity line on the right. For very negative x, e^x is almost zero, so softplus(x) ≈ e^x, which approaches zero without touching it.

Step 5 in symbols: the slope

The Derivative of softplus is d/dx softplus(x) = e^x / (1 + e^x). This expression is the sigmoid function of x, which lies between 0 and 1. So the slope is always between 0 and 1, rising smoothly from near 0 on the left to near 1 on the right. ReLU's slope, by contrast, jumps from 0 to 1 at zero.

Worked examples

Example
1. Softplus at zero

Find softplus(0).

  1. Compute e^0. Any number to the power 0 is 1, so e^0 = 1.
  2. Add 1: 1 + 1 = 2.
  3. Take the natural logarithm: ln(2) ≈ 0.6931.

The answer is 0.6931. The output is positive at an input that ReLU would map to 0.

Example
2. Comparing with ReLU across a range

Compare softplus with ReLU at x = −2, 0 and 2.

  1. At x = −2: ReLU gives 0. Softplus gives ln(1 + e^(−2)) ≈ 0.127.
  2. At x = 0: ReLU gives 0. Softplus gives ln(2) ≈ 0.693.
  3. At x = 2: ReLU gives 2. Softplus gives ln(1 + e^2). Since e^2 ≈ 7.389, we get ln(8.389) ≈ 2.127.
  4. The difference at x = 2 is 2.127 minus 2, which is 0.127.
  5. The gap is largest at zero, where softplus is smooth and ReLU has its corner, and it shrinks as x moves away from zero.

The lesson: softplus is a close approximation to ReLU away from zero, and it replaces the corner with a smooth curve.

Example
3. A positive scale for a model

A network outputs the raw score s = −0.5 for the standard deviation of a prediction. Standard deviations must be positive, so the network applies softplus.

  1. Compute e^(−0.5). This is about 0.6065.
  2. Add 1: 1.6065.
  3. Take the natural logarithm: ln(1.6065) ≈ 0.4741.
  4. The standard deviation used by the model is 0.4741. It is positive even though the raw score was negative.
  5. If the raw score changes by a small amount, the standard deviation changes by a smooth amount, which keeps training stable.

Try it: a raw score is s = 0. What standard deviation does softplus give? Answer: ln(2) ≈ 0.6931.

Common mistakes and tradeoffs

It is tempting to think softplus is a different activation from ReLU in kind. In fact it is the same shape with the corner rounded off. Far from zero, the two agree closely; near zero they differ. So the choice is about smoothness, not about a new capability.

It is tempting to think softplus is always better because it is smooth. In fact the zero output of ReLU is useful: it makes units sparse, and computing ReLU is cheaper. Softplus needs an exponential and a logarithm, which cost more to compute.

It is tempting to think a softplus output is a probability. In fact softplus gives a positive number, not a number between 0 and 1. A probability needs the sigmoid, which is the derivative of softplus.

When to use it. Use softplus when a value must be positive and vary smoothly, such as a scale, a variance or a rate, or when the smoothness of the activation matters.

When not to use it. For a deep hidden layer where speed matters most, ReLU is usually the default.

Alternatives. ReLU is cheaper and sparse. Sigmoid squashes to the interval from 0 to 1 and is used for probabilities.

History

Softplus appears in the statistics and machine learning literature as a smooth way to keep a parameter positive. It is named for its resemblance to the plus function, max(0, x), which is ReLU. Its use as a neural activation became common as researchers looked for smooth alternatives to ReLU and for ways to keep scale parameters positive in probabilistic models. It caught on because it solves a common problem with one simple formula.

Recap

  • Softplus is ln(1 + e^x), defined for every real number and always positive.
  • For large inputs it behaves like x; for very negative inputs it is near zero but not zero.
  • Its slope is the sigmoid of x, which changes smoothly from 0 to 1.
  • It is the smooth version of ReLU, used when smoothness or strict positivity matters.
  • Read next: Activation Function for the general role of the bend a neuron applies, and Sigmoid Function for the slope of softplus.

Check yourself

QuestionRecall: what is the definition of softplus?Show answer

Softplus is f(x) = ln(1 + e^x). It is the natural logarithm of 1 plus e raised to the input.

QuestionCompute softplus(0) to four decimal places.Show answer

e^0 = 1, so 1 + e^0 = 2, and ln(2) ≈ 0.6931.

QuestionWhy is softplus always positive, even for very negative inputs?Show answer

Because e^x is always positive, 1 + e^x is always greater than 1. The natural logarithm of any number greater than 1 is positive. So ln(1 + e^x) is positive for every x, even when e^x is tiny.

QuestionA model uses softplus on a raw score to produce a rate. The raw score rises by a small amount. Why is this better than using ReLU for the rate?Show answer

Softplus changes smoothly everywhere, so the rate changes gently with the score and its slope is never discontinuous. ReLU has a corner at zero, where its slope jumps from 0 to 1. For a rate that must stay positive and vary smoothly, softplus gives steadier gradients. ReLU would also output exactly zero for negative scores, and a rate of zero is not allowed in this model.

Sources