Functions and operators

LSE⁡(z)=log⁡∑iezi\operatorname{LSE}(\mathbf{z}) = \log \sum_{i} e^{z_i} Log-sum-exp

log Σ exp(zᵢ): a smooth maximum, and the normalizer of a softmax in log space.

In ML papers

LSE⁡(z)=log⁡∑iezi\operatorname{LSE}(\mathbf{z}) = \log \sum_i e^{z_i} is a smooth maximum: it is at least max⁡izi\max_i z_i and at most max⁡izi+log⁡n\max_i z_i + \log n, and close to the max when one entry dominates.

It is the log of the softmax denominator, so log⁡softmax⁡(z)i=zi−LSE⁡(z)\log \operatorname{softmax}(\mathbf{z})_i = z_i - \operatorname{LSE}(\mathbf{z}), and the cross-entropy loss is LSE⁡(z)−zy\operatorname{LSE}(\mathbf{z}) - z_y. Code computes it as m+log⁡∑iezi−mm + \log \sum_i e^{z_i - m} with m=max⁡izim = \max_i z_i, to avoid overflow. Its gradient is the softmax.

How to type it

LaTeXShows
\operatorname{logsumexp}(\mathbf{z})logsumexp⁡(z)\operatorname{logsumexp}(\mathbf{z})
\operatorname{LSE}(\mathbf{z})LSE⁡(z)\operatorname{LSE}(\mathbf{z})
\log \sum_i e^{z_i} written outlog⁡∑iezi\log \sum_i e^{z_i}

A worked example

LSE⁡(1,2,3)=log⁡(e1+e2+e3)≈log⁡30.19≈3.41\operatorname{LSE}(1, 2, 3) = \log(e^1 + e^2 + e^3) \approx \log 30.19 \approx 3.41

Slightly above the max, 33.

Common confusions

Related

softmax⁡(z)i=ezi∑jezj\operatorname{softmax}(\mathbf{z})_i = \frac{e^{z_i}}{\sum_j e^{z_j}}Softmaxlog⁡pθ(x)\log p_\theta(x)Logarithmex=exp⁡(x)e^{x} = \exp(x)Exponentialmax⁡(0,x)\max(0, x)Max and min

Decode this example →