class_docstr: Model for Graph Property Prediction Based on Graph Convolution Networks (GCN).
  
  This model proceeds as follows:
  
  * Update node representations in graphs with a variant of GCN
  * For each graph, compute its representation by 1) a weighted sum of the node
      representations in the graph, where the weights are computed by applying a
      gating function to the node representations 2) a max pooling of the node
      representations 3) concatenating the output of 1) and 2)
  * Perform the final prediction using an MLP
  
  Examples
  --------
  >>> import deepchem as dc
  >>> from deepchem.models import GCNModel
  >>> # preparing dataset
  >>> smiles = ["C1CCC1", "CCC"]
  >>> labels = [0., 1.]
  >>> featurizer = dc.feat.MolGraphConvFeaturizer()
  >>> X = featurizer.featurize(smiles)
  >>> dataset = dc.data.NumpyDataset(X=X, y=labels)
  >>> # training model
  >>> model = GCNModel(mode='classification', n_tasks=1,
  ...                  batch_size=16, learning_rate=0.001)
  >>> loss = model.fit(dataset, nb_epoch=5)
  
  References
  ----------
  .. [1] Thomas N. Kipf and Max Welling. "Semi-Supervised Classification with Graph
      Convolutional Networks." ICLR 2017.
  
  Notes
  -----
  This class requires DGL (https://github.com/dmlc/dgl) and DGL-LifeSci
  (https://github.com/awslabs/dgl-lifesci) to be installed.
  
  This model is different from deepchem.models.GraphConvModel as follows:
  
  * For each graph convolution, the learnable weight in this model is shared across all nodes.
      ``GraphConvModel`` employs separate learnable weights for nodes of different degrees. A
      learnable weight is shared across all nodes of a particular degree.
  * For ``GraphConvModel``, there is an additional GraphPool operation after each
      graph convolution. The operation updates the representation of a node by applying an
      element-wise maximum over the representations of its neighbors and itself.
  * For computing graph-level representations, this model computes a weighted sum and an
      element-wise maximum of the representations of all nodes in a graph and concatenates them.
      The node weights are obtained by using a linear/dense layer followd by a sigmoid function.
      For ``GraphConvModel``, the sum over node representations is unweighted.
  * There are various minor differences in using dropout, skip connection and batch
      normalization.
class_docstr_tok: ["Model","for","Graph","Property","Prediction","Based","on","Graph","Convolution","Networks","(","GCN",")",".","This","model","proceeds","as","follows",":","*","Update","node","representations","in","graphs","with","a","variant","of","GCN","*","For","each","graph",",","compute","its","representation","by","1",")","a","weighted","sum","of","the","node","representations","in","the","graph",",","where","the","weights","are","computed","by","applying","a","gating","function","to","the","node","representations","2",")","a","max","pooling","of","the","node","representations","3",")","concatenating","the","output","of","1",")","and","2",")","*","Perform","the","final","prediction","using","an","MLP","Examples","--","--","--","--",">",">",">","import","deepchem","as","dc",">",">",">","from","deepchem.models","import","GCNModel",">",">",">","#","preparing","dataset",">",">",">","smiles","=","[","``","C1CCC1","''",",","``","CCC","''","]",">",">",">","labels","=","[","0.",",","1",".","]",">",">",">","featurizer","=","dc.feat.MolGraphConvFeaturizer","(",")",">",">",">","X","=","featurizer.featurize","(","smiles",")",">",">",">","dataset","=","dc.data.NumpyDataset","(","X=X",",","y=labels",")",">",">",">","#","training","model",">",">",">","model","=","GCNModel","(","mode='classification","'",",","n_tasks=1",",","...","batch_size=16",",","learning_rate=0.001",")",">",">",">","loss","=","model.fit","(","dataset",",","nb_epoch=5",")","References","--","--","--","--","--","..","[","1","]","Thomas","N.","Kipf","and","Max","Welling",".","``","Semi-Supervised","Classification","with","Graph","Convolutional","Networks",".","''","ICLR","2017",".","Notes","--","--","-","This","class","requires","DGL","(","https",":","\/\/github.com\/dmlc\/dgl",")","and","DGL-LifeSci","(","https",":","\/\/github.com\/awslabs\/dgl-lifesci",")","to","be","installed",".","This","model","is","different","from","deepchem.models.GraphConvModel","as","follows",":","*","For","each","graph","convolution",",","the","learnable","weight","in","this","model","is","shared","across","all","nodes",".","``","GraphConvModel","``","employs","separate","learnable","weights","for","nodes","of","different","degrees",".","A","learnable","weight","is","shared","across","all","nodes","of","a","particular","degree",".","*","For","``","GraphConvModel","``",",","there","is","an","additional","GraphPool","operation","after","each","graph","convolution",".","The","operation","updates","the","representation","of","a","node","by","applying","an","element-wise","maximum","over","the","representations","of","its","neighbors","and","itself",".","*","For","computing","graph-level","representations",",","this","model","computes","a","weighted","sum","and","an","element-wise","maximum","of","the","representations","of","all","nodes","in","a","graph","and","concatenates","them",".","The","node","weights","are","obtained","by","using","a","linear\/dense","layer","followd","by","a","sigmoid","function",".","For","``","GraphConvModel","``",",","the","sum","over","node","representations","is","unweighted",".","*","There","are","various","minor","differences","in","using","dropout",",","skip","connection","and","batch","normalization","."]
docstr: Parameters
  ----------
  n_tasks: int
      Number of tasks.
  graph_conv_layers: list of int
      Width of channels for GCN layers. graph_conv_layers[i] gives the width of channel
      for the i-th GCN layer. If not specified, the default value will be [64, 64].
  activation: callable
      The activation function to apply to the output of each GCN layer.
      By default, no activation function will be applied.
  residual: bool
      Whether to add a residual connection within each GCN layer. Default to True.
  batchnorm: bool
      Whether to apply batch normalization to the output of each GCN layer.
      Default to False.
  dropout: float
      The dropout probability for the output of each GCN layer. Default to 0.
  predictor_hidden_feats: int
      The size for hidden representations in the output MLP predictor. Default to 128.
  predictor_dropout: float
      The dropout probability in the output MLP predictor. Default to 0.
  mode: str
      The model type, 'classification' or 'regression'. Default to 'regression'.
  number_atom_features: int
      The length of the initial atom feature vectors. Default to 30.
  n_classes: int
      The number of classes to predict per task
      (only used when ``mode`` is 'classification'). Default to 2.
  self_loop: bool
      Whether to add self loops for the nodes, i.e. edges from nodes to themselves.
      When input graphs have isolated nodes, self loops allow preserving the original feature
      of them in message passing. Default to True.
  kwargs
      This can include any keyword argument of TorchModel.
docstr_tok: ["Parameters","--","--","--","--","--","n_tasks",":","int","Number","of","tasks",".","graph_conv_layers",":","list","of","int","Width","of","channels","for","GCN","layers",".","graph_conv_layers","[","i","]","gives","the","width","of","channel","for","the","i-th","GCN","layer",".","If","not","specified",",","the","default","value","will","be","[","64",",","64","]",".","activation",":","callable","The","activation","function","to","apply","to","the","output","of","each","GCN","layer",".","By","default",",","no","activation","function","will","be","applied",".","residual",":","bool","Whether","to","add","a","residual","connection","within","each","GCN","layer",".","Default","to","True",".","batchnorm",":","bool","Whether","to","apply","batch","normalization","to","the","output","of","each","GCN","layer",".","Default","to","False",".","dropout",":","float","The","dropout","probability","for","the","output","of","each","GCN","layer",".","Default","to","0.","predictor_hidden_feats",":","int","The","size","for","hidden","representations","in","the","output","MLP","predictor",".","Default","to","128.","predictor_dropout",":","float","The","dropout","probability","in","the","output","MLP","predictor",".","Default","to","0.","mode",":","str","The","model","type",",","'classification","'","or","'regression","'",".","Default","to","'regression","'",".","number_atom_features",":","int","The","length","of","the","initial","atom","feature","vectors",".","Default","to","30.","n_classes",":","int","The","number","of","classes","to","predict","per","task","(","only","used","when","``","mode","``","is","'classification","'",")",".","Default","to","2.","self_loop",":","bool","Whether","to","add","self","loops","for","the","nodes",",","i.e",".","edges","from","nodes","to","themselves",".","When","input","graphs","have","isolated","nodes",",","self","loops","allow","preserving","the","original","feature","of","them","in","message","passing",".","Default","to","True",".","kwargs","This","can","include","any","keyword","argument","of","TorchModel","."]
code: def __init__(
      self,
      n_tasks: int,
      graph_conv_layers: Optional[list] = None,
      activation=None,
      residual: bool = True,
      batchnorm: bool = False,
      dropout: float = 0.0,
      predictor_hidden_feats: int = 128,
      predictor_dropout: float = 0.0,
      mode: str = "regression",
      number_atom_features=30,
      n_classes: int = 2,
      self_loop: bool = True,
      **kwargs,
  ):
      """
      Parameters
      ----------
      n_tasks: int
          Number of tasks.
      graph_conv_layers: list of int
          Width of channels for GCN layers. graph_conv_layers[i] gives the width of channel
          for the i-th GCN layer. If not specified, the default value will be [64, 64].
      activation: callable
          The activation function to apply to the output of each GCN layer.
          By default, no activation function will be applied.
      residual: bool
          Whether to add a residual connection within each GCN layer. Default to True.
      batchnorm: bool
          Whether to apply batch normalization to the output of each GCN layer.
          Default to False.
      dropout: float
          The dropout probability for the output of each GCN layer. Default to 0.
      predictor_hidden_feats: int
          The size for hidden representations in the output MLP predictor. Default to 128.
      predictor_dropout: float
          The dropout probability in the output MLP predictor. Default to 0.
      mode: str
          The model type, 'classification' or 'regression'. Default to 'regression'.
      number_atom_features: int
          The length of the initial atom feature vectors. Default to 30.
      n_classes: int
          The number of classes to predict per task
          (only used when ``mode`` is 'classification'). Default to 2.
      self_loop: bool
          Whether to add self loops for the nodes, i.e. edges from nodes to themselves.
          When input graphs have isolated nodes, self loops allow preserving the original feature
          of them in message passing. Default to True.
      kwargs
          This can include any keyword argument of TorchModel.
      """
      model = GCN(
          n_tasks=n_tasks,
          graph_conv_layers=graph_conv_layers,
          activation=activation,
          residual=residual,
          batchnorm=batchnorm,
          dropout=dropout,
          predictor_hidden_feats=predictor_hidden_feats,
          predictor_dropout=predictor_dropout,
          mode=mode,
          number_atom_features=number_atom_features,
          n_classes=n_classes,
      )
      if mode == "regression":
          loss: Loss = L2Loss()
          output_types = ["prediction"]
      else:
          loss = SparseSoftmaxCrossEntropy()
          output_types = ["prediction", "loss"]
      super(GCNModel, self).__init__(
          model, loss=loss, output_types=output_types, **kwargs
      )
  
      self._self_loop = self_loop
  
file_path: deepchem/deepchem/models/torch_models/gcn.py
imports: import torch.nn
  import torch.nn.functional
  from deepchem.models.losses import Loss, L2Loss, SparseSoftmaxCrossEntropy
  from deepchem.models.torch_models.torch_model import TorchModel
  from typing import Optional
label_desc: Use image node_id 1 to create a new GCNModel object from inherited base classes: TorchModel with example: obj = GCNModel(n_tasks, graph_conv_layers, activation, residual, batchnorm, dropout, predictor_hidden_feats, predictor_dropout, mode, number_atom_features, n_classes, _loop)