def convert_single_example(example, tokenize_fn):
  """Converts a single `InputExample` into a single `InputFeatures`."""

  if isinstance(example, PaddingInputExample):
    return InputFeatures(
        input_ids=[0] * FLAGS.max_seq_length * 4,
        input_mask=[1] * FLAGS.max_seq_length * 4,
        segment_ids=[0] * FLAGS.max_seq_length * 4,
        label_id=0,
        is_real_example=False)

  input_ids, input_mask, all_seg_ids = [], [], []
  tokens_context = tokenize_fn(example.context)
  for i in range(len(example.qa_list)):
    tokens_qa = tokenize_fn(example.qa_list[i])
    if len(tokens_qa) > FLAGS.max_qa_length:
      tokens_qa = tokens_qa[- FLAGS.max_qa_length:]

    if len(tokens_context) + len(tokens_qa) > FLAGS.max_seq_length - 3:
      tokens = tokens_context[: FLAGS.max_seq_length - 3 - len(tokens_qa)]
    else:
      tokens = tokens_context

    segment_ids = [SEG_ID_A] * len(tokens)

    tokens.append(SEP_ID)
    segment_ids.append(SEG_ID_A)

    tokens.extend(tokens_qa)
    segment_ids.extend([SEG_ID_B] * len(tokens_qa))

    tokens.append(SEP_ID)
    segment_ids.append(SEG_ID_B)

    tokens.append(CLS_ID)
    segment_ids.append(SEG_ID_CLS)

    cur_input_ids = tokens
    cur_input_mask = [0] * len(cur_input_ids)

    if len(cur_input_ids) < FLAGS.max_seq_length:
      delta_len = FLAGS.max_seq_length - len(cur_input_ids)
      cur_input_ids = [0] * delta_len + cur_input_ids
      cur_input_mask = [1] * delta_len + cur_input_mask
      segment_ids = [SEG_ID_PAD] * delta_len + segment_ids

    assert len(cur_input_ids) == FLAGS.max_seq_length
    assert len(cur_input_mask) == FLAGS.max_seq_length
    assert len(segment_ids) == FLAGS.max_seq_length

    input_ids.extend(cur_input_ids)
    input_mask.extend(cur_input_mask)
    all_seg_ids.extend(segment_ids)

  label_id = example.label

  feature = InputFeatures(
      input_ids=input_ids,
      input_mask=input_mask,
      segment_ids=all_seg_ids,
      label_id=label_id)
  return feature
Converts a single `InputExample` into a single `InputFeatures`.
run_race.py