docstr: Verifies eval results for the graph-regularized model.
  
  This uses a linear regressor as the base model.
  
  Args:
    train_example: An instance of `tf.train.Example` used for training.
    test_example: An instance of `tf.train.Example` used for evaluation.
    model_fn: A function that builds a linear regression model.
    max_neighbors: The maximum number of neighbors for graph regularization.
    weight: Initial value for the weights variable in the linear regressor.
    distributed_strategy: An instance of `tf.distribute.Strategy` specifying
      the distributed strategy to use for training.
docstr_tok: ["Verifies","eval","results","for","the","graph-regularized","model",".","This","uses","a","linear","regressor","as","the","base","model",".","Args",":","train_example",":","An","instance","of","`","tf.train.Example","`","used","for","training",".","test_example",":","An","instance","of","`","tf.train.Example","`","used","for","evaluation",".","model_fn",":","A","function","that","builds","a","linear","regression","model",".","max_neighbors",":","The","maximum","number","of","neighbors","for","graph","regularization",".","weight",":","Initial","value","for","the","weights","variable","in","the","linear","regressor",".","distributed_strategy",":","An","instance","of","`","tf.distribute.Strategy","`","specifying","the","distributed","strategy","to","use","for","training","."]
code: def _train_and_check_eval_results(
      self,
      train_example,
      test_example,
      model_fn,
      max_neighbors,
      weight,
      distributed_strategy=None,
  ):
      """Verifies eval results for the graph-regularized model.
  
      This uses a linear regressor as the base model.
  
      Args:
        train_example: An instance of `tf.train.Example` used for training.
        test_example: An instance of `tf.train.Example` used for evaluation.
        model_fn: A function that builds a linear regression model.
        max_neighbors: The maximum number of neighbors for graph regularization.
        weight: Initial value for the weights variable in the linear regressor.
        distributed_strategy: An instance of `tf.distribute.Strategy` specifying
          the distributed strategy to use for training.
      """
  
      train_dataset = make_dataset(
          train_example,
          input_shape=[2],
          training=True,
          max_neighbors=max_neighbors,
      )
  
      test_dataset = make_dataset(
          test_example, input_shape=[2], training=False, max_neighbors=0
      )
  
      def _create_and_compile_graph_reg_model(
          model_fn, weight, max_neighbors
      ):
          """Creates and compiles a graph regularized model.
  
          Args:
            model_fn: A function that builds a linear regression model.
            weight: Initial value for the weights variable in the linear regressor.
            max_neighbors: The maximum number of neighbors for graph regularization.
  
          Returns:
            A pair containing the unregularized model and the graph regularized
            model as `tf.keras.Model` instances.
          """
          model = model_fn((2,), weight)
          graph_reg_config = configs.make_graph_reg_config(
              max_neighbors=max_neighbors, multiplier=1
          )
          graph_reg_model = (
              graph_regularization.GraphRegularizationWithCaching(
                  model, graph_reg_config
              )
          )
          graph_reg_model.compile(
              optimizer=tf.keras.optimizers.SGD(LEARNING_RATE),
              loss="MSE",
              metrics=["accuracy"],
          )
          return model, graph_reg_model
  
      if distributed_strategy:
          with distributed_strategy.scope():
              (
                  model,
                  graph_reg_model,
              ) = _create_and_compile_graph_reg_model(
                  model_fn, weight, max_neighbors
              )
      else:
          model, graph_reg_model = _create_and_compile_graph_reg_model(
              model_fn, weight, max_neighbors
          )
  
      graph_reg_model.fit(x=train_dataset, epochs=1, steps_per_epoch=1)
  
      # Evaluating the graph-regularized model should yield the same results
      # as evaluating the base model as the former involves just using the
      # base model for evaluation.
      graph_reg_model_eval_results = dict(
          zip(
              graph_reg_model.metrics_names,
              graph_reg_model.evaluate(x=test_dataset),
          )
      )
      base_model_eval_results = dict(
          zip(model.metrics_names, model.evaluate(x=test_dataset))
      )
      self.assertAllClose(
          base_model_eval_results, graph_reg_model_eval_results
      )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from absl.testing import parameterized
  from neural_structured_learning import configs
  from research.carls import graph_regularization
  from research.carls import neighbor_cache_client
  import numpy
  import tensorflow
  from google.protobuf import text_format
  from tensorflow.python.framework import test_util
label_desc: Use image node_id 8 for calling the GraphRegularizationWithCachingTest obj's underlying member method code with example usage: obj._train_and_check_eval_results(train_example, test_example, model_fn, max_neighbors, weight, distributed_strategy) and returns: model,  graph_reg_model