def token_replace(token_list, vocab, probs, num_changes):
  """Replace tokens at random one at a time from the vocab."""
  original_len = len(token_list)
  for _ in range(num_changes):
    random_index = random.randint(0, len(token_list) - 1)
    token_list[random_index] = sample_next_token(vocab, probs, "_uniform")
  assert len(token_list) == original_len
  return token_list
Replace tokens at random one at a time from the vocab.
language/bert_extraction/steal_bert_classifier/data_generation/preprocess_util.py