def file_based_convert_examples_record(examples, max_seq_length, tokenizer,
                                       output_file):
  """Convert record json data to tfrecord."""
  dirname = os.path.dirname(output_file)
  if not tf.gfile.Exists(dirname):
    tf.gfile.MakeDirs(dirname)
  writer = tf.python_io.TFRecordWriter(output_file)

  for (ex_index, example) in enumerate(examples):
    if ex_index % 1000 == 0:
      tf.logging.info("DANITER:Writing example %d of %d" %
                      (ex_index, len(examples)))

    input_features = convert_single_example_record(example, max_seq_length,
                                                   tokenizer)

    for input_feature in input_features:
      features = collections.OrderedDict()
      cand_size = 25
      features["context_input_ids"] = create_int_feature(input_feature.text)
      for i in range(len(input_feature.completions)):
        features["comp_input_ids" + str(i)] = create_int_feature(
            input_feature.completions[i])
      for i in range(len(input_feature.completions), cand_size):
        rand_entry = np.random.randint(len(input_feature.completions))
        features["comp_input_ids" + str(i)] = create_int_feature(
            input_feature.completions[rand_entry])

      assert len(features.keys()) == (cand_size + 1)
      tf_example = tf.train.Example(
          features=tf.train.Features(feature=features))
      writer.write(tf_example.SerializeToString())
  writer.close()
Convert record json data to tfrecord.
language/conpono/evals/model_builder.py