class_docstr: InfographStar is a semi-supervised graph convolutional network for predicting molecular properties.
  It aims to maximize the mutual information between the graph-level representation and the
  representations of substructures of different scales. It does this by producing graph-level
  encodings and substructure encodings, and then using a discriminator to classify if they
  are from the same molecule or not.
  
  Supervised training is done by using the graph-level encodings to predict the target property. Semi-supervised training is done by adding a loss term that maximizes the mutual information between the graph-level encodings and the substructure encodings to the supervised loss.
  These modes can be chosen by setting the training_mode parameter.
  
  To conduct training in unsupervised mode, use InfoGraphModel.
  
  References
  ----------
  .. [1] F.-Y. Sun, J. Hoffmann, V. Verma, and J. Tang, “InfoGraph: Unsupervised and Semi-supervised Graph-Level Representation Learning via Mutual Maximization.” arXiv, Jan. 17, 2020. http://arxiv.org/abs/1908.01000
  
  Parameters
  ----------
  num_features: int
      Number of node features for each input
  edge_features: int
      Number of edge features for each input
  embedding_dim: int
      Dimension of the embedding
  training_mode: str
      The mode to use for training. Options are 'supervised', 'semisupervised'. For unsupervised training, use InfoGraphModel.
  measure: str
      The divergence measure to use for the unsupervised loss. Options are 'GAN', 'JSD',
      'KL', 'RKL', 'X2', 'DV', 'H2', or 'W1'.
  average_loss: bool
      Whether to average the loss over the batch
  
  Examples
  --------
  >>> from deepchem.models.torch_models import InfoGraphStarModel
  >>> from deepchem.feat import MolGraphConvFeaturizer
  >>> from deepchem.data import NumpyDataset
  >>> import torch
  >>> smiles = ["C1CCC1", "C1=CC=CN=C1"]
  >>> featurizer = MolGraphConvFeaturizer(use_edges=True)
  >>> X = featurizer.featurize(smiles)
  >>> y = torch.randint(0, 2, size=(2, 1)).float()
  >>> w = torch.ones(size=(2, 1)).float()
  >>> ds = NumpyDataset(X, y, w)
  >>> num_feat = max([ds.X[i].num_node_features for i in range(len(ds))])
  >>> edge_dim = max([ds.X[i].num_edge_features for i in range(len(ds))])
  >>> model = InfoGraphStarModel(num_feat, edge_dim, 15, training_mode='semisupervised')
  >>> loss = model.fit(ds, nb_epoch=1)
docstr: Builds the components of the InfoGraphStar model. InfoGraphStar works by maximizing the mutual information between the graph-level representation and the representations of substructures of different scales.
  
  It does this by producing graph-level encodings and substructure encodings, and then using a discriminator to classify if they are from the same molecule or not.
  
  The encoder is a graph convolutional network that produces the graph-level encodings and substructure encodings.
  
  In a supervised training mode, only 1 encoder is used and the encodings are not compared, while in a semi-supvervised training mode they are different in order to prevent negative transfer from the pretraining stage.
  
  The local discriminator is a multilayer perceptron that classifies if the substructure encodings are from the same molecule or not while the global discriminator classifies if the graph-level encodings are from the same molecule or not.
  
  Components list, type and description:
  --------------------------------------
  encoder: InfoGraphEncoder
  
  unsup_encoder: InfoGraphEncoder for supervised or GINEncoder for unsupervised training
  
  ff1: MultilayerPerceptron, feedforward network
  
  ff2: MultilayerPerceptron, feedforward network
  
  fc1: torch.nn.Linear, fully connected layer
  
  fc2: torch.nn.Linear, fully connected layer
  
  local_d: MultilayerPerceptron, local discriminator
  
  global_d: MultilayerPerceptron, global discriminator
