def l1_normalize(x, dim, epsilon=1e-12, name=None):
  """l1 normalizes x.

  Args:
    x: The tensor to normalize.
    dim: The dimension to normalize along.
    epsilon: Lower bound on the norm, used to avoid exploding gradients as the
      norm approaches 0.
    name: Optional name for this op.
  Returns:
    x normalized along dim.
  """
  with tf.name_scope(name, 'l1_normalize', [x]) as scope:
    x = tf.convert_to_tensor(x, name='x')
    x = tf.verify_tensor_all_finite(x, 'Error at input %s' % scope)
    x_norm = tf.maximum(tf.reduce_sum(tf.abs(x), [dim], keep_dims=True),
                        epsilon)
    return tf.div(x, x_norm, name=scope)
def l1_normalize ( x , dim , epsilon = 1e-12 , name = None ) : with tf . name_scope ( name , 'l1_normalize' , [ x ] ) as scope : x = tf . convert_to_tensor ( x , name = 'x' ) x = tf . verify_tensor_all_finite ( x , 'Error at input %s' % scope ) x_norm = tf . maximum ( tf . reduce_sum ( tf . abs ( x ) , [ dim ] , keep_dims = True ) , epsilon ) return tf . div ( x , x_norm , name = scope )
l1 normalizes x.

  Args:
    x: The tensor to normalize.
    dim: The dimension to normalize along.
    epsilon: Lower bound on the norm, used to avoid exploding gradients as the
      norm approaches 0.
    name: Optional name for this op.
  Returns:
    x normalized along dim.