import tensorflow as tf

                      if greater than 0 then smooth the labels.
      weight: scale the loss by this factor.
      name: Optional scope/name for op_scope.

  Returns:
      A tensor with the cross entropy loss.
  """
  logits.get_shape().assert_is_compatible_with(labels.get_shape())
  with tf.name_scope(name):
    num_classes = labels.get_shape()[-1].value
    labels = tf.cast(labels, logits.dtype)
    if label_smoothing > 0:
      smooth_positives = 1.0 - label_smoothing
      smooth_negatives = label_smoothing / num_classes
      labels = labels * smooth_positives + smooth_negatives
    cross_entropy = tf.nn.softmax_cross_entropy_with_logits(
        logits=logits, labels=labels, name='xentropy')
    weight = tf.convert_to_tensor(weight, dtype=logits.dtype.base_dtype, name='loss_weight')
    loss = tf.multiply(weight, tf.reduce_mean(cross_entropy), name='value')
    return loss


def l1_l2_regularizer(var, weight_l1=1.0, weight_l2=1.0, name='l1_l2_regularizer'):
  """Define a L2Loss, useful for regularize, i.e. weight decay.

  Args:
      var: tensor to regularize.
      weight_l1: an optional weight to modulate the l1 loss.
      weight_l2: an optional weight to modulate the l2 loss.
      name: Optional scope/name for op_scope.
