Skip to main content

What is a loss function?

The AI Glossary

In our classes, we often pause to explain the ideas behind AI and the language used to describe it. These posts grew out of those conversations. They’re for anyone who would like to understand AI better, with no technical background assumed.

A loss function is a rule for assigning a numerical penalty to a model’s output during training. It tells the learning procedure what counts as an error and how much different errors matter. Training then tries to reduce the loss across examples.

Suppose a model predicts waiting time. Predicting 12 days when the observed wait was 10 creates an error of two days. One loss function could use the size of that difference. Another could square it, making large errors count more strongly. Both evaluate the same predictions, but they encourage somewhat different behavior.

For a model estimating categories, the loss often evaluates the probabilities it assigns rather than only whether its final choice was correct. Giving the correct category a very low probability can receive a larger penalty than a more uncertain mistake. For a language model, a common training task rewards assigning higher probability to the next token—the next word or word fragment—in the training text.

Not every learning task has a human-provided correct answer. A model might learn by reconstructing hidden information or using feedback about actions. “Objective function” is a broader term for what an optimization procedure seeks to improve. It may include a loss plus additional penalties or rewards. These terms are related, but they are not interchangeable in every method.

The training loss is also different from the outcome an organization ultimately cares about. A lower language-model loss does not directly establish truthfulness. A lower prediction error does not prove that acting on a prediction benefits people. A system can optimize a convenient measurement while neglecting something important that was never included.

In a clinic, missing a genuinely urgent referral may have different consequences from requesting an unnecessary administrative review. Those consequences should inform the task and its evaluation, but reducing them to numbers requires judgment. The useful discussion starts before choosing an algorithm: what errors matter, whose burden counts and what evidence will show that the resulting service is better?

Sources: Goodfellow, Bengio and Courville — Deep Learning, Chapter 8: Optimization; Ouyang and colleagues — Training Language Models to Follow Instructions with Human Feedback (2022)

Further reading from Harvard Chan: Public Health Perspectives — How Health Care Leaders Can Build Effective, Bias free AI (2022).

To learn more, take a look at the AI in Health Care Certificate of Specialization from the Advanced Learning Academy at Harvard T.H. Chan School of Public Health. You can take an individual course or work toward the full certificate.


I’m a doctor, not a statistician. I teach the AI in Health Care Certificate of Specialization with Dr. Heather Mattie, a statistician and co-director of Harvard Chan’s Health Data Science master’s program. For more on data science and statistics, see Harvard Chan’s Health Data Science resources.

AI is a fast-moving field. This explanation reflects our class discussions and related material at the time of writing. Terminology, capabilities and tools may change.

For suggested additions or corrections, please email me at tpanch@hsph.harvard.edu.

Dr. Trishan Panch
Program Director, AI in Health Care
Harvard T.H. Chan School of Public Health — Advanced Learning Academy

Lead with AI in Health Care

The AI Pragmatist is a monthly newsletter from ALA faculty, with new explainers & essays from the Advanced Learning Academy