class_docstr: Generate new examples by replacing words in examples.
  
  Substitutions must be of the form 'foo -> bar, spam -> eggs'.
class_docstr_tok: ["Generate","new","examples","by","replacing","words","in","examples",".","Substitutions","must","be","of","the","form","'foo","-",">","bar",",","spam","-",">","eggs","'","."]
code: def __init__(
      self, replacements: Optional[dict[str, list[str]]] = None
  ):
      # Populate dictionary with replacement options.
      if replacements is not None:
          assert isinstance(
              replacements, dict
          ), "Replacements must be a dict."
          assert all(
              [isinstance(tgt, list) for tgt in replacements.values()]
          ), "Replacement dict must be str->list[str]"
          self.default_replacements = replacements
      else:
          self.default_replacements = {}
  
file_path: lit/lit_nlp/components/word_replacer.py
imports: from collections.abc import Iterator, Sequence
  import re
  from typing import Optional
  from absl import logging
  from lit_nlp.api import components
  from lit_nlp.api import dataset
  from lit_nlp.api import model
  from lit_nlp.api import types
  from lit_nlp.lib import utils
label_desc: Use image node_id 1 to create a new WordReplacer object from inherited base classes: lit_components with example: obj = WordReplacer(replacements)