docs: def padded_cross_entropy_loss(logits, labels, smoothing, vocab_size):
    """Calculate cross entropy loss while ignoring padding.
  
    Args:
      logits: Tensor of size [batch_size, length_logits, vocab_size]
      labels: Tensor of size [batch_size, length_labels]
      smoothing: Label smoothing constant, used to determine the on and off values
      vocab_size: int size of the vocabulary
    Returns:
      Returns a float32 tensor with shape
        [batch_size, max(length_logits, length_labels)]
    """
    with tf.name_scope("loss", [logits, labels]):
      logits, labels = _pad_tensors_to_same_length(logits, labels)
  
      # Calculate smoothing cross entropy
      with tf.name_scope("smoothing_cross_entropy", [logits, labels]):
        confidence = 1.0 - smoothing
        low_confidence = (1.0 - confidence) / tf.to_float(vocab_size - 1)
        soft_targets = tf.one_hot(
            tf.cast(labels, tf.int32),
            depth=vocab_size,
            on_value=confidence,
            off_value=low_confidence)
        xentropy = tf.nn.softmax_cross_entropy_with_logits_v2(
            logits=logits, labels=soft_targets)
  
        # Calculate the best (lowest) possible value of cross entropy, and
        # subtract from the cross entropy loss.
        normalizing_constant = -(
            confidence * tf.log(confidence) + tf.to_float(vocab_size - 1) *
            low_confidence * tf.log(low_confidence + 1e-20))
        xentropy -= normalizing_constant
  
      weights = tf.to_float(tf.not_equal(labels, 0))
      return xentropy * weights, weights