cross_entropy_loss

opennmt.utils.cross_entropy_loss(logits, labels, label_smoothing=0.0, training=None, weight=None)[source]

Computes the cross entropy loss.

Parameters
  • logits – The unscaled probabilities with shape \([B, V]\).

  • labels – The true labels with shape \([B]\).

  • label_smoothing – The label smoothing value.

  • training – Compute training loss.

  • weight – The weight of each example with shape \([B]\).

Returns

The cumulated loss and the loss normalizer.