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: Class initializer.
  
  Args:
    base_model: Unregularized model to which the loss term resulting from
      graph regularization will be added.
    graph_reg_config: Instance of `nsl.configs.GraphRegConfig` that contains
      configuration for graph regularization. Use
      `nsl.configs.make_graph_reg_config` to construct one.
    neighbor_cache_client: Used to look up and update cached neighbor state.
docstr_tok: ["Class","initializer",".","Args",":","base_model",":","Unregularized","model","to","which","the","loss","term","resulting","from","graph","regularization","will","be","added",".","graph_reg_config",":","Instance","of","`","nsl.configs.GraphRegConfig","`","that","contains","configuration","for","graph","regularization",".","Use","`","nsl.configs.make_graph_reg_config","`","to","construct","one",".","neighbor_cache_client",":","Used","to","look","up","and","update","cached","neighbor","state","."]
code: def __init__(
      self,
      base_model,
      graph_reg_config=None,
      neighbor_cache_client=None,
  ):
      """Class initializer.
  
      Args:
        base_model: Unregularized model to which the loss term resulting from
          graph regularization will be added.
        graph_reg_config: Instance of `nsl.configs.GraphRegConfig` that contains
          configuration for graph regularization. Use
          `nsl.configs.make_graph_reg_config` to construct one.
        neighbor_cache_client: Used to look up and update cached neighbor state.
      """
  
      super(GraphRegularizationWithCaching, self).__init__(
          base_model=base_model, graph_reg_config=graph_reg_config
      )
      self.neighbor_cache_client = neighbor_cache_client
  
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 1 to create a new GraphRegularizationWithCaching object from inherited base classes: graph_regularization with example: obj = GraphRegularizationWithCaching(base_model, graph_reg_config, neighbor_cache_client)