AI GLOSSARY · AI CONCEPTS
Loss function
Definition
A loss function assigns a numerical penalty to an outcome under a specified objective. Training often minimizes an aggregate of such penalties, possibly with regularization. A small training loss does not establish good performance on new data.
Also called: loss functions, cost function, objective function, loss function machine learning, cost function machine learning.
In plain language
A model learns by being told how badly it did, and the loss function is the scoring rule that does the telling. Suppose a model predicts house prices. For each house the rule compares the predicted price with the real one and turns the gap into a number. A small total means good predictions and a large total means poor ones. Training then changes the model's internal numbers to push the total down. Optimization aims to reduce the chosen objective, which may differ from the outcome you care about. A rule that barely punishes large mistakes can produce a model that makes them. A low score on training examples also does not prove the model works on new data, so it needs separate testing.
Technical definition
In supervised learning, a loss can compare predictions with target values; other learning settings define penalties for their own objectives. Per-example losses can be summed or averaged into a training objective, sometimes with regularization. Gradient-based optimization can use derivatives, but not every loss is differentiable and not every optimizer requires gradients.
Worked examples in this catalogue
Catalogue examples point at a skill, guide or coding tool listed on this site, with what to run and what you see. An example marked illustrative describes the item from its own documentation; it was not executed for this page. Platform Scores are our assessment under a published method, not a safety guarantee.
Guide · Illustrative, not executed
Prompt Engineering for Agents vs Chat Models
- What you see
- The guide compares prompting an agent with prompting a chat model, and cites Anthropic's advice to have success criteria and a way to test them before improving a prompt.
- Why it exercises the concept
- Defining what counts as wrong before you optimise is the idea behind a loss function. Here a person sets the test, where in training the formula is built into the training code.
Skill by Skill Almanac · Illustrative, not executed
llm-eval-test-sets 57/100 · Provisional, not yet measuredScored · Method v0.2 · How we score
- What you see
- Builds and validates an eval dataset for any LLM feature, with a checker for duplicates, missing graders, imbalance and leakage.
- Why it exercises the concept
- An eval set scores a finished feature on cases you chose. It is a separate measurement from the training loss, and keeping the two apart is the point of the contrast.
Skill by Skill Almanac · Illustrative, not executed
llm-json-output-validator 58/100 · Provisional, not yet measuredScored · Method v0.2 · How we score
- What you see
- Validates LLM replies against a JSON Schema subset and tallies failures by class and field.
- Why it exercises the concept
- It turns 'wrong' into a count you can track, a task-level counterpart to a loss: a defined rule for what an error is.
How it shows up when you use agents
A loss function appears when you or an agent define an optimization or training task. The model you use was trained against a loss chosen by its builders, which fixed what it was scored on during training. Language models are trained with their own loss (see Large language model and RLHF).
What this means in practice:
- A training objective is not a quality guarantee. A fluent answer can still be wrong; training loss alone does not establish factual accuracy. The safer habit is to give the agent a way to check its work, such as tests, instead of trusting its tone.
- You still need your own definition of wrong. Before you change a prompt or a skill, decide what a failure looks like and count it. The evaluation step is yours; the training loss is not.
- Training loss is not a report card. A model can score well on its training examples and still do badly on new ones. See Overfitting.
If you are tuning an agent setup, the next action is to write down three failure cases and check them after each change.
Worked example (illustrative)
For two chosen prediction errors, 1 and 3, mean absolute error is (1+3)/2=2, while mean squared error is (1²+3²)/2=5. The sum of squared errors would instead be 10. These calculated penalties use the same errors but different reductions; they are not interchangeable scores or evidence of a useful deployed model.
Common confusions
- Loss function versus evaluation metric. The loss is the number training pushes down. Metrics such as accuracy or a test pass rate are used to judge a model afterwards, and they can disagree with the loss.
- Loss function versus cost function. Sources differ on whether the two terms mean the same thing, so check how the one you are reading defines each.
- Loss versus error in your task. A model's training loss does not tell you whether it will edit your repository correctly. Tests on your own work do.
- Loss function versus backpropagation. The loss measures how wrong a prediction is; backpropagation computes local derivatives that a gradient-based optimizer can use. A finite update need not reduce the loss. See Backpropagation.
Related terms
Show all 22 related terms
Terms that mention Loss function
More in AI concepts
Sources
- What is a loss function?, IBM (accessed 2026-11-24)
- Linear regression: Loss, Google for Developers (accessed 2026-11-24)
- What is backpropagation?, IBM (accessed 2026-11-24)
Definitions are written by Skill Almanac from these sources and were checked against them on 2026-11-24. Wikipedia is never the only source.
Review record
Last verified
Drafted by Claude (original draft) and Codex (automated revisions); sources and example targets checked by Independent automated source review (OpenAI Codex); not human peer review on 2026-11-24. Last verified .
Change log (5)
- : Independent automated factual/example review completed. Cached US query estimate aligned to receipt; no traffic promise. Final technical gate recorded separately; publication disabled. Relevant topic demand only; definition intent unconfirmed.
- : First version.
- : Verifier pass: applied verifier corrections to unsourced or overstated claims.
- : Learning-method scope and counterexample corrections; independent exact-version review pending.
- : Automated review completed; approved for the staged public release. Search indexing is controlled by the release configuration.