(self)
Sets self._train_op, the op to run for training.
Sets self._train_op, the op to run for training.
Sets self . _train_op the op to run for training .
def _add_train_op(self):
    """Sets self._train_op, the op to run for training."""
    # Take gradients of the trainable variables w.r.t. the loss function to minimize
    loss_to_minimize = self._total_loss if self._hps.coverage else self._loss
    tvars = tf.trainable_variables()
    gradients = tf.gradients(loss_to_minimize, tvars, aggregation_method=tf.AggregationMethod.EXPERIMENTAL_TREE)

    # Clip the gradients
    with tf.device("/gpu:0"):
      grads, global_norm = tf.clip_by_global_norm(gradients, self._hps.max_grad_norm)

    # Add a summary
    tf.summary.scalar('global_norm', global_norm)

    # Apply adagrad optimizer
    optimizer = tf.train.AdagradOptimizer(self._hps.lr, initial_accumulator_value=self._hps.adagrad_init_acc)
    with tf.device("/gpu:0"):
      self._train_op = optimizer.apply_gradients(zip(grads, tvars), global_step=self.global_step, name='train_step')
def _add_train_op ( self ) : # Take gradients of the trainable variables w.r.t. the loss function to minimize loss_to_minimize = self . _total_loss if self . _hps . coverage else self . _loss tvars = tf . trainable_variables ( ) gradients = tf . gradients ( loss_to_minimize , tvars , aggregation_method = tf . AggregationMethod . EXPERIMENTAL_TREE ) # Clip the gradients with tf . device ( "/gpu:0" ) : grads , global_norm = tf . clip_by_global_norm ( gradients , self . _hps . max_grad_norm ) # Add a summary tf . summary . scalar ( 'global_norm' , global_norm ) # Apply adagrad optimizer optimizer = tf . train . AdagradOptimizer ( self . _hps . lr , initial_accumulator_value = self . _hps . adagrad_init_acc ) with tf . device ( "/gpu:0" ) : self . _train_op = optimizer . apply_gradients ( zip ( grads , tvars ) , global_step = self . global_step , name = 'train_step' )