class_docstr: Graph regularization class with support for caching neighbor state.
  
  It requires an instance of `NeighborCacheClient` to issue lookup and update
  operations to the neighbor cache.
  
  Example usage:
  
  ```python
  # Create a base model using the sequential, functional, or subclass API.
  base_model = tf.keras.Sequential(...)
  
  # Create a NeighborCacheClient object that implements the abstract methods.
  class NeighborCacheClientImpl(carls.NeighborCacheClient):
    def lookup(self, neighbor_ids):
      Send lookup request to cache server, and return the result.
  
    def update(self, neighbor_ids, neighbor_state):
      Send update request to the cache server.
  
  # Wrap the base model to include graph regularization using up to 1 neighbor
  # per sample.
  neighbor_cache_client = NeighborCacheClientImpl()
  graph_config = nsl.configs.make_graph_reg_config(max_neighbors=1)
  graph_model = carls.GraphRegularizationWithCaching(
      base_model, graph_config, neighbor_cache_client)
  
  # Compile, train, and evaluate the graph-regularized model as usual.
  graph_model.compile(
      optimizer='adam',
      loss=tf.keras.losses.SparseCategoricalCrossentropy(),
      metrics=['accuracy'])
  graph_model.fit(train_dataset, epochs=5)
  graph_model.evaluate(test_dataset)
  ```
docstr: Invokes `base_model` on `features` and updates the neighbor cache.
docstr_tok: ["Invokes","`","base_model","`","on","`","features","`","and","updates","the","neighbor","cache","."]
code: def _infer_and_update(self, features, training, **kwargs):
      """Invokes `base_model` on `features` and updates the neighbor cache."""
      if self.neighbor_cache_client:
          key = features.pop(
              self.neighbor_cache_client.key_feature_name
          )
      output = self.base_model(features, training=training, **kwargs)
      if self.neighbor_cache_client:
          # TODO(thunderfyc): Make update operation optional when we have config
          # for neighbor cache in graph config.
          self.neighbor_cache_client.update(key, output)
      return output
  
file_path: neural-structured-learning/research/carls/graph_regularization.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from neural_structured_learning.keras import graph_regularization
  import tensorflow
label_desc: Use image node_id 2 for calling the GraphRegularizationWithCaching obj's underlying member method code with example usage: obj._infer_and_update(features, training) and returns: output