import tensorflow as tf

    if scale < 0.:
      raise ValueError('Setting a scale less than 0 on a regularizer: %g' % scale)
    if scale == 0.:
      return lambda _: None

  def l1(weights, name='l1_regularizer'):
    """Applies L1 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, tf.reduce_sum(tf.abs(weights)), name=name)

  return l1


