liveBook · Manning

Objective function

As explained in LLMs in Production

A loss function is an objective that quantifies discrepancies between a model's predictions and target outputs for optimization during training.

During LLM training, the objective function turns each batch’s prediction quality into a loss signal used to adjust the model’s weights. Repeating prediction and adjustment across epochs improves the model, while monitoring loss helps detect overfitting to training data. section 5.2.1

A practical training loop uses the objective function to:

  • Process tokenized data in batches, obtain predictions, calculate loss, and apply backpropagation. section 5.5
  • Track training behavior alongside techniques such as early stopping, dropout, and learning-rate scheduling; none alone guarantees generalization. section 5.2.1
  • Optimize for broad text understanding rather than merely minimizing loss on the training data. section 5.2.1
Figure 5.2 A simplified version of all the steps necessary to train a language model (large or otherwise) from scratch. You must have data, then define all of the model behavior, and only then proceed to train.
figure

Use the training-pipeline figure to place the objective function after data preparation and model definition, before iterative training. section 5.2.1

How LLMs in Production covers it

How deep it goes
Explains loss within the training loop and links it to epochs, weight updates, and overfitting without deriving its formula.
Examples
Uses a from-scratch language-model pipeline and a GPT-style PyTorch listing as concrete training contexts.
What you can do after
Apply it via a training loop that batches data, obtains predictions and loss, and performs backpropagation.
How it connects
Connects loss to batches, predictions, backpropagation, epochs, overfitting, early stopping, dropout, and learning-rate scheduling.

Also explained in

Compare how 30 books explain objective function →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of LLMs in Production. The section links point to the parts of the book it draws on.