Accurate Computation of the Log-Sum-Exp and Softmax Functions
Pierre Blanchard, Desmond J. Higham, Nicholas J. Higham

TL;DR
This paper analyzes the numerical stability of various algorithms for computing the log-sum-exp and softmax functions, providing error bounds and practical recommendations for accurate implementation in low precision environments.
Contribution
It offers a detailed rounding error analysis of different evaluation algorithms and compares their accuracy, guiding better implementation choices.
Findings
Shifted formulas are similarly accurate to unshifted ones.
Shifted softmax is generally more accurate than division-free variants.
Numerical experiments confirm the theoretical error bounds.
Abstract
Evaluating the log-sum-exp function or the softmax function is a key step in many modern data science algorithms, notably in inference and classification. Because of the exponentials that these functions contain, the evaluation is prone to overflow and underflow, especially in low precision arithmetic. Software implementations commonly use alternative formulas that avoid overflow and reduce the chance of harmful underflow, employing a shift or another rewriting. Although mathematically equivalent, these variants behave differently in floating-point arithmetic. We give rounding error analyses of different evaluation algorithms and interpret the error bounds using condition numbers for the functions. We conclude, based on the analysis and numerical experiments, that the shifted formulas are of similar accuracy to the unshifted ones and that the shifted softmax formula is typically more…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsNumerical Methods and Algorithms · Gaussian Processes and Bayesian Inference · Probabilistic and Robust Engineering Design
