code: def substitute_word_synonyms(
      aug_toks: list[types.AugTok],
      *,
      num: int | float = 1,
      pos: Optional[str | set[str]] = None,
  ) -> list[types.AugTok]:
      """
      Randomly substitute words for which synonyms are available
      with a randomly selected synonym,
      up to ``num`` times or with a probability of ``num``.
  
      Args:
          aug_toks: Sequence of tokens to augment through synonym substitution.
          num: If int, maximum number of words with available synonyms
              to substitute with a randomly selected synonym; if float, probability
              that a given word with synonyms will be substituted.
          pos: Part of speech tag(s) of words to be considered for augmentation.
              If None, all words with synonyms are considered.
  
      Returns:
          New, augmented sequence of tokens.
  
      Note:
          This transform requires :class:`textacy.resources.ConceptNet` to be downloaded
          to work properly, since this is the data source for word synonyms to be substituted.
      """
      _validate_aug_toks(aug_toks)
      pos = utils.to_collection(pos, str, set)
      cand_idxs = [
          idx
          for idx, aug_tok in enumerate(aug_toks)
          if aug_tok.syns and (pos is None or aug_tok.pos in pos)
      ]
      rand_idxs = set(_select_random_candidates(cand_idxs, num))
      if not rand_idxs:
          return aug_toks[:]
  
      new_aug_toks = []
      for idx, aug_tok in enumerate(aug_toks):
          if idx in rand_idxs:
              new_aug_toks.append(
                  types.AugTok(
                      text=random.choice(aug_tok.syns),
                      ws=aug_tok.ws,
                      pos=aug_tok.pos,
                      is_word=aug_tok.is_word,
                      syns=aug_tok.syns,  # TODO: re-fetch syns? use []?
                  )
              )
          else:
              new_aug_toks.append(aug_tok)
      return new_aug_toks
  
file_path: textacy/src/textacy/augmentation/transforms.py
imports: from __future__ import annotations
  import random
  from typing import Optional
  from cytoolz import itertoolz
  from ..None import errors, types, utils
  from .None import utils
label_desc: Use image node_id 1 for calling a global function with example usage: substitute_word_synonyms(aug_toks) and returns: new_aug_toks, aug_toks