NLLLoss

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

Compute the negative likelihood loss.

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='mean'
)[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 ignored value of target.
  • reduce (bool, optional) True to set the reduction to ‘sum’ or ‘mean’.
  • reduction ({'none', 'mean', 'sum', 'valid'}, optional) The reduce method.