code: def reverse_substitution(
      element: tuple[
          str,
          tuple[
              str,
              AbbrevExpansionPair,
              Mapping[int, AbbrevExpansionPair],
          ],
      ],
      substitution_rate: float,
      min_snippet_token_len: int,
  ) -> Iterator[tuple[AbbrevExpansionPair, tuple[str, WSRSFeatures]]]:
      """Conducts reverse substitution.
  
      Yields one WSRSFeatures obj per unique replacement.
  
      Args:
        element: A key-value tuple containing the url as the key, and a 3-tuple as
          the value containing the snippet extracted from the c4 doc, the rarest
          abbreviation-expansion substitution candidate in the snippet, and a
          mapping from snippet index to each substitution candidate.
        substitution_rate: The rate at which expansions should be substituted for
          abbreviations.
        min_snippet_token_len: The minimum number of tokens an abbreviated snippet
          can be composed of.
  
      Yields:
        A key-value tuple in which the key is a tuple containing the rarest
        abbreviation-expansion pair replacement for that snippet, and the value is a
        tuple containing the original key and a WSRSFeatures object holding the
        extracted snippet and its abbreviated form.
      """
      key, (snippet, rarest_pair, index_to_pair) = element
      abbreviated_snippet = snippet
      if index_to_pair:
          abbreviated_snippet = _reverse_substitute_snippet(
              snippet, index_to_pair, substitution_rate
          )
      if len(abbreviated_snippet.split(" ")) < min_snippet_token_len:
          return
      features = WSRSFeatures()
      features.original_snippet = snippet
      features.abbreviated_snippet = abbreviated_snippet
  
      yield rarest_pair, (key, features)
  
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 6 for calling a global function with example usage: reverse_substitution(element, substitution_rate, min_snippet_token_len) without return types