cross_entropy

dragon.vm.torch.nn.functional.cross_entropy(
  input,
  target,
  weight=None,
  size_average=None,
  ignore_index=None,
  reduce=None,
  reduction='mean'
)[source]

Compute the softmax cross entropy with sparse target.

The CrossEntropy function is defined as:

\[\text{CrossEntropy}(p_{t}) = -\log(p_{t}) \]
Parameters:
  • input (dragon.vm.torch.Tensor) – The input tensor.
  • target (dragon.vm.torch.Tensor) – The target tensor.
  • weight (dragon.vm.torch.Tensor, optional) – The weight for each class.
  • size_average (bool, optional) – Whether to average the loss.
  • ignore_index (int, optional) – The label index to ignore.
  • reduce (bool, optional) – Whether to reduce the loss.
  • reduction ({'none', 'mean', 'sum', 'valid'}, optional) – The reduce method.
Returns:

dragon.vm.torch.Tensor – The loss.