Skip to content
masterclass Buddy

PyTorch · Class

nn.NLLLoss

NLLLoss computes negative log likelihood for class-index targets. It expects log-probabilities, usually produced by LogSoftmax, and supports class weights and ignored targets.

Last updated

Syntax

torch.nn.NLLLoss(weight=None, size_average=None, ignore_index=-100, reduce=None, reduction='mean')

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • LogSoftmax
  • CrossEntropyLoss

Source: NLLLoss — PyTorch 2.15 documentation. Checked 2026-11-03.