import tensorflow as tf

  Returns:
      A tensor with the clipped kappa log loss.
  """
  with tf.name_scope(name):
    num_classes = labels.get_shape()[-1].value
    labels = tf.cast(labels, predictions.dtype)
    if label_smoothing > 0:
      smooth_positives = 1.0 - label_smoothing
      smooth_negatives = label_smoothing / num_classes
      labels = labels * smooth_positives + smooth_negatives
    log_loss_res = log_loss_tf(predictions, labels)
    kappa_loss_res = kappa_loss(
        predictions, labels, y_pow=y_pow, num_ratings=num_classes, batch_size=batch_size)
    return kappa_loss_res + log_scale * tf.clip_by_value(log_loss_res, log_cutoff, 10**3)


def cross_entropy_loss(logits, labels, label_smoothing=0.0, weight=1.0, name='cross_entropy_loss'):
  """Define a cross entropy loss with label smoothing.

  Args:
      predictions: 2D tensor or array, [batch_size, num_classes] predictions of the network .
      labels: 2D tensor or array,[batch_size, num_classes]  ground truth labels or target labels.
      label_smoothing: a float, used to smooth the labels for better generalization
                      if greater than 0 then smooth the labels.
      weight: scale the loss by this factor.
      name: Optional scope/name for op_scope.
