Lably
Skip to content

Softmax function

Smooth approximation of one-hot arg max

  • 13 min read
  • 9 chapters

Related on Lably

Through Tuple, Probability distribution and Logistic function

Definition

The softmax function takes as input a tuple z of K real numbers, and normalizes it into a probability distribution consisting of K probabilities proportional to the exponentials of the input numbers. That is, prior to applying softmax, some tuple components could be negative, or greater than one; and might not sum to 1; but after applying softmax, each component will be in the interval (0,1), and the components will add up to 1, so that they can be interpreted as probabilities. Furthermore, the larger input components will correspond to larger probabilities.

Formally, the standard (unit) softmax function σ:RK→(0,1)K, where ⁠K>1⁠, takes a tuple z=(z1,…,zK)∈RK and computes each component of vector σ(z)∈(0,1)K with

σ(z)i=ezi∑j=1Kezj.

In words, the softmax applies the standard exponential function to each element zi of the input tuple z (consisting of K real numbers), and normalizes these values by dividing by the sum of all these exponentials. The normalization ensures that the sum of the components of the output vector σ(z) is 1. The term "softmax" derives from the amplifying effects of the exponential on any maxima in the input tuple. For example, the standard softmax of (1,2,8) is approximately (0.001,0.002,0.997), which amounts to assigning almost all of the total unit weight in the result to the position of the tuple's maximal element (of 8).

In general, instead of e a different base b > 0 can be used. As above, if b > 1 then larger input components will result in larger output probabilities, and increasing the value of b will create probability distributions that are more concentrated around the positions of the largest input values. Conversely, if 0 < b < 1 then smaller input components will result in larger output probabilities, and decreasing the value of b will create probability distributions that are more concentrated around the positions of the smallest input values. Writing b=eβ or b=e−β (for real β) yields the expressions:

σ(z)i=eβzi∑j=1Keβzj or σ(z)i=e−βzi∑j=1Ke−βzj for i=1,…,K.

A value proportional to the reciprocal of β is sometimes referred to as the temperature: β=1/kT, where k is typically 1 or the Boltzmann constant and T is the temperature. A higher temperature results in a more uniform output distribution (i.e. with higher entropy; it is "more random"), while a lower temperature results in a sharper output distribution, usually with one value dominating.

In some fields, the base is fixed, corresponding to a fixed scale, while in others the parameter β (or T) is varied.

The softmax function is a multiple-variable generalization of the logistic function.

Sign in to keep reading

8 more chapters are free with a Lably account.

More in Computing and communication