{"course":{"slug":"how-llms-work","title":"How a Language Model Actually Works","url":"https://addaly.com/learn/how-llms-work","level":"intermediate","track":"start"},"lesson":{"slug":"the-loss-and-perplexity","title":"What the training objective actually measures","url":"https://addaly.com/learn/how-llms-work/the-loss-and-perplexity","position":41,"of":78,"minutes":8,"answer":"Cross-entropy loss measures how surprised the model is by the true next token, and the entire capability of the system is a side effect of driving that one number down.","keyIdea":"Cross-entropy loss measures how surprised the model is by the true next token, and the entire capability of the system is a side effect of driving that one number down."},"body":{"format":"markdown","text":"## One number, minimised\n\nThe training objective is small enough to write in a line. At every position, the model produces a probability distribution over the vocabulary. Take the probability it assigned to the token that actually came next. Take the negative logarithm. Average over all positions.\n\n```python\nloss = -np.mean(np.log(probs[range(T), true_next_tokens]))\n```\n\nThat is cross-entropy loss, and it is the whole objective of pretraining. Nothing in it mentions truth, helpfulness, reasoning or safety. All of those are downstream consequences of predicting text well.\n\n## Reading the number\n\nThe negative log of a probability. If the model gave the correct token a probability of 1.0, the loss at that position is 0. If 0.5, it is 0.69. If 0.01, it is 4.6.\n\nBecause the logarithm is steep near zero, being *very* wrong is punished hard. A model that assigns 0.001 to the true token takes a loss of 6.9 at that position, which will dominate the average over many confident-and-correct positions. This is why models learn to hedge: spreading a little probability across plausible alternatives is cheap insurance against a catastrophic single position.\n\nTypical values give you a scale. A well-trained current model reaches a loss around 1.6 to 2.0 nats per token on general text. Random guessing over a 128,000-entry vocabulary would be about 11.8. Human-level performance on this task is not well defined, but the remaining gap is small in nats and large in what it buys.\n\n## Perplexity\n\nPerplexity is the exponential of the loss. A loss of 2.0 is a perplexity of 7.4, and the interpretation is intuitive: the model is as uncertain as if it were choosing uniformly among 7.4 equally likely options at each step.\n\nTwo warnings that matter more than the definition.\n\n**Perplexity is not comparable across tokenizers.** A model with a large vocabulary produces fewer tokens for the same text, so its per-token perplexity is measured on different units. Comparing perplexity across model families is meaningless unless you normalise: bits per byte or bits per character does this correctly, and is what careful papers report.\n\n**Perplexity is not comparable across datasets.** A model that memorised your test set will have wonderful perplexity on it. Held-out data from the same distribution is the minimum requirement, and contamination is the constant threat.\n\n## What low loss does and does not imply\n\nDriving this number down produces grammar, factual association, translation, arithmetic to a degree, and the appearance of reasoning, because all of these help predict text written by people who possessed them. That is the remarkable result at the centre of the field, and it was not obvious in advance.\n\nWhat it does not produce is any preference for true statements over plausible ones. The loss rewards assigning high probability to the token that came next in the corpus. Where the corpus is wrong, predicting the wrong thing is exactly correct. Where the model is generating rather than predicting, nothing in this objective distinguishes a true continuation from a plausible one, which is the mechanism the hallucination lesson describes.\n\n## Where you meet it\n\nYou will see loss curves whenever you fine-tune. Three readings worth knowing:\n\n- **Training loss falling, validation loss rising**: overfitting. The model is memorising your examples. Stop earlier, use fewer epochs, or add data.\n- **Both flat from the start**: the learning rate is too low, or the data is not formatted the way the model expects. Check the chat template before you touch hyperparameters.\n- **A sudden spike**: the numerical instability from module two. Roll back and lower the learning rate.\n\nAnd the practical caution: a lower fine-tuning loss does not mean a better model for your purpose. Loss measures agreement with your training examples. If those examples are mediocre, a lower loss means more faithfully mediocre. The number to trust is a held-out evaluation on the task you actually care about."},"check":{"question":"A fine-tune reaches a much lower training loss than a previous run, but users say the model is worse. What is the most likely explanation?","options":[{"text":"The learning rate was too high, producing a low loss through numerical instability.","correct":false,"tempting":"Instability is a real cause of strange training curves, so pointing at the learning rate is a habitual and often useful move."},{"text":"Perplexity and loss diverge at low values, so the loss number is misleading.","correct":false,"tempting":"Perplexity is just the exponential of loss, but the relationship is obscure enough that this sounds like a subtle technical caveat."},{"text":"The loss measures agreement with the training examples, so a lower value can mean the model has more faithfully reproduced examples that were not good.","correct":true},{"text":"The tokenizer changed between runs, making the two loss values incomparable.","correct":false,"tempting":"Loss really is incomparable across tokenizers, which makes this a correct principle applied to a situation where it does not arise."}]},"prev":{"slug":"what-is-in-the-training-data","title":"What is actually in the training data","url":"https://addaly.com/learn/how-llms-work/what-is-in-the-training-data"},"next":{"slug":"how-weights-get-updated","title":"How a number inside the model gets changed","url":"https://addaly.com/learn/how-llms-work/how-weights-get-updated"},"authorship":"Founder and series editor: Dr Mustafa Mun. Written by AI models to a written standard. Exam keys checked blind by a second model: 3,665 of 3,666 agreed. Academic review invited.","review":{"status":"Draft, open for academic review"},"cite":"Addaly (2026) 'What the training objective actually measures', in How a Language Model Actually Works. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/how-llms-work/the-loss-and-perplexity (Accessed: 13 October 2026).","licence":{"name":"CC BY-NC-SA 4.0","url":"https://creativecommons.org/licenses/by-nc-sa/4.0/"},"reader":{"schema":1,"title":"What the training objective actually measures","courseTitle":"How a Language Model Actually Works","module":{"index":5,"slug":"where-the-weights-come-from","title":"Where the weights come from"},"answer":null,"keyIdea":"Cross-entropy loss measures how surprised the model is by the true next token, and the entire capability of the system is a side effect of driving that one number down.","hero":{"kind":"plate","image":null,"alt":null,"caption":null},"blocks":[{"t":"h2","id":"one-number-minimised","runs":[{"text":"One number, minimised"}]},{"t":"p","runs":[{"text":"The training objective is small enough to write in a line. At every position, the model produces a probability distribution over the vocabulary. Take the probability it assigned to the token that actually came next. Take the negative logarithm. Average over all positions."}]},{"t":"code","lang":"python","label":"Python","text":"loss = -np.mean(np.log(probs[range(T), true_next_tokens]))"},{"t":"p","runs":[{"text":"That is cross-entropy loss, and it is the whole objective of pretraining. Nothing in it mentions truth, helpfulness, reasoning or safety. All of those are downstream consequences of predicting text well."}]},{"t":"h2","id":"reading-the-number","runs":[{"text":"Reading the number"}]},{"t":"p","runs":[{"text":"The negative log of a probability. If the model gave the correct token a probability of 1.0, the loss at that position is 0. If 0.5, it is 0.69. If 0.01, it is 4.6."}]},{"t":"p","runs":[{"text":"Because the logarithm is steep near zero, being "},{"text":"very","i":true},{"text":" wrong is punished hard. A model that assigns 0.001 to the true token takes a loss of 6.9 at that position, which will dominate the average over many confident-and-correct positions. This is why models learn to hedge: spreading a little probability across plausible alternatives is cheap insurance against a catastrophic single position."}]},{"t":"p","runs":[{"text":"Typical values give you a scale. A well-trained current model reaches a loss around 1.6 to 2.0 nats per token on general text. Random guessing over a 128,000-entry vocabulary would be about 11.8. Human-level performance on this task is not well defined, but the remaining gap is small in nats and large in what it buys."}]},{"t":"h2","id":"perplexity","runs":[{"text":"Perplexity"}]},{"t":"p","runs":[{"text":"Perplexity is the exponential of the loss. A loss of 2.0 is a perplexity of 7.4, and the interpretation is intuitive: the model is as uncertain as if it were choosing uniformly among 7.4 equally likely options at each step."}]},{"t":"p","runs":[{"text":"Two warnings that matter more than the definition."}]},{"t":"p","runs":[{"text":"Perplexity is not comparable across tokenizers.","b":true},{"text":" A model with a large vocabulary produces fewer tokens for the same text, so its per-token perplexity is measured on different units. Comparing perplexity across model families is meaningless unless you normalise: bits per byte or bits per character does this correctly, and is what careful papers report."}]},{"t":"p","runs":[{"text":"Perplexity is not comparable across datasets.","b":true},{"text":" A model that memorised your test set will have wonderful perplexity on it. Held-out data from the same distribution is the minimum requirement, and contamination is the constant threat."}]},{"t":"h2","id":"what-low-loss-does-and-does-not-imply","runs":[{"text":"What low loss does and does not imply"}]},{"t":"p","runs":[{"text":"Driving this number down produces grammar, factual association, translation, arithmetic to a degree, and the appearance of reasoning, because all of these help predict text written by people who possessed them. That is the remarkable result at the centre of the field, and it was not obvious in advance."}]},{"t":"p","runs":[{"text":"What it does not produce is any preference for true statements over plausible ones. The loss rewards assigning high probability to the token that came next in the corpus. Where the corpus is wrong, predicting the wrong thing is exactly correct. Where the model is generating rather than predicting, nothing in this objective distinguishes a true continuation from a plausible one, which is the mechanism the hallucination lesson describes."}]},{"t":"h2","id":"where-you-meet-it","runs":[{"text":"Where you meet it"}]},{"t":"p","runs":[{"text":"You will see loss curves whenever you fine-tune. Three readings worth knowing:"}]},{"t":"ul","items":[[{"text":"Training loss falling, validation loss rising","b":true},{"text":": overfitting. The model is memorising your examples. Stop earlier, use fewer epochs, or add data."}],[{"text":"Both flat from the start","b":true},{"text":": the learning rate is too low, or the data is not formatted the way the model expects. Check the chat template before you touch hyperparameters."}],[{"text":"A sudden spike","b":true},{"text":": the numerical instability from module two. Roll back and lower the learning rate."}]]},{"t":"p","runs":[{"text":"And the practical caution: a lower fine-tuning loss does not mean a better model for your purpose. Loss measures agreement with your training examples. If those examples are mediocre, a lower loss means more faithfully mediocre. The number to trust is a held-out evaluation on the task you actually care about."}]}],"check":{"question":[{"text":"A fine-tune reaches a much lower training loss than a previous run, but users say the model is worse. What is the most likely explanation?"}],"options":[{"text":[{"text":"The learning rate was too high, producing a low loss through numerical instability."}],"correct":false,"tempting":[{"text":"Instability is a real cause of strange training curves, so pointing at the learning rate is a habitual and often useful move."}]},{"text":[{"text":"Perplexity and loss diverge at low values, so the loss number is misleading."}],"correct":false,"tempting":[{"text":"Perplexity is just the exponential of loss, but the relationship is obscure enough that this sounds like a subtle technical caveat."}]},{"text":[{"text":"The loss measures agreement with the training examples, so a lower value can mean the model has more faithfully reproduced examples that were not good."}],"correct":true,"tempting":null},{"text":[{"text":"The tokenizer changed between runs, making the two loss values incomparable."}],"correct":false,"tempting":[{"text":"Loss really is incomparable across tokenizers, which makes this a correct principle applied to a situation where it does not arise."}]}],"order":[0,1,2,3],"why":null},"prev":{"slug":"what-is-in-the-training-data","title":"What is actually in the training data","minutes":9},"next":{"slug":"how-weights-get-updated","title":"How a number inside the model gets changed","minutes":9}}}