docstr_tok: ["Builds","the","components","of","the","InfoGraphStar","model",".","InfoGraphStar","works","by","maximizing","the","mutual","information","between","the","graph-level","representation","and","the","representations","of","substructures","of","different","scales",".","It","does","this","by","producing","graph-level","encodings","and","substructure","encodings",",","and","then","using","a","discriminator","to","classify","if","they","are","from","the","same","molecule","or","not",".","The","encoder","is","a","graph","convolutional","network","that","produces","the","graph-level","encodings","and","substructure","encodings",".","In","a","supervised","training","mode",",","only","1","encoder","is","used","and","the","encodings","are","not","compared",",","while","in","a","semi-supvervised","training","mode","they","are","different","in","order","to","prevent","negative","transfer","from","the","pretraining","stage",".","The","local","discriminator","is","a","multilayer","perceptron","that","classifies","if","the","substructure","encodings","are","from","the","same","molecule","or","not","while","the","global","discriminator","classifies","if","the","graph-level","encodings","are","from","the","same","molecule","or","not",".","Components","list",",","type","and","description",":","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","encoder",":","InfoGraphEncoder","unsup_encoder",":","InfoGraphEncoder","for","supervised","or","GINEncoder","for","unsupervised","training","ff1",":","MultilayerPerceptron",",","feedforward","network","ff2",":","MultilayerPerceptron",",","feedforward","network","fc1",":","torch.nn.Linear",",","fully","connected","layer","fc2",":","torch.nn.Linear",",","fully","connected","layer","local_d",":","MultilayerPerceptron",",","local","discriminator","global_d",":","MultilayerPerceptron",",","global","discriminator"]
code: def build_components(self):
      """
      Builds the components of the InfoGraphStar model. InfoGraphStar works by maximizing the mutual information between the graph-level representation and the representations of substructures of different scales.
  
      It does this by producing graph-level encodings and substructure encodings, and then using a discriminator to classify if they are from the same molecule or not.
  
      The encoder is a graph convolutional network that produces the graph-level encodings and substructure encodings.
  
      In a supervised training mode, only 1 encoder is used and the encodings are not compared, while in a semi-supvervised training mode they are different in order to prevent negative transfer from the pretraining stage.
  
      The local discriminator is a multilayer perceptron that classifies if the substructure encodings are from the same molecule or not while the global discriminator classifies if the graph-level encodings are from the same molecule or not.
  
      Components list, type and description:
      --------------------------------------
      encoder: InfoGraphEncoder
  
      unsup_encoder: InfoGraphEncoder for supervised or GINEncoder for unsupervised training
  
      ff1: MultilayerPerceptron, feedforward network
  
      ff2: MultilayerPerceptron, feedforward network
  
      fc1: torch.nn.Linear, fully connected layer
  
      fc2: torch.nn.Linear, fully connected layer
  
      local_d: MultilayerPerceptron, local discriminator
  
      global_d: MultilayerPerceptron, global discriminator
      """
      if self.task == "supervised":
          return {
              "encoder": InfoGraphEncoder(
                  self.num_features,
                  self.edge_features,
                  self.embedding_dim,
              ),
              "unsup_encoder": InfoGraphEncoder(
                  self.num_features,
                  self.edge_features,
                  self.embedding_dim,
              ),
              "ff1": MultilayerPerceptron(
                  2 * self.embedding_dim,
                  self.embedding_dim,
                  (self.embedding_dim,),
              ),
              "ff2": MultilayerPerceptron(
                  2 * self.embedding_dim,
                  self.embedding_dim,
                  (self.embedding_dim,),
              ),
              "fc1": torch.nn.Linear(
                  2 * self.embedding_dim, self.embedding_dim
              ),
              "fc2": torch.nn.Linear(
                  self.embedding_dim, self.output_dim
              ),
              "local_d": MultilayerPerceptron(
                  self.embedding_dim,
                  self.embedding_dim,
                  (self.embedding_dim,),
                  skip_connection=True,
              ),
              "global_d": MultilayerPerceptron(
                  2 * self.embedding_dim,
                  self.embedding_dim,
                  (self.embedding_dim,),
                  skip_connection=True,
              ),
          }
      elif self.task == "semisupervised":
          return {
              "encoder": InfoGraphEncoder(
                  self.num_features,
                  self.edge_features,
                  self.embedding_dim,
              ),
              "unsup_encoder": GINEncoder(
                  self.num_features,
                  self.embedding_dim,
                  self.num_gc_layers,
              ),
              "ff1": MultilayerPerceptron(
                  2 * self.embedding_dim,
                  self.embedding_dim,
                  (self.embedding_dim,),
              ),
              "ff2": MultilayerPerceptron(
                  self.embedding_dim,
                  self.embedding_dim,
                  (self.embedding_dim,),
              ),
              "fc1": torch.nn.Linear(
                  2 * self.embedding_dim, self.embedding_dim
              ),
              "fc2": torch.nn.Linear(
                  self.embedding_dim, self.output_dim
              ),
              "local_d": MultilayerPerceptron(
                  self.embedding_dim,
                  self.embedding_dim,
                  (self.embedding_dim,),
                  skip_connection=True,
              ),
              "global_d": MultilayerPerceptron(
                  self.embedding_dim,
                  self.embedding_dim,
                  (self.embedding_dim,),
                  skip_connection=True,
              ),
          }
  
imports: import torch
  import torch.nn
  import torch.nn.functional
  from torch.nn import GRU, Linear, ReLU, Sequential
  from typing import Iterable, List, Tuple, Optional, Dict, Literal
  from deepchem.metrics import to_one_hot
  import deepchem
  from deepchem.models.losses import SoftmaxCrossEntropy
  from deepchem.feat.graph_data import BatchGraphData
  from deepchem.models.losses import GlobalMutualInformationLoss, LocalMutualInformationLoss
  from deepchem.models.torch_models.layers import MultilayerPerceptron
  from deepchem.models.torch_models.modular import ModularTorchModel
label_desc: Use image node_id 2 for calling the InfoGraphStarModel obj's underlying member method code with example usage: obj.build_components() and returns: dict, dict