lm1b/model/model_nodes.py
def attach_training_nodes(loss, hparams=None):
  """
  Attach nodes for training. Work in progress...
  :param loss:
  :param hparams:
  :return:
  """
  trainable_vars = tf.trainable_variables()
  tf.get_collection(tf.GraphKeys.MODEL_VARIABLES, scope="")
  tf.global_variables()
  all_gradients = tf.gradients(loss, trainable_vars)
  lstm_gradients = filter(lambda x: -1 < x.op.name.find("lstm"), all_gradients)
  non_lstm_gradients = set(all_gradients).difference(lstm_gradients)

  lstm_gradients, global_norm = tf.clip_by_global_norm(lstm_gradients, hparams.lstm_clip_grad_norm)
  all_gradients = non_lstm_gradients.union(lstm_gradients)

  optimizer = tf.train.AdagradOptimizer(hparams.learning_rate)
  global_step = tf.Variable(0, name='global_step', trainable=False)
  train_op = optimizer.apply_gradients(zip(all_gradients, trainable_vars), global_step=global_step)
  return {"train_op": train_op, "global_step": global_step}

  Attach nodes for training. Work in progress...
  :param loss:
  :param hparams:
  :return:
  
Attach nodes for training. Work in progress
Attach nodes for training . Work in progress
def attach_training_nodes(loss, hparams=None):
  trainable_vars = tf.trainable_variables()
  tf.get_collection(tf.GraphKeys.MODEL_VARIABLES, scope="")
  tf.global_variables()
  all_gradients = tf.gradients(loss, trainable_vars)
  lstm_gradients = filter(lambda x: -1 < x.op.name.find("lstm"), all_gradients)
  non_lstm_gradients = set(all_gradients).difference(lstm_gradients)
  lstm_gradients, global_norm = tf.clip_by_global_norm(lstm_gradients, hparams.lstm_clip_grad_norm)
  all_gradients = non_lstm_gradients.union(lstm_gradients)
  optimizer = tf.train.AdagradOptimizer(hparams.learning_rate)
  global_step = tf.Variable(0, name='global_step', trainable=False)
  train_op = optimizer.apply_gradients(zip(all_gradients, trainable_vars), global_step=global_step)
  return {"train_op": train_op, "global_step": global_step}
def attach_training_nodes ( loss , hparams = None ) : trainable_vars = tf . trainable_variables ( ) tf . get_collection ( tf . GraphKeys . MODEL_VARIABLES , scope = "" ) tf . global_variables ( ) all_gradients = tf . gradients ( loss , trainable_vars ) lstm_gradients = filter ( lambda x : - 1 < x . op . name . find ( "lstm" ) , all_gradients ) non_lstm_gradients = set ( all_gradients ) . difference ( lstm_gradients ) lstm_gradients , global_norm = tf . clip_by_global_norm ( lstm_gradients , hparams . lstm_clip_grad_norm ) all_gradients = non_lstm_gradients . union ( lstm_gradients ) optimizer = tf . train . AdagradOptimizer ( hparams . learning_rate ) global_step = tf . Variable ( 0 , name = 'global_step' , trainable = False ) train_op = optimizer . apply_gradients ( zip ( all_gradients , trainable_vars ) , global_step = global_step ) return { "train_op" : train_op , "global_step" : global_step }
Attach nodes for training.
Attach nodes for training .
"""
  Attach nodes for training. Work in progress...
  :param loss:
  :param hparams:
  :return:
  """
None
loss
None
hparams
None