Log-Softmax: Definition, Properties, and Applications
Updated 24 October 2026
Log-softmax is the componentwise logarithm of the softmax transformation, producing non-positive values that sum to 0 and exponentiate to a categorical distribution.
It is widely applied in loss functions for classification, including in categorical negative log-likelihood, cross-entropy, and probability computations, due to numerical stability and precision in handling large logit values.
Robotics, natural language processing, and machine learning for optimizing probabilities and improving cross-entropy loss values.
Log-softmax is the componentwise logarithm of the softmax transformation. For a logit vector o∈RD, it is defined by
The resulting coordinates are log probabilities: they are nonpositive and exponentiate to a categorical distribution whose components sum to one. Log-softmax is the standard representation used in categorical negative log-likelihood, cross-entropy, likelihood computation, and many probabilistic neural-network objectives. It is mathematically equivalent to softmax followed by a logarithm, but its direct log-sum-exp formulation is substantially preferable for numerical computation.
1. Definition and probabilistic interpretation
Let o=Wh∈RD be the output of a neural network, where D is the number of classes. Softmax maps unrestricted real-valued scores to the categorical posterior
p(y=k∣x)=softmax(o)k=∑j=1Dexp(oj)exp(ok).
Every component is positive and the components sum to one. Log-softmax is the vector of corresponding logarithms:
ℓk(o)=logsoftmax(o)k=ok−LSE(o),
where
LSE(o)=logj=1∑Dexp(oj).
For a target class c, the categorical negative log-likelihood is
L(o,c)=−ℓc(o)=−oc+logj=1∑Dexp(oj).
This is the single-example softmax cross-entropy. For a dataset, maximum likelihood minimizes
L(θ)=−n∑logpθ(yn∣xn).
Thus softmax is the probability-valued map, log-softmax is the log-probability-valued map, and cross-entropy or negative log-likelihood is the loss formed by negating the log-softmax coordinate associated with the observed class (Brébisson et al., 2015).
The transformation is invariant to common translation:
Consequently, pairwise log-odds boundaries are affine, even though the probabilities and individual log-softmax values are nonlinear normalized functions (Ahmed, 2018).
2. Differential and convex-analytic properties
Writing logsoftmax(o)k=log∑j=1Dexp(oj)exp(ok)=ok−logj=1∑Dexp(oj).5 with inverse temperature logsoftmax(o)k=log∑j=1Dexp(oj)exp(ok)=ok−logj=1∑Dexp(oj).6,
Since o=Wh∈RD0 is convex, softmax is a monotone map. Its Jacobian and the Hessian of the potential are
o=Wh∈RD1
For any o=Wh∈RD2,
o=Wh∈RD3
The quadratic form is o=Wh∈RD4 times a variance under the categorical distribution o=Wh∈RD5.
The log-softmax Jacobian is
o=Wh∈RD6
For the untempered case o=Wh∈RD7,
o=Wh∈RD8
For a fixed class o=Wh∈RD9, D0 is concave in D1 because it is affine minus a convex log-sum-exp function. Its gradient is
D2
The Jacobian of the vector-valued log-softmax map is generally nonsymmetric. Therefore, monotonicity and co-coercivity results proved for the softmax map do not automatically apply to the vector log-softmax map (Gao et al., 2017).
The softmax map is D3-Lipschitz under the Euclidean norm:
D4
It is also D5-co-coercive:
D6
These properties follow from the gradient structure of log-sum-exp and the Baillon–Haddad theorem. Lower inverse temperature produces a smoother map; higher inverse temperature increases sensitivity to logit changes.
The entropy-regularized characterization is
D7
whose unique maximizer is D8. Softmax is therefore the entropy-regularized counterpart of argmax, with temperature D9 controlling the trade-off between concentration and entropy. As p(y=k∣x)=softmax(o)k=∑j=1Dexp(oj)exp(ok).0, the distribution approaches the uniform distribution; as p(y=k∣x)=softmax(o)k=∑j=1Dexp(oj)exp(ok).1, it concentrates on maximal logits, subject to tie behavior.
3. Numerical evaluation
The identity
p(y=k∣x)=softmax(o)k=∑j=1Dexp(oj)exp(ok).2
should be evaluated with a maximum shift. Let
p(y=k∣x)=softmax(o)k=∑j=1Dexp(oj)exp(ok).3
Then
p(y=k∣x)=softmax(o)k=∑j=1Dexp(oj)exp(ok).4
and
p(y=k∣x)=softmax(o)k=∑j=1Dexp(oj)exp(ok).5
All shifted exponent arguments are nonpositive, so exponential overflow is avoided. Underflow of terms far below the maximum is generally harmless because their contribution to the normalization is negligible (Blanchard et al., 2019).
When one shifted term is exactly zero, a more accurate log-sum-exp implementation uses
p(y=k∣x)=softmax(o)k=∑j=1Dexp(oj)exp(ok).6
where p(y=k∣x)=softmax(o)k=∑j=1Dexp(oj)exp(ok).7. The use of log1p preserves small contributions that might be lost when forming p(y=k∣x)=softmax(o)k=∑j=1Dexp(oj)exp(ok).8 explicitly.
A fused log_softmax operation is generally preferable to computing softmax, followed by a logarithm. Explicit exponentiation and normalization can underflow a small probability to zero, producing p(y=k∣x)=softmax(o)k=∑j=1Dexp(oj)exp(ok).9 after the logarithm even when the corresponding log probability is representable. For finite inputs with at least one finite maximum, the shifted formulation avoids exponential overflow.
Relative error is not always an appropriate accuracy measure for log-softmax. The largest log-softmax coordinate may be close to zero, particularly when one class dominates. A small absolute error can then correspond to a large relative error. The final subtraction ℓk(o)=logsoftmax(o)k=ok−LSE(o),0 can also exhibit cancellation for a unique maximal logit. Absolute error is therefore more informative for coordinates near zero.
A recent analysis identifies two additional floating-point effects in common implementations. Softmax Collapse occurs when the winning-class probability rounds to one, causing the computed gradient ℓk(o)=logsoftmax(o)k=ok−LSE(o),1 to round to zero while non-target gradients remain nonzero. Softmax Cancellation occurs in distillation when separately rounded teacher and student probabilities are subtracted, producing a nonzero gradient even when teacher and student logits coincide. The proposed remedies compute small differences through softplus, log1p, and expm1, and enforce the exact zero-sum gradient identity rather than obtaining the target gradient by subtracting one from a rounded probability (Barron et al., 22 Oct 2026).
For ordinary cross-entropy with target distribution ℓk(o)=logsoftmax(o)k=ok−LSE(o),2 and model distribution ℓk(o)=logsoftmax(o)k=ok−LSE(o),3,
ℓk(o)=logsoftmax(o)k=ok−LSE(o),4
For a hard target ℓk(o)=logsoftmax(o)k=ok−LSE(o),5,
ℓk(o)=logsoftmax(o)k=ok−LSE(o),6
In high-confidence regimes, an alternative expression preserves the small target gradient directly:
ℓk(o)=logsoftmax(o)k=ok−LSE(o),7
where
ℓk(o)=logsoftmax(o)k=ok−LSE(o),8
This avoids losing the target gradient when ℓk(o)=logsoftmax(o)k=ok−LSE(o),9 rounds to one.
4. Representational capacity and alternatives
For a linear-logit LLM with hidden representations LSE(o)=logj=1∑Dexp(oj).0 and output embeddings LSE(o)=logj=1∑Dexp(oj).1,
LSE(o)=logj=1∑Dexp(oj).2
The matrix of log probabilities is
LSE(o)=logj=1∑Dexp(oj).3
where
LSE(o)=logj=1∑Dexp(oj).4
The first term has rank at most LSE(o)=logj=1∑Dexp(oj).5, and the second has rank at most one. Therefore,
LSE(o)=logj=1∑Dexp(oj).6
This is the softmax bottleneck: the conditional log-probability matrix generated by a linear-softmax model is confined to a low-dimensional linear space. The limitation concerns log probabilities, not necessarily the ordinary-rank of the probability matrix obtained after exponentiation (Ganea et al., 2019).
The bottleneck can be understood directly from
LSE(o)=logj=1∑Dexp(oj).7
The exponential in softmax is canceled by the logarithm, leaving the original low-rank logits plus one shared normalization direction. If the true log-probability matrix has rank greater than LSE(o)=logj=1∑Dexp(oj).8, exact representation is impossible within the linear-softmax parameterization.
Several alternatives modify the score function or normalization:
Sigsoftmax uses
LSE(o)=logj=1∑Dexp(oj).9
where c0 is the sigmoid. Its log unnormalized score contains
c1
introducing nonlinear structure that can raise the rank of the log-output matrix. It preserves categorical normalization and monotonicity (Kanai et al., 2018).
Learnable monotonic transformations replace logits c2 by c3 before softmax:
c4
The resulting log probabilities are
c5
Piecewise Linear Increasing Functions provide an efficient parameterization of c6. The identity function recovers ordinary softmax, while sigsoftmax is a special case with
c7
These transformations preserve within-context logit ordering while avoiding the linear-logit rank bound (Ganea et al., 2019).
Mixtures of softmaxes combine several softmax distributions. The logarithm of a mixture does not reduce to one low-rank bilinear logit matrix plus a rank-one normalization term, allowing a higher-rank family of log distributions. Mixture-of-sigsoftmax extends this principle with sigsoftmax components (Kanai et al., 2018).
Spherical normalizers replace the exponential by positive functions such as
c8
A quadratic normalizer depends on the score sum c9 and squared norm L(o,c)=−ℓc(o)=−oc+logj=1∑Dexp(oj).0, enabling exact output-weight updates with computational cost L(o,c)=−ℓc(o)=−oc+logj=1∑Dexp(oj).1 rather than L(o,c)=−ℓc(o)=−oc+logj=1∑Dexp(oj).2 under the spherical-loss algorithm. Log-Spherical Softmax uses L(o,c)=−ℓc(o)=−oc+logj=1∑Dexp(oj).3, while Log-Taylor Softmax uses
L(o,c)=−ℓc(o)=−oc+logj=1∑Dexp(oj).4
The latter is strictly positive and requires no L(o,c)=−ℓc(o)=−oc+logj=1∑Dexp(oj).5 (Brébisson et al., 2015).
The empirical behavior is task-dependent. Log-Taylor Softmax outperformed ordinary log-softmax on the reported MNIST and CIFAR-10 experiments, while ordinary log-softmax performed better on CIFAR-100 and language-modeling tasks. On Penn Treebank and One Billion Word, log-softmax had substantially better perplexity and embedding quality. Sigsoftmax and related monotonic transformations improved language-model perplexity on reported Penn Treebank and WikiText-2 experiments, while mixture models achieved further improvements at higher computational cost (Kanai et al., 2018).
5. Temperature, robustness, and generalized log losses
Ordinary log-softmax uses the ordinary exponential and logarithm. A generalized construction replaces them with tempered functions. The tempered logarithm is
L(o,c)=−ℓc(o)=−oc+logj=1∑Dexp(oj).6
with L(o,c)=−ℓc(o)=−oc+logj=1∑Dexp(oj).7 as L(o,c)=−ℓc(o)=−oc+logj=1∑Dexp(oj).8. For L(o,c)=−ℓc(o)=−oc+logj=1∑Dexp(oj).9, it is bounded below:
L(θ)=−n∑logpθ(yn∣xn).0
Its inverse is the tempered exponential
L(θ)=−n∑logpθ(yn∣xn).1
Tempered softmax uses an implicitly determined normalization scalar:
L(θ)=−n∑logpθ(yn∣xn).2
where
L(θ)=−n∑logpθ(yn∣xn).3
At L(θ)=−n∑logpθ(yn∣xn).4, this reduces to ordinary softmax. For L(θ)=−n∑logpθ(yn∣xn).5, the output has heavier negative tails and assigns more probability mass to low-scoring classes.
The bi-tempered logistic loss combines a L(θ)=−n∑logpθ(yn∣xn).6-tempered Bregman divergence with a L(θ)=−n∑logpθ(yn∣xn).7-tempered probability map:
L(θ)=−n∑logpθ(yn∣xn).8
The emphasized robust regime is
L(θ)=−n∑logpθ(yn∣xn).9
The loss temperature logsoftmax(o)k=log∑j=1Dexp(oj)exp(ok)=ok−logj=1∑Dexp(oj).00 bounds the influence of examples assigned very small probability, while logsoftmax(o)k=log∑j=1Dexp(oj)exp(ok)=ok−logj=1∑Dexp(oj).01 produces heavy-tailed probabilities and reduces sensitivity to small-margin label noise. The mismatch makes the last-layer objective generally non-convex. Matched temperatures logsoftmax(o)k=log∑j=1Dexp(oj)exp(ok)=ok−logj=1∑Dexp(oj).02 produce a convex matching loss, and logsoftmax(o)k=log∑j=1Dexp(oj)exp(ok)=ok−logj=1∑Dexp(oj).03 recovers ordinary KL divergence, cross-entropy, and log-softmax (Amid et al., 2019).
For a one-hot target of class logsoftmax(o)k=log∑j=1Dexp(oj)exp(ok)=ok−logj=1∑Dexp(oj).04, the complete bi-tempered loss is
The second, model-dependent term is essential; the loss is not merely a tempered negative log-likelihood. Its logit gradient contains escort-probability factors and reduces to logsoftmax(o)k=log∑j=1Dexp(oj)exp(ok)=ok−logj=1∑Dexp(oj).06 only in the ordinary case.
6. Applications, geometry, and limitations
Classification and class geometry
For linear softmax scores, dominant regions are convex intersections of half-spaces:
Data-free synthesis therefore reduces to solving a linear system of class-parameter differences. Feasibility requires loop-summation constraints: prescribed pairwise normals and offsets must telescope to zero around every closed class loop. Convex separability alone is not sufficient for exact realization by an logsoftmax(o)k=log∑j=1Dexp(oj)exp(ok)=ok−logj=1∑Dexp(oj).09-class linear softmax (Ahmed, 2018).
Game theory and reinforcement learning
In entropy-regularized strategy selection, a softmax policy
This is a logit equilibrium. Convexity of log-sum-exp and co-coercivity of softmax support convergence arguments under the stated anti-monotonicity and fixed-point assumptions. These results concern the probability-valued softmax map, not the vector-valued log-softmax map (Gao et al., 2017).
The softmax itself admits convex lower and concave upper bounds suitable for convex relaxations of neural networks and transformer attention. These bounds can be constructed through exponential-reciprocal or log-sum-exp decompositions (Wei et al., 2023).
Attribution
For a target class logsoftmax(o)k=log∑j=1Dexp(oj)exp(ok)=ok−logj=1∑Dexp(oj).15,
Probability gradients include an additional factor logsoftmax(o)k=log∑j=1Dexp(oj)exp(ok)=ok−logj=1∑Dexp(oj).18 and can vanish when the target probability is close to zero or one. Log-softmax gradients retain the class-competition structure without the low-probability attenuation. For one-hot cross-entropy,
Logits, probabilities, and log-softmax thus provide different attribution semantics: raw logits measure absolute target-score sensitivity, whereas probabilities and log probabilities measure relative class-discriminative sensitivity. Preliminary attribution experiments reported similar probability and log-softmax maps in several settings, but no universal superiority was established (Lerma et al., 2023).
In multinomial-logistic mixture-of-experts models, the same covariates can appear in both the gate and expert regressions. When expert slopes vanish, derivatives of the gating and expert components can become linearly dependent, producing local weak-identifiability and slower parameter-estimation rates. A bounded transformation logsoftmax(o)k=log∑j=1Dexp(oj)exp(ok)=ok−logj=1∑Dexp(oj).22 in the gate can restore derivative independence under the stated conditions (Nguyen et al., 2023).
7. Distinctions, limitations, and implementation principles
Log-softmax should not be conflated with several related objects:
Softmax is a normalized exponential probability map.
Log-softmax is the logarithm of that probability map.
Cross-entropy or negative log-likelihood is a loss formed from target-weighted negative log-softmax values.
Log-odds are pairwise differences of log-softmax coordinates.
Log-sum-exp is the shared normalization potential.
The exponential is not uniquely forced by the requirement that outputs be positive and sum to one. Other positive normalizers can define categorical distributions, including quadratic spherical normalizers and learned monotonic transformations. Nevertheless, ordinary log-softmax remains a strong default because it combines a coherent categorical likelihood, simple gradients, translation invariance, broad software support, and stable log-sum-exp evaluation. Its principal limitations include computational dependence on output dimension, the linear-logit softmax bottleneck, sharp exponential competition, and floating-point failure modes in extreme confidence or distillation regimes.
preferably through a fused operation. It should avoid explicit softmax followed by logarithm, use log1p where a small quantity is added to one, use softplus for expressions such as logsoftmax(o)k=log∑j=1Dexp(oj)exp(ok)=ok−logj=1∑Dexp(oj).24, and use expm1 when differences of nearly equal exponentials are required. In low-precision or high-confidence settings, preserving the zero-sum cross-entropy gradient is as important as preventing overflow.
It explains the probabilistic normalization, translation invariance, gradient structure, convex-analytic properties of softmax, affine pairwise log-odds, the low-rank softmax bottleneck, the construction of verification bounds, and the numerical algorithms required for reliable computation.