code: def add_weights_regularizer(
      variable, loss="L2", weight_decay=0.001, add_to_collection=None
  ):
      """add_weights_regularizer.
  
      Add a weights regularizer to the provided Tensor
  
      Arguments:
          variable: `Variable`. Tensor to add regularization.
          loss: `str`. Regularization mode.
          weight_decay: `float`. Decay to use for regularization.
          add_to_collection: `str`. Add the regularization loss to the
              specified collection. Default: tf.GraphKeys.REGULARIZATION_LOSSES.
  
      Returns:
          `tf.Tensor`. The weight regularizer.
  
      """
      if not add_to_collection:
          add_to_collection = tf.GraphKeys.REGULARIZATION_LOSSES
      if isinstance(loss, str):
          regul = regularizers.get(loss)
          weights_regularizer = regul(variable, weight_decay)
      elif loss and callable(loss):
          weights_regularizer = loss(variable)
      else:
          weights_regularizer = loss
      if add_to_collection:
          tf.add_to_collection(add_to_collection, weights_regularizer)
      return weights_regularizer
  
imports: from __future__ import division, print_function, absolute_import
  import tensorflow.compat.v1
  from ..None import regularizers
label_desc: Use image node_id 1 for calling a global function with example usage: add_weights_regularizer(variable, loss, weight_decay, add_to_collection) and returns: weights_regularizer