def sequence_accuracy(labels, outputs):
  """Compute the sequence-level accuracy.

  A sequence is only considered correct if all of its entries were predicted
  correctly.

  Args:
    labels: ground-truth labels, shape=(batch, packed_seq_length)
    outputs: predicted tokens, shape=(batch, seq_length)
  Returns:
    Two ops, one for getting the current average accuracy and another for
    updating the running average estimate.
  """
  # A sequence is correct if all of the non-padded entries are correct
  all_correct = tf.reduce_all(
      tf.logical_or(tf.equal(labels, outputs), tf.equal(labels, 0)), axis=-1
  )
  return tf.metrics.mean(all_correct)
Compute the sequence-level accuracy.

  A sequence is only considered correct if all of its entries were predicted
  correctly.

  Args:
    labels: ground-truth labels, shape=(batch, packed_seq_length)
    outputs: predicted tokens, shape=(batch, seq_length)
  Returns:
    Two ops, one for getting the current average accuracy and another for
    updating the running average estimate.