def file_based_convert_examples_to_features_dual(examples, label_list,
                                                 max_seq_length, tokenizer,
                                                 output_file):
  """Convert a set of `InputExample`s to a TFRecord file."""

  writer = tf.python_io.TFRecordWriter(output_file)
  num_written = 0

  for (ex_index, example) in enumerate(examples):
    if ex_index % 10000 == 0:
      tf.logging.info("Writing example " + str(ex_index))
    num_written = num_written + 1

    feature = convert_single_example_dual(ex_index, example, max_seq_length,
                                          tokenizer, label_list)

    def create_int_feature(values):
      f = tf.train.Feature(int64_list=tf.train.Int64List(value=list(values)))
      return f

    def create_float_feature(values):
      f = tf.train.Feature(float_list=tf.train.FloatList(value=list(values)))
      return f

    features = collections.OrderedDict()
    p_ids = []
    q_ids = []

    for qp in feature.unique_ids:
      elems = qp.split("-")
      q_id = int(elems[0])
      p_id = int(elems[1])
      p_ids.append(p_id)
      q_ids.append(q_id)
    features["q_ids"] = create_int_feature(q_ids)
    features["cand_nums"] = create_int_feature(p_ids)
    features["input_ids_1"] = create_int_feature(feature.input_ids_1)
    features["input_mask_1"] = create_int_feature(feature.input_mask_1)
    features["segment_ids_1"] = create_int_feature(feature.segment_ids_1)
    features["input_ids_2"] = create_int_feature(feature.input_ids_2)
    features["input_masks_2"] = create_int_feature(feature.input_masks_2)
    features["segment_ids_2"] = create_int_feature(feature.segment_ids_2)
    features["label_ids"] = create_int_feature(feature.label_ids)
    features["scores"] = create_float_feature(feature.scores)

    tf_example = tf.train.Example(features=tf.train.Features(feature=features))
    writer.write(tf_example.SerializeToString())
  print("Wrote " + str(num_written) + " in " + output_file)
Convert a set of `InputExample`s to a TFRecord file.
language/multivec/preprocessing/create_training_data.py