def l2_regularizer(weight=1.0, scope=None):
 def regularizer(tensor):
  with tf.name_scope(scope, 'L2Regularizer', [tensor]):
   l2_weight = tf.convert_to_tensor(weight, dtype=tensor.dtype.base_dtype, name='weight')
   return tf.multiply(l2_weight, tf.nn.l2_loss(tensor), name='value')
 return regularizer

def l2_regularizer ( weight = 1.0 , scope = None ) : def regularizer ( tensor ) : with tf . name_scope ( scope , 'L2Regularizer' , [ tensor ] ) : l2_weight = tf . convert_to_tensor ( weight , dtype = tensor . dtype . base_dtype , name = 'weight' ) return tf . multiply ( l2_weight , tf . nn . l2_loss ( tensor ) , name = 'value' ) return regularizer
define a l2 regularizer .