|
|
| (7 intermediate revisions by 2 users not shown) |
| Line 1: |
Line 1: |
| [[Category:Machine learning]]
| | [[Category:Large language model]] |
| [[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. |
| A '''language model loss''' is the quantity minimised during training of a [[large language model (LLM)|language model]]: it measures how little probability the model assigns to the tokens that actually occur. For a token sequence $x_1, x_2, \cdots, x_T$ and model parameters $\theta$, the loss is the mean negative log-likelihood of the observed tokens,
| |
|
| |
|
| $$
| | == Formal definition == |
| \mathcal{L}(\theta)
| |
| = | |
| -\frac{1}{T}\sum_{t=1}^{T}\log P_\theta(x_t \mid x_{1:t-1}),
| |
| $$
| |
| | |
| where $P_\theta(x_t \mid x_{1:t-1})$ is the probability the model assigns to token $x_t$ given the tokens that precede it.
| |
| | |
| == Units == | |
| | |
| The logarithm fixes the unit. The natural logarithm gives nats per token, and rescaling gives bits per token,
| |
| | |
| $$
| |
| \begin{cases}
| |
| \mathcal{L}_{\text{nat}}(\theta) = -\frac{1}{T}\sum_{t=1}^{T}\log P_\theta(x_t \mid x_{1:t-1}) \\
| |
| \mathcal{L}_{\text{bit}}(\theta) = \frac{\mathcal{L}_{\text{nat}}(\theta)}{\ln 2}
| |
| \end{cases}
| |
| $$
| |
| | |
| Training reports conventionally quote $\mathcal{L}_{\text{nat}}$.
| |
|
| |
|
| == Perplexity ==
| | With [[model parameters]] $\theta$, the '''language model loss''' on training sample $\vec x=(x_1,\cdots,x_T)$: |
| | |
| Perplexity is the exponential of the loss in nats,
| |
|
| |
|
| $$ | | $$ |
| \operatorname{PP}(\theta) = \exp\big(\mathcal{L}_{\text{nat}}(\theta)\big),
| | L(\theta) |
| $$
| |
| | |
| 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$.
| |
| | |
| == Relation to the pretraining objective ==
| |
| | |
| The loss is the negated, length-normalised form of the conditional log-likelihood that pretraining maximises,
| |
| | |
| $$
| |
| \log P_\theta(x_1, x_2, \cdots, x_T)
| |
| = | | = |
| \sum_{t=1}^{T}\log 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}) |
| =
| |
| -T\,\mathcal{L}(\theta).
| |
| $$ | | $$ |
|
| |
|
| Minimising the loss and maximising the likelihood are the same operation, and [[large language model (LLM)|scaling laws]] are stated in terms of the loss because it is the quantity whose behaviour is measured across model sizes.
| | <blockquote> |
| | $\vec x=(x_1,\cdots,x_T)$ is a text [[token (machine learning)|token]] sequence of length $T$ (e.g., <code>('I','am','myself','.')</code>). |
| | </blockquote> |
|
| |
|
| == Irreducible loss == | | === Unit === |
|
| |
|
| The loss is bounded below by the conditional entropy of the text itself: no model predicts next tokens better than the true distribution generates them. Scaling-law fits write this floor as $L_\infty$ and add reducible terms for the size of the model and for the size of the training set.<ref>{{#cite:Q3141}}</ref> | | The unit of the language model loss is determined by $b$. |
| | |
| == Concrete examples ==
| |
| | |
| For a single predicted token the loss is $-\log P_\theta$, so it depends only on the probability the model gave the token that occurred:
| |
|
| |
|
| {| class="wikitable" | | {| class="wikitable" |
| |+ Loss of a single predicted token
| |
| ! $P_\theta$
| |
| ! $\mathcal{L}_{\text{nat}}$
| |
| ! $\mathcal{L}_{\text{bit}}$
| |
| ! $\operatorname{PP}$
| |
| |- | | |- |
| | $0.9$
| | ! $b$ |
| | $0.105$
| | ! Unit |
| | $0.152$
| |
| | $1.11$
| |
| |- | | |- |
| | $0.5$ | | | 2 |
| | $0.693$
| | | Bit |
| | $1$
| |
| | $2$ | |
| |- | | |- |
| | $10^{-2}$ | | | e |
| | $4.61$ | | | Nat |
| | $6.64$
| |
| | $10^{2}$
| |
| |- | | |- |
| | $10^{-5}$ | | | 10 |
| | $11.5$ | | | Hartley |
| | $16.6$
| |
| | $10^{5}$
| |
| |} | | |} |
|
| |
|
| A model that is uniform over a vocabulary of $10^{5}$ tokens, that is $P_\theta = 10^{-5}$ for every token, therefore sits at $11.5$ nats per token, the no-knowledge baseline against which trained models are compared. Averaging over a sequence mixes such terms: a 2-token sequence predicted at $P_\theta = 0.9$ and then at $P_\theta = 0.5$ has a loss of
| | <blockquote> |
| | Training reports conventionally quote $L_{\text{nat}}$. |
| | </blockquote> |
|
| |
|
| $$
| | == Perplexity == |
| \mathcal{L}
| | |
| =
| | See [[perplexity (LLM)]]. |
| -\frac{1}{2}\left(\log 0.9 + \log 0.5\right)
| |
| \approx 0.399 \text{ nats}
| |
| \approx 0.576 \text{ bits}.
| |
| $$
| |
|
| |
|
| == Scaling of the loss == | | == Loss and training compute budget == |
|
| |
|
| Empirically the loss falls as a power law in training compute $C$,
| | It is empirically determined |
|
| |
|
| $$ | | $$ |
| L(C)=aC^{-\alpha}, | | L(C) \propto C^{-\alpha}, |
| \qquad \alpha \approx 0.05. | | \qquad \alpha \approx 0.05. |
| $$ | | $$ |
| | where $C$ is the [[training compute budget]]. |
| | |
| | As a consequence, halving the loss requires roughly $10^{6}$ times more compute. |
|
| |
|
| 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>
| | <ref>{{#cite:Q3141}}</ref> |
The language model loss measures how "surprised" a large language model (LLM) is by the true values of tokens it attempts to predict.
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 $L_{\text{nat}}$.
Perplexity
See perplexity (LLM).
Loss and training compute budget
It is empirically determined
$$
L(C) \propto C^{-\alpha},
\qquad \alpha \approx 0.05.
$$
where $C$ is the training compute budget.
As a consequence, halving the loss requires roughly $10^{6}$ times more compute.
[1]
- ↑ Kaplan, J., McCandlish, S., Henighan, T., Brown, T. B., Chess, B., Child, R., Gray, S., Radford, A., Wu, J., & Amodei, D. (2020). Scaling Laws for Neural Language Models. https://arxiv.org/abs/2001.08361