import tensorflow as tf

def log_loss_custom(predictions, labels, eps=1e-7, name='log'):
  """Define a log loss.

  Args:
      predictions: 2D tensor or array, [batch_size, num_classes] predictions of the network .
      labels: 2D or array tensor, [batch_size, num_classes]  ground truth labels or target labels.
      eps: a constant to set upper or lower limit for labels, smoothening factor
      name: Optional scope/name for op_scope.

  Returns:
      A tensor with the log loss.
  """
  with tf.name_scope(name):
    predictions = tf.to_float(predictions)
    labels = tf.to_float(labels)
    predictions = tf.clip_by_value(predictions, eps, 1 - eps)
    predictions.get_shape().assert_is_compatible_with(labels.get_shape())
    loss = -tf.reduce_mean(labels * tf.log(predictions))
    return loss


def log_loss_tf(predictions, labels, eps=1e-7, weights=1.0, name='log_loss'):
  """Define a log loss.

  Args:
      predictions: 2D tensor or array, [batch_size, num_classes] predictions of the network .
