Language model loss: Difference between revisions
Align notation with Category:Artificial neural network: loss is the cost function C (as in backpropagation, gradient descent), freeing L (via update-page on MediaWiki MCP Server) |
No edit summary |
||
| Line 1: | Line 1: | ||
[[Category:Machine learning]] | [[Category:Machine learning]] | ||
[[Category:Large language models]] | [[Category:Large language models]] | ||
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)$: | |||
$$ | $$ | ||
C(\theta) | C(\theta) | ||
= | = | ||
-\frac{1}{T}\sum_{t=1}^{T}\ | -\frac{1}{T}\sum_{t=1}^{T}\log_b P_\theta(x_t \mid x_{1:t-1}) | ||
$$ | $$ | ||
<blockquote> | |||
$\vec x=(x_1,\cdots,x_T)$ is a text [[token]] sequence of length $T$ (e.g., <code>('I','am','myself','.')</code>). | |||
</blockquote> | |||
== | === Unit === | ||
The | The unit of the language model loss is determined by $b$. | ||
$$ | {| class="wikitable" | ||
|- | |||
! $b$ | |||
! Unit | |||
|- | |||
| 2 | |||
| Bit | |||
|- | |||
| e | |||
| Nat | |||
|- | |||
| 10 | |||
| Hartley | |||
|} | |||
<blockquote> | |||
Training reports conventionally quote $C_{\text{nat}}$. | Training reports conventionally quote $C_{\text{nat}}$. | ||
</blockquote> | |||
== Perplexity == | == Perplexity == | ||
| Line 33: | Line 51: | ||
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$. | 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 == | == Irreducible loss == | ||
The loss is bounded below by the conditional entropy of the text itself | 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) | C(F) \prop F^{-\alpha}, | ||
\qquad \alpha \approx 0.05. | \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.<ref>{{#cite:Q3141}}</ref> | 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.<ref>{{#cite:Q3141}}</ref> | ||
Revision as of 16:15, 11 November 2026
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)$:
$$ C(\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]