def build_model_fn(self):
    """Return a function suitable for use in creating an Estimator.

    Will call self.build_model

    Returns:
      a Python function
    """

    def model_fn(features, labels, mode, params):
      """Estimator model_fn produced by ModelBuilder.

      Args:
        features: passed to config_model_prediction
        labels: passed to config_model_[training|evaluation]
        mode: from tf.estimator.ModeKeys
        params: dict of options passed to config_* methods

      Returns:
        a Python function
      """
      # initialize and partially configure the model
      m = Model()
      m.context = self.build_context(params=params)

      self.config_model_prediction(m, features, params=params)
      if mode == tf_estimator.ModeKeys.PREDICT:
        return tf_estimator.EstimatorSpec(mode=mode, predictions=m.predictions)

      self.config_model_training(m, labels, params)
      if mode == tf_estimator.ModeKeys.TRAIN:
        return tf_estimator.EstimatorSpec(
            mode=mode, train_op=m.train_op, loss=m.loss)

      self.config_model_evaluation(m, labels, params)
      if mode == tf_estimator.ModeKeys.EVAL:
        return tf_estimator.EstimatorSpec(
            mode=mode, loss=m.loss, eval_metric_ops=m.evaluations)

      raise ValueError('illegal mode %r' % mode)

    return model_fn
Return a function suitable for use in creating an Estimator.

    Will call self.build_model

    Returns:
      a Python function
    
language/nql/nql/util.py