(
    aug_toks: List[types.AugTok],
    *,
    num: int | float = 1,
    pos: Optional[str | Set[str]] = None,
)
return new_aug_toks
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.
Randomly substitute words for which synonyms are available
    with a randomly selected synonym,
    up to ``num`` times or with a probability of ``num``.
Randomly substitute words for which synonyms are available with a randomly selected synonym up to num times or with a probability of num .
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
def substitute_word_synonyms ( aug_toks : List [ types . AugTok ] , * , num : int | float = 1 , pos : Optional [ str | Set [ str ] ] = None , ) -> List [ types . AugTok ] : _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