Numerically Stable Softmax & Cross-Entropy is a classic coding problem testing an engineer's mastery over IEEE 754 floating-point limits and numerical stability tricks; naive
softmax(z)i=∑ezjezi triggers floating-point overflow (`inf`) when logits are large (
zi=1000), yielding `NaN` quotients; the numerically safe algorithm exploits translation invariance:
softmax(z)=softmax(z−c); setting
c=max(z) shifts all exponents into
(−∞,0] where the maximum value is
exp(0)=1, guaranteeing no overflow; furthermore, combining it with Log-Sum-Exp prevents underflow when evaluating log-probabilities in Cross-Entropy.