def optimize_log_loss(decoder_tgt, decoder_outputs, weights, hps):
  """Optimize log loss.

  Args:
    decoder_tgt: gold outputs. [batch_size, len, vocab_size]
    decoder_outputs: predictions. [batch_size, len, vocab_size]
    weights: [batch_size, len] Mask.
    hps: hyperparams

  Returns:
    loss: Loss.
    train_op: Tensorflow Op for updating parameters.
  """

  loss = tf.nn.sparse_softmax_cross_entropy_with_logits(
      labels=decoder_tgt,
      logits=decoder_outputs.rnn_output)
  loss = tf.reduce_mean(loss * weights)
  # loss = tf.Print(loss, [loss])

  global_step = tf.train.get_global_step()
  values = [hps.learning_rate,
            hps.learning_rate / 5.,
            hps.learning_rate / 10.,
            hps.learning_rate / 25.,
            hps.learning_rate / 50.]
  boundaries = [hps.lr_schedule,
                int(hps.lr_schedule*1.5),
                hps.lr_schedule*2,
                int(hps.lr_schedule*2.5)]
  learning_rate = tf.train.piecewise_constant(
      global_step, boundaries, values)

  assert hps.trainer == "adam", "Only supporting Adam now."

  trainable_var_list = tf.trainable_variables()
  grads = tf.gradients(loss, trainable_var_list)
  gvs = list(zip(grads, trainable_var_list))

  grads = [g for g, _ in gvs]
  train_op = adam.adam(
      trainable_var_list,
      grads,
      learning_rate,
      partial(adam.warmup_constant),
      hps.total_steps,
      weight_decay=hps.weight_decay,
      max_grad_norm=hps.max_grad_norm,
      bias_l2=True)

  return loss, train_op
Optimize log loss.

  Args:
    decoder_tgt: gold outputs. [batch_size, len, vocab_size]
    decoder_outputs: predictions. [batch_size, len, vocab_size]
    weights: [batch_size, len] Mask.
    hps: hyperparams

  Returns:
    loss: Loss.
    train_op: Tensorflow Op for updating parameters.
  
language/labs/exemplar_decoding/models/common.py