class_docstr: Individual fairness perturbation for person names.
class_docstr_tok: ["Individual","fairness","perturbation","for","person","names","."]
docstr: Generates a new Instance by perturbing the input, tagging the Instance and perturbing the References,
  Ensures substituted names are persistent across `Instance` and their `Reference`s.
docstr_tok: ["Generates","a","new","Instance","by","perturbing","the","input",",","tagging","the","Instance","and","perturbing","the","References",",","Ensures","substituted","names","are","persistent","across","`","Instance","`","and","their","`","Reference","`","s","."]
code: def apply(
      self, instance: Instance, seed: Optional[int] = None
  ) -> Instance:
      """
      Generates a new Instance by perturbing the input, tagging the Instance and perturbing the References,
      Ensures substituted names are persistent across `Instance` and their `Reference`s.
      """
      rng: Random = self.get_rng(instance)
  
      # Use these to ensure that the same name replacements happen in both the instance text and the reference texts
      name_substitution_mapping: Dict[str, str] = {}
      skipped_tokens: Set[str] = set()
  
      references: List[Reference] = instance.references
      if self.should_perturb_references:
          references = [
              replace(
                  reference,
                  output=Output(
                      text=self.perturb_with_persistency(
                          reference.output.text,
                          rng,
                          name_substitution_mapping,
                          skipped_tokens,
                      )
                  ),
                  tags=reference.tags,
              )
              for reference in references
          ]
  
      return replace(
          instance,
          input=Input(
              text=self.perturb_with_persistency(
                  instance.input.text,
                  rng,
                  name_substitution_mapping,
                  skipped_tokens,
              )
          ),
          references=references,
          perturbation=self.description,
      )
  
imports: import os
  import re
  from collections import defaultdict
  from dataclasses import dataclass, replace
  from functools import reduce
  from pathlib import Path
  from random import Random
  from typing import Dict, List, Optional, Set
  from helm.benchmark.scenarios.scenario import Input, Instance, Reference, Output
  from helm.common.general import ensure_file_downloaded, ensure_directory_exists, match_case
  from .perturbation_description import PerturbationDescription
  from .perturbation import Perturbation
label_desc: Use image node_id 11 for calling the PersonNamePerturbation obj's underlying member method code with example usage: obj.apply(instance, seed) and returns: replace