class_docstr: Class that wraps a given `Keras` model to include graph regularization.
  
  Graph regularization is configured by an instance of
  `nsl.configs.GraphRegConfig` and the resulting loss is added as a
  regularization term to the model's training objective. The graph-regularized
  model reuses the layers and variables from the base model. So, training this
  model will also update the variables in the base model.
  
  Note: This class expects input data to include neighor features corresponding
  to the maximum number of neighbors used for graph regularization.
  
  Example usage:
  
  ```python
  # Create a base model using the sequential, functional, or subclass API.
  base_model = tf.keras.Sequential(...)
  
  # Wrap the base model to include graph regularization using up to 1 neighbor
  # per sample.
  graph_config = nsl.configs.make_graph_reg_config(max_neighbors=1)
  graph_model = nsl.keras.GraphRegularization(base_model, graph_config)
  
  # 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.
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","."]
code: def __init__(self, base_model, graph_reg_config=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.
      """
  
      super(GraphRegularization, self).__init__(
          name="GraphRegularization"
      )
      self.base_model = base_model
      self.graph_reg_config = (
          nsl_configs.GraphRegConfig()
          if graph_reg_config is None
          else graph_reg_config
      )
      self.nbr_features_layer = nsl_layers.NeighborFeatures(
          self.graph_reg_config.neighbor_config
      )
      self.regularizer = nsl_layers.PairwiseDistance(
          self.graph_reg_config.distance_config, name="graph_loss"
      )
  
file_path: neural-structured-learning/neural_structured_learning/keras/graph_regularization.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import neural_structured_learning.configs
  from neural_structured_learning.keras import layers
  import tensorflow
label_desc: Use image node_id 1 to create a new GraphRegularization object from inherited base classes: tf.keras with example: obj = GraphRegularization(base_model, graph_reg_config)