def write_predictions(input_path, output_path, spider_examples_json):
  """Writes one-best predictions in Spider-evaluation compatible format."""
  predictions_dicts = _load_predictions_dicts(input_path)
  utterance_to_one_best_sql_map = _utterance_to_one_best_sql_map(
      predictions_dicts)

  examples = _load_json(spider_examples_json)
  with tf.gfile.Open(output_path, 'w') as output_file:
    for example in examples:
      utterance = ' '.join(example['question_toks'])
      db_id = example['db_id']
      if utterance not in utterance_to_one_best_sql_map:
        print('No prediction for utterance: %s' % utterance)
        # Write a line with dummy output.
        output_file.write('SKIP\t%s\n' % db_id)
      else:
        prediction = utterance_to_one_best_sql_map[utterance]
        output_file.write('%s\t%s\n' % (prediction, db_id))
Writes one-best predictions in Spider-evaluation compatible format.
language/xsp/evaluation/convert_preds_for_spider_eval.py