(
    aug_toks: List[types.AugTok],
    *,
    num: int | float = 1,
    pos: Optional[str | Set[str]] = None,
)
return new_aug_toks
Randomly delete words,
    up to ``num`` times or with a probability of ``num``.

    Args:
        aug_toks: Sequence of tokens to augment through word deletion.
        num: If int, maximum number of words to delete;
            if float, probability that a given word will be deleted.
        pos: Part of speech tag(s) of words to be considered for augmentation.
            If None, all words are considered.

    Returns:
        New, augmented sequence of tokens.
Randomly delete words,
    up to ``num`` times or with a probability of ``num``.
Randomly delete words up to num times or with a probability of num .
def delete_words(
    aug_toks: List[types.AugTok],
    *,
    num: int | float = 1,
    pos: Optional[str | Set[str]] = None,
) -> List[types.AugTok]:
    """
    Randomly delete words,
    up to ``num`` times or with a probability of ``num``.

    Args:
        aug_toks: Sequence of tokens to augment through word deletion.
        num: If int, maximum number of words to delete;
            if float, probability that a given word will be deleted.
        pos: Part of speech tag(s) of words to be considered for augmentation.
            If None, all words are considered.

    Returns:
        New, augmented sequence of tokens.
    """
    _validate_aug_toks(aug_toks)
    pos = utils.to_collection(pos, str, set)
    # bail out on very short sentences to avoid clobbering meaning
    if len(aug_toks) < 3:
        return aug_toks[:]

    cand_idxs = [
        idx
        for idx, aug_tok in enumerate(aug_toks)
        if aug_tok.is_word and (pos is None or aug_tok.pos in pos) and idx > 0
    ]
    rand_idxs = set(_select_random_candidates(cand_idxs, num))
    if not rand_idxs:
        return aug_toks[:]

    new_aug_toks: List[types.AugTok] = []
    # NOTE: https://github.com/python/mypy/issues/5492
    padded_triplets = itertoolz.sliding_window(
        3, [None] + aug_toks + [None]  # type: ignore
    )
    for idx, (prev_tok, curr_tok, next_tok) in enumerate(padded_triplets):
        if idx in rand_idxs:
            # special case: word then [deleted word] then punctuation
            # give deleted word's whitespace to previous word
            if prev_tok and next_tok and prev_tok.is_word and not next_tok.is_word:
                new_aug_toks[-1] = types.AugTok(
                    text=prev_tok.text,
                    ws=curr_tok.ws,
                    pos=prev_tok.pos,
                    is_word=prev_tok.is_word,
                    syns=prev_tok.syns,
                )
        else:
            new_aug_toks.append(curr_tok)
    return new_aug_toks
def delete_words ( 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 ) # bail out on very short sentences to avoid clobbering meaning if len ( aug_toks ) < 3 : return aug_toks [ : ] cand_idxs = [ idx for idx , aug_tok in enumerate ( aug_toks ) if aug_tok . is_word and ( pos is None or aug_tok . pos in pos ) and idx > 0 ] rand_idxs = set ( _select_random_candidates ( cand_idxs , num ) ) if not rand_idxs : return aug_toks [ : ] new_aug_toks : List [ types . AugTok ] = [ ] # NOTE: https://github.com/python/mypy/issues/5492 padded_triplets = itertoolz . sliding_window ( 3 , [ None ] + aug_toks + [ None ] # type: ignore ) for idx , ( prev_tok , curr_tok , next_tok ) in enumerate ( padded_triplets ) : if idx in rand_idxs : # special case: word then [deleted word] then punctuation # give deleted word's whitespace to previous word if prev_tok and next_tok and prev_tok . is_word and not next_tok . is_word : new_aug_toks [ - 1 ] = types . AugTok ( text = prev_tok . text , ws = curr_tok . ws , pos = prev_tok . pos , is_word = prev_tok . is_word , syns = prev_tok . syns , ) else : new_aug_toks . append ( curr_tok ) return new_aug_toks