def write_spans(caption_file, question_file, output_file, vocab, params):
  """Write spans to disk using RC model.

  Args:
    caption_file: Path to caption predictions.
    question_file: Path to question.
    output_file: Path to write spans selected by the QA model.
    vocab: Instance of text_utils.Vocab.
    params: Model parameters.
  """

  # Wrapper for QA model.
  def model_fn(features, labels, mode, params):
    """A model function satisfying the tf.estimator API."""
    del labels
    assert mode == tf_estimator.ModeKeys.PREDICT, "Mode should be PREDICT."
    span, _ = rc_span(
        question_ids=features["question_inputs"].token_ids,
        question_mask=features["question_inputs"].mask,
        context_ids=features["context_inputs"].token_ids,
        context_mask=features["context_inputs"].mask,
        rc_model=hub.Module(params["rc_model"]),
        vocab=vocab,
        no_answer_bias=params.get("no_answer_bias", -1e4))
    return tf_estimator.tpu.TPUEstimatorSpec(
        mode=mode,
        predictions=dict(
            question_id=features["question_id"],
            image_id=features["image_id"],
            beam_id=features["beam_id"],
            span=span))

  # Get estimator.
  params = copy.copy(params)
  params["model_dir"] = experiment_utils.get_tempdir()
  estimator = experiment_utils.get_estimator(model_fn, params)

  # Write predictions.
  tf.logging.info("Writing predictions to disk...")
  tf.io.gfile.makedirs(os.path.dirname(output_file))
  with tf.io.gfile.GFile(output_file, "w") as f:
    iterator = estimator.predict(
        input_fn=functools.partial(
            rc_dataset.get_dataset,
            caption_file=caption_file,
            qa_file=question_file,
            scratch_file=experiment_utils.get_tempfile(),
            vocab=vocab),
        yield_single_examples=True)
    i = 0
    for ex in iterator:
      i += 1
      f.write(json.dumps(ex, cls=io_utils.NumpyEncoder) + "\n")
      if i % 1000 == 0:
        tf.logging.info("Wrote %d predictions", i)
    tf.logging.info("Done. Wrote %d predictions.", i)
Write spans to disk using RC model.

  Args:
    caption_file: Path to caption predictions.
    question_file: Path to question.
    output_file: Path to write spans selected by the QA model.
    vocab: Instance of text_utils.Vocab.
    params: Model parameters.
  
language/capwap/utils/reward_utils.py