The standard log-softmax subtracts the maximum and then the log of the sum of exponentials. For a row with a large margin that sum is , which rounds to 1, so the log-probability of the leading class comes out as exactly 0 and its probability as exactly 1: softmax collapse. Barron et al. (2026) rewrite the computation so that the leading entry is , a small number that floats store well. Implement their log-softmax and softmax for a batch of rows.
fixed_log_softmax(z)
z is a 2-D float array of shape (N, K) with K >= 2; each row is one logit vector.np.argmax): shift so that entry becomes 0, ; compute the margin from the other entries only, ; and return(N, K). Within rounding it must equal the standard log-softmax, but at the argmax it must stay strictly negative as long as is representable (for example about for the row [40, 0, 0], where the standard version returns exactly 0).1000.fixed_softmax(z)
fixed_log_softmax(z), shape (N, K).np.log1p is what keeps from collapsing to 0.