code: def regularizer(name, regularization_fn, name_filter='weights'):
    
    regex = re.compile(name_filter)
    def fn(var_name, variable, phase):
      if phase is pt.Phase.train and regex.search(var_name):
        with tf.name_scope(None, name, [variable]):
          loss = regularization_fn(variable)
        if loss is not None:
          tf.add_to_collection(tf.GraphKeys.REGULARIZATION_LOSSES, loss)
      return variable
    return fn
docs: Wraps a regularizer in a parameter-function.
  
    Args:
      name: The name scope for this regularizer.
      regularization_fn: A function with signature:
        fn(variable) -> loss `Tensor` or `None`.
      name_filter: A regex that will be used to filter variables by name.
  
    Returns:
      A parameter modification function that adds the loss to the
      REGULARIZATION_LOSSES graph key.