NLLLoss

class dragon.vm.torch.nn.NLLLoss(
  weight=None,
  size_average=None,
  ignore_index=None,
  reduce=None,
  reduction='valid'
)[source]

Compute the negative likelihood loss with sparse labels.

The NLL loss function is defined as:

\[\text{NLLLoss}(p_{t}) = -\log(p_{t}) \]

Examples:

m1 = torch.nn.LogSoftmax(dim=1)
m2 = torch.nn.NLLLoss()
loss = m2(m1(torch.randn(2, 2)), torch.tensor([0, 1]))

__init__

NLLLoss.__init__(
  weight=None,
  size_average=None,
  ignore_index=None,
  reduce=None,
  reduction='valid'
)[source]

Create a NLLLoss module.

Parameters:
  • weight (dragon.vm.torch.Tensor, optional) – The weight for each class.
  • size_average (bool, optional) – True to set the reduction to ‘mean’.
  • ignore_index (int, optional) – The label index to ignore.
  • reduce (bool, optional) – True to set the reduction to ‘sum’ or ‘mean’.
  • reduction ({'none', 'mean', 'sum', 'valid'}, optional) – The reduce method.