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: Create batch data for GCN.
  
  Parameters
  ----------
  batch: tuple
      The tuple is ``(inputs, labels, weights)``.
  
  Returns
  -------
  inputs: DGLGraph
      DGLGraph for a batch of graphs.
  labels: list of torch.Tensor or None
      The graph labels.
  weights: list of torch.Tensor or None
      The weights for each sample or sample/task pair converted to torch.Tensor.
docstr_tok: ["Create","batch","data","for","GCN",".","Parameters","--","--","--","--","--","batch",":","tuple","The","tuple","is","``","(","inputs",",","labels",",","weights",")","``",".","Returns","--","--","--","-","inputs",":","DGLGraph","DGLGraph","for","a","batch","of","graphs",".","labels",":","list","of","torch.Tensor","or","None","The","graph","labels",".","weights",":","list","of","torch.Tensor","or","None","The","weights","for","each","sample","or","sample\/task","pair","converted","to","torch.Tensor","."]
code: def _prepare_batch(self, batch):
      """Create batch data for GCN.
  
      Parameters
      ----------
      batch: tuple
          The tuple is ``(inputs, labels, weights)``.
  
      Returns
      -------
      inputs: DGLGraph
          DGLGraph for a batch of graphs.
      labels: list of torch.Tensor or None
          The graph labels.
      weights: list of torch.Tensor or None
          The weights for each sample or sample/task pair converted to torch.Tensor.
      """
      try:
          import dgl
      except:
          raise ImportError("This class requires dgl.")
  
      inputs, labels, weights = batch
      dgl_graphs = [
          graph.to_dgl_graph(self_loop=self._self_loop)
          for graph in inputs[0]
      ]
      inputs = dgl.batch(dgl_graphs).to(self.device)
      _, labels, weights = super(GCNModel, self)._prepare_batch(
          ([], labels, weights)
      )
      return inputs, labels, weights
  
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 2 for calling the GCNModel obj's underlying member method code with example usage: obj._prepare_batch(batch) and returns: inputs,  labels,  weights