def _compute_loss(logits, decode_steps, target_len, weights, output_vocab_size,
                  model_config):
  """Computes loss given batch of model outputs and labels."""
  logit_target_ids = decode_utils.get_extended_indices(decode_steps,
                                                       output_vocab_size,
                                                       model_config)
  batch_loss = loss.sequence_loss(
      logits=logits,
      targets=logit_target_ids,
      sequence_length=target_len,
      weights=weights)

  # Calculate the average log perplexity.
  return tf.reduce_sum(batch_loss.losses) / batch_loss.total_steps
Computes loss given batch of model outputs and labels.
language/xsp/model/model_builder.py