class_docstr: Wrapper thats adds adversarial regularization to a given `tf.keras.Model`.
  
  This model will reuse the layers and variables as the given `base_model`, so
  training this model will also update the variables in the `base_model`. The
  adversarial regularization can be configured by `adv_config`. (See
  `nsl.configs.AdvRegConfig` for the hyperparameters.) The regularization term
  will be added into training objective, and will be minimized during training
  together with other losses specified in `compile()`.
  
  This model expects its input to be a dictionary mapping feature names to
  feature values. The dictionary should contain both input data (`x`) and target
  data (`y`). The feature names of the target data should be passed to this
  model's constructor in `label_keys`, so the model can distinguish between
  input data and target data. If your samples are weighted, the sample weight
  should also be a feature in the dictionary, and its name should be passed to
  the constructor in `sample_weight_key`. When calling this model's `fit()` or
  `evaluate()` method, the argument `y` should not be set because the target
  data is already in the input dictionary. The dictionary format also implies
  that the input has to be named, i.e. the `name` argument of `tf.keras.Input()`
  should be set.
  
  Example:
  
  ```python
  # A linear regression model (for demonstrating the usage only)
  base_model = tf.keras.Sequential([
      tf.keras.Input(shape=(2,), name='input'),
      tf.keras.layers.Dense(1),
  ])
  
  # Applies the wrapper, with 0.2 as regularization weight.
  adv_config = nsl.configs.make_adv_reg_config(multiplier=0.2)
  adv_model = nsl.keras.AdversarialRegularization(base_model,
                                                  label_keys=['label'],
                                                  adv_config=adv_config)
  
  # Compiles the model as usual.
  adv_model.compile(optimizer='adam', loss='mean_squared_error')
  
  # Trains the model. (The actual training data is omitted for clarity.)
  # The model minimizes (mean_squared_error + 0.2 * adversarial_regularization).
  adv_model.fit(x={'input': x_train, 'label': y_train}, batch_size=32)
  ```
  
  It is recommended to use `tf.data.Dataset` to handle the dictionary format
  requirement of the input, especially when using the `validation_data` argument
  in `fit()`.
  
  ```python
  train_data = tf.data.Dataset.from_tensor_slices(
      {'input': x_train, 'label': y_train}).batch(batch_size)
  val_data = tf.data.Dataset.from_tensor_slices(
      {'input': x_val, 'label': y_val}).batch(batch_size)
  val_steps = x_val.shape[0] / batch_size
  adv_model.fit(train_data, validation_data=val_data,
                validation_steps=val_steps, epochs=2, verbose=1)
  ```
docstr: Constructor of `AdversarialRegularization` class.
  
  Args:
    base_model: A `tf.Keras.Model` to which adversarial regularization will be
      applied.
    label_keys: A tuple of strings denoting which keys in the input features
      (a `dict` mapping keys to tensors) represent labels. This list should be
      1-to-1 corresponding to the output of the `base_model`.
    sample_weight_key: A string denoting which key in the input feature (a
      `dict` mapping keys to tensors) represents sample weight. If not set,
      the weight is 1.0 for each input example.
    adv_config: Instance of `nsl.configs.AdvRegConfig` for configuring
      adversarial regularization.
    base_with_labels_in_features: A Boolean value indicating whether the base
      model expects label features as input. This option is effective only
      when the base model is a subclassed Keras model. (For functional and
      Sequential models, the expected inputs can be inferred from the model
      itself.) If set to true, the base model will be called with an input
      dictionary including label and sample-weight features. If set to false,
      label and sample-weight features will not present in base model's input
      dictionary.
docstr_tok: ["Constructor","of","`","AdversarialRegularization","`","class",".","Args",":","base_model",":","A","`","tf.Keras.Model","`","to","which","adversarial","regularization","will","be","applied",".","label_keys",":","A","tuple","of","strings","denoting","which","keys","in","the","input","features","(","a","`","dict","`","mapping","keys","to","tensors",")","represent","labels",".","This","list","should","be","1-to-1","corresponding","to","the","output","of","the","`","base_model","`",".","sample_weight_key",":","A","string","denoting","which","key","in","the","input","feature","(","a","`","dict","`","mapping","keys","to","tensors",")","represents","sample","weight",".","If","not","set",",","the","weight","is","1.0","for","each","input","example",".","adv_config",":","Instance","of","`","nsl.configs.AdvRegConfig","`","for","configuring","adversarial","regularization",".","base_with_labels_in_features",":","A","Boolean","value","indicating","whether","the","base","model","expects","label","features","as","input",".","This","option","is","effective","only","when","the","base","model","is","a","subclassed","Keras","model",".","(","For","functional","and","Sequential","models",",","the","expected","inputs","can","be","inferred","from","the","model","itself",".",")","If","set","to","true",",","the","base","model","will","be","called","with","an","input","dictionary","including","label","and","sample-weight","features",".","If","set","to","false",",","label","and","sample-weight","features","will","not","present","in","base","model","'s","input","dictionary","."]
code: def __init__(
      self,
      base_model,
      label_keys=("label",),
      sample_weight_key=None,
      adv_config=None,
      base_with_labels_in_features=False,
  ):
      """Constructor of `AdversarialRegularization` class.
  
      Args:
        base_model: A `tf.Keras.Model` to which adversarial regularization will be
          applied.
        label_keys: A tuple of strings denoting which keys in the input features
          (a `dict` mapping keys to tensors) represent labels. This list should be
          1-to-1 corresponding to the output of the `base_model`.
        sample_weight_key: A string denoting which key in the input feature (a
          `dict` mapping keys to tensors) represents sample weight. If not set,
          the weight is 1.0 for each input example.
        adv_config: Instance of `nsl.configs.AdvRegConfig` for configuring
          adversarial regularization.
        base_with_labels_in_features: A Boolean value indicating whether the base
          model expects label features as input. This option is effective only
          when the base model is a subclassed Keras model. (For functional and
          Sequential models, the expected inputs can be inferred from the model
          itself.) If set to true, the base model will be called with an input
          dictionary including label and sample-weight features. If set to false,
          label and sample-weight features will not present in base model's input
          dictionary.
      """
      super(AdversarialRegularization, self).__init__(
          name="AdversarialRegularization"
      )
      self.base_model = base_model
      self.label_keys = label_keys
      self.sample_weight_key = sample_weight_key
      self.adv_config = adv_config or nsl_configs.AdvRegConfig()
      self._base_with_labels_in_features = base_with_labels_in_features
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  import functools
  import types
  import attr
  import neural_structured_learning.configs
  from neural_structured_learning.lib import adversarial_neighbor
  import six
  import tensorflow
label_desc: Use image node_id 1 to create a new AdversarialRegularization object from inherited base classes: tf.keras with example: obj = AdversarialRegularization(base_model, label_keys, sample_weight_key, adv_config, base_with_labels_in_features)