class_docstr: Superclass for models used for the classification or agreement model.
  
  Attributes:
    aggregation: A string representing the way to aggregate two inputs provided
      in the function `_aggregate`. This is designed for the agreement model,
      where the source and target inputs need to be integrated. The allowed
      options are the following:
        None: no aggregation is performed.
        - `add`: the two inputs are added
        - `dist`: squared distance between the two inputs, elementwise.
        - `concat`: the two inputs are concatenated along axis=1.
        - `project_add`: the two inputs are first projected to a different space
          using a fully connected network with the hidden units provided in
          hidden_aggregation, and followed by the activation function in
          activation. Then the projected inputs are added, like in `add`.
        - `project_dist`: The two inputs are projected as in `project_add`,
          followed by a distance calculation like in `dist`.
        - `project_concat`: The two inputs are projected as in `project_add`,
          followed by a concatenation like in `concat`.
    hidden_aggregation: A tuple or list of integers representing the number of
      hidden units in each layer of the projection network described above.
    activation: An activation function to be applied to the outputs of each
      fully connected layer of the aggregation multilayer perceptron.
docstr: Aggregates the input features.
  
  Because this MLP can be used both by the classification and agreement
  models, the provided inputs could be a single batch of features for the
  classification model, or a tuple of two batches (src_features, tgt_features)
  for the agreement model. In the latter case, the two inputs need to be
  aggregated before they are passed through the MLP. Here we provide several
  options for how this aggregation can be done, specified by the `aggregate`
  class attribute. The valid options are:
  - None: no aggregation is performed (this is used by the classification
          model).
  - add: The two inputs are added: src_features + tgt_features.
  - dist: The two inputs are aggregated into their squared difference.
  - concat: The two inputs are concatenated along the features dimension.
  - project_add: The two inputs are projected to another space, and then
                 added.
  - project_dist: The two inputs are projected to another space, and then
                  we compute squared element-wise distance.
  - project_concat: The two inputs are projected to another space, and then
                    concatenated.
  
  Args:
    inputs: A batch of features of shape (batch_size, num_features) or
      a tuple of two such batches of features.
  Returns:
    A batch of aggregated features of shape (batch_size, new_num_features),
    where the feature dimension size may have changed.
docstr_tok: ["Aggregates","the","input","features",".","Because","this","MLP","can","be","used","both","by","the","classification","and","agreement","models",",","the","provided","inputs","could","be","a","single","batch","of","features","for","the","classification","model",",","or","a","tuple","of","two","batches","(","src_features",",","tgt_features",")","for","the","agreement","model",".","In","the","latter","case",",","the","two","inputs","need","to","be","aggregated","before","they","are","passed","through","the","MLP",".","Here","we","provide","several","options","for","how","this","aggregation","can","be","done",",","specified","by","the","`","aggregate","`","class","attribute",".","The","valid","options","are",":","-","None",":","no","aggregation","is","performed","(","this","is","used","by","the","classification","model",")",".","-","add",":","The","two","inputs","are","added",":","src_features","+","tgt_features",".","-","dist",":","The","two","inputs","are","aggregated","into","their","squared","difference",".","-","concat",":","The","two","inputs","are","concatenated","along","the","features","dimension",".","-","project_add",":","The","two","inputs","are","projected","to","another","space",",","and","then","added",".","-","project_dist",":","The","two","inputs","are","projected","to","another","space",",","and","then","we","compute","squared","element-wise","distance",".","-","project_concat",":","The","two","inputs","are","projected","to","another","space",",","and","then","concatenated",".","Args",":","inputs",":","A","batch","of","features","of","shape","(","batch_size",",","num_features",")","or","a","tuple","of","two","such","batches","of","features",".","Returns",":","A","batch","of","aggregated","features","of","shape","(","batch_size",",","new_num_features",")",",","where","the","feature","dimension","size","may","have","changed","."]
code: def _aggregate(self, inputs):
      """Aggregates the input features.
  
      Because this MLP can be used both by the classification and agreement
      models, the provided inputs could be a single batch of features for the
      classification model, or a tuple of two batches (src_features, tgt_features)
      for the agreement model. In the latter case, the two inputs need to be
      aggregated before they are passed through the MLP. Here we provide several
      options for how this aggregation can be done, specified by the `aggregate`
      class attribute. The valid options are:
      - None: no aggregation is performed (this is used by the classification
              model).
      - add: The two inputs are added: src_features + tgt_features.
      - dist: The two inputs are aggregated into their squared difference.
      - concat: The two inputs are concatenated along the features dimension.
      - project_add: The two inputs are projected to another space, and then
                     added.
      - project_dist: The two inputs are projected to another space, and then
                      we compute squared element-wise distance.
      - project_concat: The two inputs are projected to another space, and then
                        concatenated.
  
      Args:
        inputs: A batch of features of shape (batch_size, num_features) or
          a tuple of two such batches of features.
      Returns:
        A batch of aggregated features of shape (batch_size, new_num_features),
        where the feature dimension size may have changed.
      """
      if self.aggregation is None:
          return inputs
      # If it requires aggregation, we assume the inputs are passes as a tuple.
      left = inputs[0]
      right = inputs[1]
  
      # In case the aggregation option requires projection, we first do this.
      if self.aggregation in (
          "project_add",
          "project_dist",
          "project_concat",
      ):
          left = self._project(left)
          right = self._project(right, reuse=True)
  
      if self.aggregation.endswith("add"):
          return left + right
      if self.aggregation.endswith("dist"):
          return tf.square(left - right)
      elif self.aggregation.endswith("concat"):
          return tf.concat((left, right), axis=1)
      else:
          raise NotImplementedError()
  
file_path: neural-structured-learning/research/gam/gam/models/models_base.py
imports: import abc
  import logging
  import numpy
  import tensorflow
label_desc: Use image node_id 8 for calling the Model obj's underlying member method code with example usage: obj._aggregate(inputs) and returns: inputs, unknown, tf, tf