Functions and operators
softmax ( z ) i = e z i ∑ j e z j \operatorname{softmax}(\mathbf{z})_i = \frac{e^{z_i}}{\sum_j e^{z_j}} softmax ( z ) i = ∑ j e z j e z i SoftmaxTurns a vector of scores into probabilities: exponentiate each, then divide by the total.
In ML papers softmax ( z ) i = e z i ∑ j e z j \operatorname{softmax}(\mathbf{z})_i = \frac{e^{z_i}}{\sum_j e^{z_j}} softmax ( z ) i = ∑ j e z j e z i 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 LaTeX Shows \operatorname{softmax}(\mathbf{z})softmax ( z ) \operatorname{softmax}(\mathbf{z}) softmax ( z ) \mathrm{softmax}(\mathbf{z})s o f t m a x ( z ) \mathrm{softmax}(\mathbf{z}) softmax ( z )
A worked example softmax ( 1 , 2 , 3 ) = ( e 1 , e 2 , e 3 ) e 1 + e 2 + e 3 ≈ ( 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) softmax ( 1 , 2 , 3 ) = e 1 + e 2 + e 3 ( e 1 , e 2 , e 3 ) ≈ ( 0.09 , 0.24 , 0.67 ) Adding the same constant to every score leaves the result unchanged, which is how implementations avoid overflow.
Work the math by hand · by the author of this site
Deep Learning Math by Hand
250 problems on gradients, backprop, attention, normalization and optimizers. By Spencer Uresk, who made this site.
See it on Amazon As an Amazon Associate I earn from qualifying purchases.
Common confusions It is a soft version of argmax (Argmax ), not of max: it returns weights over positions. Applied to a matrix, check the axis: attention normalizes each row. Equations that use it Related Decode this example →
Further reading, by other authors
Understanding Deep Learning by Simon J. D. Prince . A modern textbook covering transformers, diffusion models and more.Deep Learning by Ian Goodfellow, Yoshua Bengio, Aaron Courville . The standard reference text, with a chapter on notation and the math background.As an Amazon Associate I earn from qualifying purchases.