def convert_single_example(ex_index, example, max_seq_length, tokenizer,
                           label_list):
  """Converts a single `InputExample` into one or more `InputFeatures`."""

  label_map = {}
  for (i, label) in enumerate(label_list):
    label_map[label] = i

  tokens_a = tokenizer.tokenize(example.text_a)
  _truncate_seq(tokens_a, FLAGS.max_query_length)

  assert (len(example.text_b_list)) == FLAGS.num_candidates
  tokens_b_list = []
  for text_b in example.text_b_list:
    tokens_b_list.append(tokenizer.tokenize(text_b))
  for tokens_b in tokens_b_list:
    # Modifies `tokens_a` and `tokens_b` in place so that the total
    # length is less than the specified length.
    # Account for [CLS], [SEP], [SEP] with "- 3"
    _truncate_seq_pair(tokens_a, tokens_b, max_seq_length - 3)

  # The convention in BERT is:
  # (a) For sequence pairs:
  #  tokens:   [CLS] is this jack ##son ##ville ? [SEP] no it is not . [SEP]
  #  type_ids: 0     0  0    0    0     0       0 0     1  1  1  1   1 1
  # (b) For single sequences:
  #  tokens:   [CLS] the dog is hairy . [SEP]
  #  type_ids: 0     0   0   0  0     0 0
  #
  # Where "type_ids" are used to indicate whether this is the first
  # sequence or the second sequence. The embedding vectors for `type=0` and
  # `type=1` were learned during pre-training and are added to the wordpiece
  # embedding vector (and position vector). This is not *strictly* necessary
  # since the [SEP] token unambiguously separates the sequences, but it makes
  # it easier for the model to learn the concept of sequences.
  #
  # For classification tasks, the first vector (corresponding to [CLS]) is
  # used as as the "sentence vector". Note that this only makes sense because
  # the entire model is fine-tuned.
  all_segment_ids = []
  all_input_ids = []
  all_input_mask = []
  all_unique_ids = []
  all_label_ids = []
  all_tokens = []
  for cand_index, tokens_b in enumerate(tokens_b_list):
    tokens = []
    segment_ids = []
    tokens.append("[CLS]")
    segment_ids.append(0)
    for token in tokens_a:
      tokens.append(token)
      segment_ids.append(0)
    tokens.append("[SEP]")
    segment_ids.append(0)

    if tokens_b:
      for token in tokens_b:
        tokens.append(token)
        segment_ids.append(1)
      tokens.append("[SEP]")
      segment_ids.append(1)

    input_ids = tokenizer.convert_tokens_to_ids(tokens)

    # The mask has 1 for real tokens and 0 for padding tokens. Only real
    # tokens are attended to.
    input_mask = [1] * len(input_ids)

    # Zero-pad up to the sequence length.
    while len(input_ids) < max_seq_length:
      input_ids.append(0)
      input_mask.append(0)
      segment_ids.append(0)

    assert len(input_ids) == max_seq_length
    assert len(input_mask) == max_seq_length
    assert len(segment_ids) == max_seq_length

    label_id = int(example.labels[cand_index])
    all_input_ids.extend(input_ids)
    all_input_mask.extend(input_mask)
    all_unique_ids.append(example.guid + "-" + example.text_b_guids[cand_index])
    all_label_ids.append(label_id)
    all_segment_ids.extend(segment_ids)
    all_tokens.extend(tokens)
  if ex_index < 5:
    tf.logging.info("*** Example ***")
    tf.logging.info("guid: %s" % (example.guid))
    tf.logging.info(
        "tokens: %s" %
        " ".join([tokenization.printable_text(x) for x in all_tokens]))
    tf.logging.info("input_ids: %s" % " ".join([str(x) for x in all_input_ids]))
    tf.logging.info("input_mask: %s" %
                    " ".join([str(x) for x in all_input_mask]))
    tf.logging.info("segment_ids: %s" %
                    " ".join([str(x) for x in all_segment_ids]))
    tf.logging.info("labels ids: %s" %
                    " ".join([str(x) for x in all_label_ids]))
    tf.logging.info("labels str: %s" %
                    " ".join([str(x) for x in example.labels]))
    tf.logging.info("prior scores: %s" %
                    " ".join([str(x) for x in example.scores]))

  feature = InputFeatures(
      unique_ids=all_unique_ids,
      input_ids=all_input_ids,
      input_masks=all_input_mask,
      segment_ids=all_segment_ids,
      label_ids=all_label_ids,
      scores=example.scores)
  return feature
Converts a single `InputExample` into one or more `InputFeatures`.
language/multivec/preprocessing/create_training_data.py