def model_function(features, labels, mode, params):
    """Builds the `tf.estimator.EstimatorSpec` to train/eval with."""
    is_train = mode == tf_estimator.ModeKeys.TRAIN
    logits = predict(is_train, embeddings, features["premise"],
                     features["hypothesis"])

    loss = tf.nn.sparse_softmax_cross_entropy_with_logits(
        labels=tf.to_int32(labels), logits=logits)
    loss = tf.reduce_mean(loss)
    if mode == tf_estimator.ModeKeys.TRAIN:
      train_op = get_train_op(loss)
    else:
      # Don't build the train_op unnecessarily, since the ADAM variables can
      # cause problems with loading checkpoints on CPUs.
      train_op = None
    metrics = dict(
        accuracy=tf.metrics.accuracy(
            tf.argmax(logits, 1, output_type=tf.int32), tf.to_int32(labels)))

    checkpoint_file = FLAGS.checkpoint_file
    if checkpoint_file is None:
      scaffold = None
    else:
      saver = tf.train.Saver(tf.trainable_variables())

      def _init_fn(_, sess):
        saver.restore(sess, checkpoint_file)

      scaffold = tf.train.Scaffold(init_fn=_init_fn)

    return tf_estimator.EstimatorSpec(
        mode=mode,
        scaffold=scaffold,
        loss=loss,
        predictions=None,
        train_op=train_op,
        eval_metric_ops=metrics)
Builds the `tf.estimator.EstimatorSpec` to train/eval with.
language/boolq/run_recurrent_model_boolq.py