def _caption_loss(self, targets, logits):
    per_example_loss = tf.nn.sparse_softmax_cross_entropy_with_logits(labels=targets, logits=logits)
    non_padding = tf.greater(targets, input_utils.PADDING)
    mask = tf.cast(non_padding, tf.float32)
    per_example_loss = (per_example_loss * mask)
    avg_loss = (tf.reduce_sum(per_example_loss) / tf.reduce_sum(mask))
    avg_loss = tf.cond(tf.math.is_nan(avg_loss), (lambda : 0.0), (lambda : avg_loss))
    return avg_loss
def _caption_loss(self, targets, logits):
    per_example_loss = tf.nn.sparse_softmax_cross_entropy_with_logits(labels=targets, logits=logits)
    non_padding = tf.greater(targets, input_utils.PADDING)
    mask = tf.cast(non_padding, tf.float32)
    per_example_loss = (per_example_loss * mask)
    avg_loss = (tf.reduce_sum(per_example_loss) / tf.reduce_sum(mask))
    avg_loss = tf.cond(tf.math.is_nan(avg_loss), (lambda : 0.0), (lambda : avg_loss))
    return avg_loss