Jump to content

Language model loss: Difference between revisions

From Wikibase
No edit summary
Notation: loss is L (via update-page on MediaWiki MCP Server)
Line 10: Line 10:


$$
$$
C(\theta)
L(\theta)
=
=
-\frac{1}{T}\sum_{t=1}^{T}\log_b P_\theta(x_t \mid x_{1:t-1})
-\frac{1}{T}\sum_{t=1}^{T}\log_b P_\theta(x_t \mid x_{1:t-1})

Revision as of 16:18, 11 November 2026

Languages: English · français · Esperanto


The language model loss measures how "surprised" a large language model (LLM) is by the true values of tokens it attempts to predict.

Formal definition

With model parameters $\theta$, the language model loss on training sample $\vec x=(x_1,\cdots,x_T)$:

$$ L(\theta) = -\frac{1}{T}\sum_{t=1}^{T}\log_b P_\theta(x_t \mid x_{1:t-1}) $$

$\vec x=(x_1,\cdots,x_T)$ is a text token sequence of length $T$ (e.g., ('I','am','myself','.')).

Unit

The unit of the language model loss is determined by $b$.

$b$ Unit
2 Bit
e Nat
10 Hartley

Training reports conventionally quote $C_{\text{nat}}$.

Perplexity

Perplexity is the exponential of the loss in nats,

$$ \operatorname{PP}(\theta) = \exp\big(C_{\text{nat}}(\theta)\big), $$

and reads as the effective number of equally likely tokens the model is choosing between. A loss of $1$ nat per token therefore corresponds to a perplexity of $e \approx 2.718$.

Irreducible loss

The loss is bounded below by the conditional entropy of the text itself, since no model predicts next tokens better than the true distribution generates them.

Loss and compute

It is empirically determined

$$ C(F) \prop F^{-\alpha}, \qquad \alpha \approx 0.05. $$

The exponent governs how expensive further improvement is: halving the loss requires roughly $10^{6}$ times more compute, which is why the gap between $2$ nats per token and $1$ nat per token, a perplexity fall from $7.389$ to $2.718$, is very large in practice.[1]