def get_predictor_for_model_fn(model_dir, model_function):
  """Build a predictor. Can't use SavedModel here due to the py_func."""
  with tf.io.gfile.GFile(os.path.join(model_dir, "params.json")) as f:
    params = json.load(f)


  best_checkpoint_pattern = os.path.join(model_dir, "export", "best_default",
                                         "checkpoint", "*.index")
  best_checkpoint = tf.io.gfile.glob(
      best_checkpoint_pattern)[0][:-len(".index")]
  serving_input_receiver = serving_fn()
  estimator_spec = model_function(
      features=serving_input_receiver.features,
      labels=None,
      mode=tf_estimator.ModeKeys.PREDICT,
      params=params)
  question_tensor = serving_input_receiver.receiver_tensors["question"]
  session = tf.train.MonitoredSession(
      session_creator=tf.train.ChiefSessionCreator(
          checkpoint_filename_with_path=best_checkpoint))

  def _predict(question):
    return session.run(
        estimator_spec.predictions, feed_dict={question_tensor: question})

  return _predict
Build a predictor. Can't use SavedModel here due to the py_func.
language/orqa/models/orqa_model.py