def METHOD_NAME(target_tokens):
    pad = self.tgt_dict.pad()
    bos = self.tgt_dict.bos()
    eos = self.tgt_dict.eos()
    unk = self.tgt_dict.unk()
    target_masks = (
        target_tokens.ne(pad) & target_tokens.ne(bos) & target_tokens.ne(eos)
    )
    target_score = target_tokens.clone().float().uniform_()
    target_score.masked_fill_(~target_masks, 2.0)
    target_length = target_masks.sum(1).float()
    target_length = target_length * target_length.clone().uniform_()
    target_length = target_length + 1  # make sure to mask at least one token.
    _, target_rank = target_score.sort(1)
    target_cutoff = new_arange(target_rank) < target_length[:, None].long()
    prev_target_tokens = target_tokens.masked_fill(
        target_cutoff.scatter(1, target_rank, target_cutoff), unk
    )
    return prev_target_tokens