docstr: Generates a new Instance by perturbing the input, tagging the Instance and perturbing the References,
  if should_perturb_references is true. Initializes a random number generator based on instance_id that gets
  passed to perturb and perturb_references.
docstr_tok: ["Generates","a","new","Instance","by","perturbing","the","input",",","tagging","the","Instance","and","perturbing","the","References",",","if","should_perturb_references","is","true",".","Initializes","a","random","number","generator","based","on","instance_id","that","gets","passed","to","perturb","and","perturb_references","."]
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,
      if should_perturb_references is true. Initializes a random number generator based on instance_id that gets
      passed to perturb and perturb_references.
      """
      rng: Random = self.get_rng(instance, seed)
  
      references: List[Reference] = instance.references
      if self.should_perturb_references:
          references = [
              self.perturb_reference(reference, rng)
              for reference in references
          ]
  
      description = replace(self.description, seed=seed)
  
      # Don't modify `id` of `Instance` here.
      # All the perturbed Instances generated from a single Instance should have the same ID.
      return replace(
          instance,
          input=Input(text=self.perturb(instance.input.text, rng)),
          references=references,
          perturbation=description,
      )
  
file_path: H2O/h2o_hf/helm/src/helm/benchmark/augmentations/perturbation.py
imports: from abc import ABC, abstractmethod
  from dataclasses import replace
  from random import Random
  from typing import List, Optional
  from .perturbation_description import PerturbationDescription
  from helm.benchmark.scenarios.scenario import Input, Instance, Reference, Output
  from helm.common.object_spec import ObjectSpec, create_object
label_desc: Use image node_id 3 for calling the Perturbation obj's underlying member method code with example usage: obj.apply(instance, seed) and returns: replace