opennmt/models/model.py
def compute_training_loss(self, features, labels, step=None):
        """Computes the training loss for a batch of examples.

        Args:
          features: A nested structure of features ``tf.Tensor``.
          labels: A nested structure of labels ``tf.Tensor``.
          step: The current training step.

        Returns:
          A tuple containing,

          - The loss to optimize.
          - The loss to report.
        """
        outputs, _ = self(features, labels, training=True, step=step)
        loss = self.compute_loss(outputs, labels, training=True)
        if isinstance(loss, tuple):
            train_loss = loss[0] / loss[1]
            report_loss = loss[0] / loss[2] if len(loss) > 2 else train_loss
        else:
            train_loss, report_loss = loss, loss
        train_loss = self.regularize_loss(train_loss, variables=self.trainable_weights)
        return train_loss, report_loss
Computes the training loss for a batch of examples.

        Args:
          features: A nested structure of features ``tf.Tensor``.
          labels: A nested structure of labels ``tf.Tensor``.
          step: The current training step.

        Returns:
          A tuple containing,

          - The loss to optimize.
          - The loss to report.
        
Computes the training loss for a batch of examples.
Computes the training loss for a batch of examples .
def compute_training_loss(self, features, labels, step=None):
        outputs, _ = self(features, labels, training=True, step=step)
        loss = self.compute_loss(outputs, labels, training=True)
        if isinstance(loss, tuple):
            train_loss = loss[0] / loss[1]
            report_loss = loss[0] / loss[2] if len(loss) > 2 else train_loss
        else:
            train_loss, report_loss = loss, loss
        train_loss = self.regularize_loss(train_loss, variables=self.trainable_weights)
        return train_loss, report_loss
def compute_training_loss ( self , features , labels , step = None ) : outputs , _ = self ( features , labels , training = True , step = step ) loss = self . compute_loss ( outputs , labels , training = True ) if isinstance ( loss , tuple ) : train_loss = loss [ 0 ] / loss [ 1 ] report_loss = loss [ 0 ] / loss [ 2 ] if len ( loss ) > 2 else train_loss else : train_loss , report_loss = loss , loss train_loss = self . regularize_loss ( train_loss , variables = self . trainable_weights ) return train_loss , report_loss
Computes the training loss for a batch of examples.
Computes the training loss for a batch of examples .
"""Computes the training loss for a batch of examples.

        Args:
          features: A nested structure of features ``tf.Tensor``.
          labels: A nested structure of labels ``tf.Tensor``.
          step: The current training step.

        Returns:
          A tuple containing,

          - The loss to optimize.
          - The loss to report.
        """
A tuple containing.

The loss to optimize.
The loss to report.
A tuple containing . The loss to optimize . The loss to report .
self
features
A nested structure of features ``tf.Tensor``.
A nested structure of features ` ` tf . Tensor ` ` .
labels
A nested structure of labels ``tf.Tensor``.
A nested structure of labels ` ` tf . Tensor ` ` .
step
The current training step.
The current training step .