code: def apply_regularization(regularizer, weights_list=None):
      """Returns the summed penalty by applying `regularizer` to the `weights_list`.
  
      Adding a regularization penalty over the layer weights and embedding weights
      can help prevent overfitting the training data. Regularization over layer
      biases is less common/useful, but assuming proper data preprocessing/mean
      subtraction, it usually shouldn't hurt much either.
  
      Args:
        regularizer: A function that takes a single `Tensor` argument and returns
          a scalar `Tensor` output.
        weights_list: List of weights `Tensors` or `Variables` to apply
          `regularizer` over. Defaults to the `GraphKeys.WEIGHTS` collection if
          `None`.
  
      Returns:
        A scalar representing the overall regularization penalty.
  
      Raises:
        ValueError: If `regularizer` does not return a scalar output, or if we find
            no weights.
      """
      if not weights_list:
          weights_list = ops.get_collection(ops.GraphKeys.WEIGHTS)
      if not weights_list:
          raise ValueError("No weights to regularize.")
      with ops.name_scope(
          "get_regularization_penalty", values=weights_list
      ) as scope:
          penalties = [regularizer(w) for w in weights_list]
          penalties = [
              p if p is not None else constant_op.constant(0.0)
              for p in penalties
          ]
          for p in penalties:
              if p.get_shape().ndims != 0:
                  raise ValueError(
                      "regularizer must return a scalar Tensor instead of a "
                      "Tensor with rank %d." % p.get_shape().ndims
                  )
  
          summed_penalty = math_ops.add_n(penalties, name=scope)
          ops.add_to_collection(
              ops.GraphKeys.REGULARIZATION_LOSSES, summed_penalty
          )
          return summed_penalty
  
file_path: tensornets/tensornets/contrib_layers/regularizers.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import numbers
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import nn
  from tensorflow.python.ops import standard_ops
  from tensorflow.python.platform import tf_logging
label_desc: Use image node_id 5 for calling a global function with example usage: apply_regularization(regularizer, weights_list) and returns: summed_penalty