code: def get_name_filter(
      patterns: Iterator[Union[Pattern, str]]
  ) -> Callable[[Union[str, Tuple[str, Any, ...]]], bool]:
      r"""Returns a binary function that filters strings (or iterables whose first
      element is a string) according to a bank of excluded patterns. Typically, used
      in conjunction with generators such as `module.named_parameters()`.
  
      Args:
          patterns: A collection of regular expressions or strings that
              define the set of names to be excluded.
  
      Returns:
          A binary function indicating whether or not an item should be filtered.
      """
      names = set()
      _patterns = set()
      for pattern in patterns:
          if isinstance(pattern, str):
              names.add(pattern)
          elif isinstance(pattern, Pattern):
              _patterns.add(pattern)
          else:
              raise TypeError(
                  "Expected `patterns` to contain `str` or `re.Pattern` typed elements, "
                  f"but found {type(pattern)}."
              )
  
      def name_filter(item: Union[str, Tuple[str, Any, ...]]) -> bool:
          name = item if isinstance(item, str) else next(iter(item))
          if name in names:
              return False
  
          for pattern in _patterns:
              if pattern.search(name):
                  return False
  
          return True
  
      return name_filter
  
file_path: botorch/botorch/optim/utils/model_utils.py
imports: from __future__ import annotations
  from re import Pattern
  from typing import Any, Callable, Dict, Iterator, NamedTuple, Optional, Tuple, Union
  from warnings import warn
  import torch
  from botorch.exceptions.warnings import BotorchWarning
  from botorch.models.gpytorch import GPyTorchModel
  from torch import Tensor
  from torch.nn import Module
  from torch.utils.data import DataLoader, TensorDataset
label_desc: Use image node_id 4 for calling a global function with example usage: get_name_filter(patterns) and returns: name_filter, True, False, False