Negative log-likelihood
Negative log-likelihood is the negative logarithm of the likelihood a probabilistic model assigns to observed data, commonly used as an objective or loss to minimize.
Optimization Algorithms: AI techniques for design, planning, and control problems
Negative log likelihood is a loss equal to the negative logarithm of the probability assigned to the true label.
- How it is used
- Uses probability assigned to the correct class as a loss for training multiclass neural networks.
- How deep it goes
- Defines NLL and explains its behavior, then demonstrates batch computation but stops short of deriving optimization details.
- Examples
- Demonstrates NLL inside NumPy forward propagation for a neural network trained on the Penguins classification dataset.
- What you can do after
- Apply it via NumPy to compute and average classification loss from logits, probabilities, and true labels.
Reinforcement Learning from Human Feedback
Negative log-likelihood is the negation of a model's log-likelihood, used as a loss for probabilistic predictions.
- How it is used
- Optimizes preference probabilities for reward modeling and DPO, and regularizes preferred completions to retain language-modeling quality.
- How deep it goes
- Derives pairwise Bradley–Terry and DPO NLL objectives, their sigmoid forms, and the DPO gradient; also relates SFT NLL to forward KL.
- Examples
- Uses chosen and rejected completions, scalar reward scores, policy-to-reference likelihood ratios, and a length-normalized winning-completion penalty.
- What you can do after
- Apply it to train Bradley–Terry reward models, optimize DPO preference pairs, and add a winning-completion NLL penalty.
Read how Reinforcement Learning from Human Feedback explains negative log-likelihood →
Deep Learning with PyTorch, Second Edition
A loss function that penalizes low predicted probability assigned to the correct class by taking the negative logarithm of that probability and summing over samples.
- How it is used
- Uses predicted class likelihoods to train a supervised image classifier.
- How deep it goes
- Defines the formula, explains probability sensitivity, gives calculation steps, and demonstrates PyTorch's log-probability convention.
- Examples
- Demonstrates CIFAR bird-versus-airplane classification with nn.LogSoftmax and nn.NLLLoss.
- What you can do after
- Apply it via PyTorch by producing log probabilities and passing them with target class labels to nn.NLLLoss.
Read how Deep Learning with PyTorch, Second Edition explains negative log-likelihood →
Natural Language Processing in Action, Second Edition
Negative log likelihood is the negative of the logarithm of a model-assigned likelihood, commonly minimized as a probabilistic prediction loss.
- How it is used
- Uses NLLLoss to train an RNN and translate prediction scores into communicable confidence estimates.
- How deep it goes
- Explains logarithm inversion and likelihood interpretation, then stops short of a deeper derivation of the loss.
- Examples
- Uses a nationality-prediction model, the name Khalid, ranked log-loss values, and exponentiated likelihoods.
- What you can do after
- Evaluate/understand model confidence by converting log-loss outputs into likelihoods and inspecting ranked predictions.
Read how Natural Language Processing in Action, Second Edition explains negative log-likelihood →
Causal AI
The negative log-likelihood loss function is the negative logarithm of the likelihood and is minimized to estimate parameters.
- How it is used
- Uses likelihood-based estimation as a machine-learning loss optimized for model parameters.
- How deep it goes
- Defines the likelihood transformation and optimization role, then connects it to numerical optimization and regularization.
- Examples
- Uses linear regression, neural networks, and L2 regularization as estimation and optimization examples.
- What you can do after
- Apply it via numerical optimization to estimate parameters when likelihood maximization lacks a closed-form solution.
Machine Learning Algorithms in Depth
A negative log likelihood is a loss equal to the negative logarithm of the likelihood assigned to observed outcomes by a probabilistic model.
- How it is used
- Uses likelihood-based loss to train probabilistic classifiers and neural networks that predict continuous probability densities.
- How deep it goes
- Derives gradients and implements SGD for logistic regression, then constructs constrained Gaussian-mixture loss, stopping short of broader likelihood theory.
- Examples
- Uses binary logistic regression with synthetic two-class data and a Gaussian mixture density network trained on synthetic multivariate data.
- What you can do after
- Builds NLL objectives from scratch, optimizes logistic regression with SGD, and applies NLL in a Keras/TensorFlow mixture density network.
Read how Machine Learning Algorithms in Depth explains negative log-likelihood →
Ensemble Methods for Machine Learning
Negative log-likelihood is the negative logarithm of the likelihood assigned by a probabilistic model to observed data.
- How it is used
- Connects assumed residual distributions with regression losses and their optimization behavior.
- How deep it goes
- Defines the optimization role and compares distribution-linked losses, stopping short of detailed derivations.
- Examples
- Uses Gaussian, Laplacian, and Huber losses for continuous-valued targets, alongside comparisons across target types.
- What you can do after
- Evaluate how distribution assumptions change loss penalties, differentiability, outlier sensitivity, and boosting suitability.
Read how Ensemble Methods for Machine Learning explains negative log-likelihood →
Related concepts
- cross entropy lossequivalent to · Cross-entropy loss measures the expected negative log probability that a predicted distribution assigns to outcomes drawn from a target distribution.
- mean squared errorequivalent to · Mean squared error is the arithmetic mean of the squared differences between corresponding predicted and target numerical values.
- DPO lossused by · The DPO loss is a preference-training objective that optimizes a policy to assign higher relative likelihood to preferred responses than to rejected responses compared with a reference policy.
- NLLLossused by · NLLLoss is a PyTorch loss function that computes negative log-likelihood loss from log-probability outputs and target classes.
- mixture density networkused by · A mixture density network is a neural network that predicts the parameters of a conditional mixture probability distribution, optionally at each sequence step.
- variational lossy autoencodermeasures · A variational lossy autoencoder is an autoencoder variant that intentionally constrains its latent representation so reconstruction preserves selected information rather than every input detail.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.






