Functions and operators

softmax⁡(z)i=ezi∑jezj\operatorname{softmax}(\mathbf{z})_i = \frac{e^{z_i}}{\sum_j e^{z_j}} Softmax

Turns a vector of scores into probabilities: exponentiate each, then divide by the total.

In ML papers

softmax⁡(z)i=ezi∑jezj\operatorname{softmax}(\mathbf{z})_i = \frac{e^{z_i}}{\sum_j e^{z_j}} maps a vector of real-valued scores (logits) to a probability distribution: every output is positive and they sum to 1, and larger scores get larger shares. It is the last step of a classifier and the heart of attention, where it is applied to each row of the score matrix.

How to type it

LaTeXShows
\operatorname{softmax}(\mathbf{z})softmax⁡(z)\operatorname{softmax}(\mathbf{z})
\mathrm{softmax}(\mathbf{z})softmax(z)\mathrm{softmax}(\mathbf{z})

A worked example

softmax⁡(1,2,3)=(e1,e2,e3)e1+e2+e3≈(0.09,0.24,0.67)\operatorname{softmax}(1, 2, 3) = \frac{(e^1, e^2, e^3)}{e^1 + e^2 + e^3} \approx (0.09, 0.24, 0.67)

Adding the same constant to every score leaves the result unchanged, which is how implementations avoid overflow.

Common confusions

Equations that use it

Related

ex=exp⁡(x)e^{x} = \exp(x)Exponential∑i=1Nxi\sum_{i=1}^{N} x_iSummationsoftmax⁡(z/τ)\operatorname{softmax}(z / \tau)Tauarg⁡max⁡θf(θ)\arg\max_{\theta} f(\theta)Argmax

Decode this example →