import tensorflow as tf

    ValueError: If scale is negative or if scale is not a float.
  """
  if isinstance(scale, numbers.Integral):
    raise ValueError('scale cannot be an integer: %s' % (scale,))
  if isinstance(scale, numbers.Real):
    if scale < 0.:
      raise ValueError('Setting a scale less than 0 on a regularizer: %g.' % scale)
    if scale == 0.:
      return lambda _: None

  def l2(weights, name='l2_regularizer'):
    """Applies l2 regularization to weights."""
    with tf.name_scope(name):
      my_scale = tf.convert_to_tensor(scale, dtype=weights.dtype.base_dtype, name='scale')
      return tf.multiply(my_scale, nn.l2_loss(weights), name=name)

  return l2


def discretized_mix_logistic_loss(inputs,
                                  predictions,
                                  sum_all=True,
                                  name='disretized_mix_logistic_loss'):
  """log-likelihood for mixture of discretized logistics, assumes the data has
  been rescaled to.

