num_gpus=FLAGS.num_gpus,
all_reduce_alg=FLAGS.all_reduce_alg,
tpu_address=FLAGS.tpu)
if FLAGS.mode in ("train", "train_and_predict"):
train_squad(strategy, input_meta_data, run_eagerly=FLAGS.run_eagerly)
if FLAGS.mode in ("predict", "train_and_predict"):
predict_squad(strategy, input_meta_data)
After Change
if "predict" in FLAGS.mode:
predict_squad(strategy, input_meta_data)
if "eval" in FLAGS.mode:
eval_metrics = eval_squad(strategy, input_meta_data)
f1_score = eval_metrics["final_f1"]
logging.info("SQuAD eval F1-score: %f", f1_score)
summary_dir = os.path.join(FLAGS.model_dir, "summaries", "eval")
summary_writer = tf.summary.create_file_writer(summary_dir)
with summary_writer.as_default():
// TODO(lehou): write to the correct step number.
tf.summary.scalar("F1-score", f1_score, step=0)
summary_writer.flush()
// Also write eval_metrics to json file.
squad_lib_sp.write_to_json_files(
eval_metrics, os.path.join(summary_dir, "eval_metrics.json"))