opennmt/models/model.py
def train(self, features, labels, optimizer, loss_scale=None):
        """Computes and applies the gradients for a batch of examples.

        Args:
          features: A nested structure of features ``tf.Tensor``.
          labels: A nested structure of labels ``tf.Tensor``.
          optimizer: The optimizer instance
            (``tf.keras.mixed_precision.LossScaleOptimizer`` is supported).
          loss_scale: An optional loss scaling factor.

        Returns:
          The loss.
        """
        loss, gradients = self.compute_gradients(
            features,
            labels,
            optimizer,
            loss_scale=loss_scale,
        )
        optimizer.apply_gradients(list(zip(gradients, self.trainable_weights)))
        return loss
Computes and applies the gradients for a batch of examples.

        Args:
          features: A nested structure of features ``tf.Tensor``.
          labels: A nested structure of labels ``tf.Tensor``.
          optimizer: The optimizer instance
            (``tf.keras.mixed_precision.LossScaleOptimizer`` is supported).
          loss_scale: An optional loss scaling factor.

        Returns:
          The loss.
        
Computes and applies the gradients for a batch of examples.
Computes and applies the gradients for a batch of examples .
def train(self, features, labels, optimizer, loss_scale=None):
        loss, gradients = self.compute_gradients(
            features,
            labels,
            optimizer,
            loss_scale=loss_scale,
        )
        optimizer.apply_gradients(list(zip(gradients, self.trainable_weights)))
        return loss
def train ( self , features , labels , optimizer , loss_scale = None ) : loss , gradients = self . compute_gradients ( features , labels , optimizer , loss_scale = loss_scale , ) optimizer . apply_gradients ( list ( zip ( gradients , self . trainable_weights ) ) ) return loss
Computes and applies the gradients for a batch of examples.
Computes and applies the gradients for a batch of examples .
"""Computes and applies the gradients for a batch of examples.

        Args:
          features: A nested structure of features ``tf.Tensor``.
          labels: A nested structure of labels ``tf.Tensor``.
          optimizer: The optimizer instance
            (``tf.keras.mixed_precision.LossScaleOptimizer`` is supported).
          loss_scale: An optional loss scaling factor.

        Returns:
          The loss.
        """
None
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 ` ` .
optimizer
The optimizer instance
(``tf.keras.mixed_precision.LossScaleOptimizer`` is supported).
The optimizer instance ( ` ` tf . keras . mixed_precision . LossScaleOptimizer ` ` is supported ) .
loss_scale
An optional loss scaling factor.
An optional loss scaling factor .