code: def _wrap_apply_to_each(
      perturb_fn: Callable, both: bool = False, *args, **kwargs
  ):
      """
      Wraps the perturb function so that it is applied to
      both elements in the (premise, hypothesis) tuple.
      """
  
      def new_fn(pair, *args, **kwargs):
          premise, hypothesis = pair[0], pair[1]
          ret = []
          fn_premise = perturb_fn(premise, *args, **kwargs)
          fn_hypothesis = perturb_fn(hypothesis, *args, **kwargs)
          if type(fn_premise) != list:
              fn_premise = [fn_premise]
          if type(fn_hypothesis) != list:
              fn_hypothesis = [fn_hypothesis]
          ret.extend([(x, str(hypothesis)) for x in fn_premise])
          ret.extend([(str(premise), x) for x in fn_hypothesis])
          if both:
              ret.extend(
                  [
                      (x, x2)
                      for x, x2 in itertools.product(
                          fn_premise, fn_hypothesis
                      )
                  ]
              )
  
          # The perturb function can return empty strings, if no relevant perturbations
          # can be applied. Eg. if the sentence is "This is a good movie", a perturbation
          # which toggles contractions will have no effect.
          return [x for x in ret if x[0] and x[1]]
  
      return new_fn
  
imports: from typing import Optional, Tuple, Iterable, Callable, Union
  import itertools
  import numpy
  from checklist.test_suite import TestSuite
  from checklist.test_types import MFT, INV, DIR, Expect
  from checklist.perturb import Perturb
  from allennlp.confidence_checks.task_checklists.task_suite import TaskSuite
  from allennlp.confidence_checks.task_checklists import utils
  from allennlp.predictors import Predictor
label_desc: Use image node_id 1 for calling a global function with example usage: _wrap_apply_to_each(perturb_fn, both) and returns: new_fn, unknown