code: def _reverse_substitute_snippet(
      snippet: str,
      index_to_pair: Mapping[int, AbbrevExpansionPair],
      substitution_rate: float,
  ) -> str:
      """Reverse substitutes a snippet, swapping expansions for abbreviations.
  
      For each candidate abbreviation, its abbreviation is sampled using the
      substitution_rate value.
  
      Args:
        snippet: The snippet to abbreviate.
        index_to_pair: A mapping from snippet index to reverse-substitution
          candidate for that index.
        substitution_rate: The rate at which expansions should be substituted for
          abbreviations.
  
      Returns:
        The abbreviated snippet.
      """
      abbreviated_snippet = ""
      for index, (abbrev, expansion) in sorted(
          index_to_pair.items(), reverse=True
      ):
          if np.random.uniform() >= substitution_rate:
              continue
          abbreviated_snippet = (
              abbrev
              + snippet[index + len(expansion) :]
              + abbreviated_snippet
          )
          snippet = snippet[:index]
      abbreviated_snippet = snippet + abbreviated_snippet
      return abbreviated_snippet
  
file_path: datasets/tensorflow_datasets/text/c4_wsrs/c4_wsrs_utils.py
imports: from __future__ import annotations
  import collections
  import dataclasses
  import random
  import re
  from typing import Iterator, Mapping, Sequence, Tuple
  import numpy
label_desc: Use image node_id 5 for calling a global function with example usage: _reverse_substitute_snippet(snippet, index_to_pair, substitution_rate) and returns: abbreviated_snippet