def truncate_next_sent(tokens_a, tokens_b, max_num_tokens, rng):
  """Truncates a pair of sequences to a maximum sequence length."""
  while True:
    total_length = len(tokens_a) + len(tokens_b)
    if total_length <= max_num_tokens:
      break

    assert len(tokens_b) >= 1

    # We want to sometimes truncate from the front and sometimes from the
    # back to add more randomness and avoid biases.
    if rng.random() < 0.5:
      del tokens_b[0]
    else:
      tokens_b.pop()
Truncates a pair of sequences to a maximum sequence length.
language/conpono/cpc/preproc/preprocessing_utils.py