def pick_answer_from_nbest(nbest, result):
  """Picks from nbest uniformly at random, or return s."""
  # If no answer can be picked, default to a null span.
  answer = [
      RawPrediction(
          start_index=0,
          end_index=0,
          answer_type_index=AnswerType.UNKNOWN,
          start_logit=0,
          end_logit=0,
          answer_type_logit=0)
  ]

  if FLAGS.sample_nbest_list > 0:
    # Pick n predicted answers from the nbest list uniformly at random.
    candidate_answers = [t for t in nbest if t.start_index > 0]
    indices = list(range(len(candidate_answers)))
    np.random.shuffle(indices)
    if candidate_answers:
      answer = [candidate_answers[i] for i in indices[:FLAGS.sample_nbest_list]]
  else:
    # When not sampling an answer, we assume that this is being used
    # for roundtrip filtering, so we only output an extractive answer
    # if it matches the input extractive answer.
    t = nbest[0]
    if (result["start_positions"] == t.start_index and
        result["end_positions"] == t.end_index):
      answer = [t]

  return answer
Picks from nbest uniformly at random, or return s.
language/capwap/synthetic/generate_answers.py