class_docstr: A graph convolutional network(GCN) for either classification or regression.
  The network consists of the following sequence of layers:
  
  - Weave feature modules
  
  - Final convolution
  
  - Weave Gather Layer
  
  - A fully connected layer
  
  - A Softmax layer
  
  Example
  --------
  >>> import numpy as np
  >>> import deepchem as dc
  >>> featurizer = dc.feat.WeaveFeaturizer()
  >>> X = featurizer(["C", "CC"])
  >>> y = np.array([1, 0])
  >>> batch_size = 2
  >>> weavemodel = dc.models.WeaveModel(n_tasks=1,n_weave=2, fully_connected_layer_sizes=[2000, 1000],mode="classification",batch_size=batch_size)
  >>> atom_feat, pair_feat, pair_split, atom_split, atom_to_pair = weavemodel.compute_features_on_batch(X)
  >>> model = Weave(n_tasks=1,n_weave=2,fully_connected_layer_sizes=[2000, 1000],mode="classification")
  >>> input_data = [atom_feat, pair_feat, pair_split, atom_split, atom_to_pair]
  >>> output = model(input_data)
  
  References
  ----------
  .. [1] Kearnes, Steven, et al. "Molecular graph convolutions: moving beyond
      fingerprints." Journal of computer-aided molecular design 30.8 (2016):
      595-608.
class_docstr_tok: ["A","graph","convolutional","network","(","GCN",")","for","either","classification","or","regression",".","The","network","consists","of","the","following","sequence","of","layers",":","-","Weave","feature","modules","-","Final","convolution","-","Weave","Gather","Layer","-","A","fully","connected","layer","-","A","Softmax","layer","Example","--","--","--","--",">",">",">","import","numpy","as","np",">",">",">","import","deepchem","as","dc",">",">",">","featurizer","=","dc.feat.WeaveFeaturizer","(",")",">",">",">","X","=","featurizer","(","[","``","C","''",",","``","CC","''","]",")",">",">",">","y","=","np.array","(","[","1",",","0","]",")",">",">",">","batch_size","=","2",">",">",">","weavemodel","=","dc.models.WeaveModel","(","n_tasks=1",",","n_weave=2",",","fully_connected_layer_sizes=","[","2000",",","1000","]",",","mode=","''","classification","''",",","batch_size=batch_size",")",">",">",">","atom_feat",",","pair_feat",",","pair_split",",","atom_split",",","atom_to_pair","=","weavemodel.compute_features_on_batch","(","X",")",">",">",">","model","=","Weave","(","n_tasks=1",",","n_weave=2",",","fully_connected_layer_sizes=","[","2000",",","1000","]",",","mode=","''","classification","''",")",">",">",">","input_data","=","[","atom_feat",",","pair_feat",",","pair_split",",","atom_split",",","atom_to_pair","]",">",">",">","output","=","model","(","input_data",")","References","--","--","--","--","--","..","[","1","]","Kearnes",",","Steven",",","et","al",".","``","Molecular","graph","convolutions",":","moving","beyond","fingerprints",".","''","Journal","of","computer-aided","molecular","design","30.8","(","2016",")",":","595-608","."]
docstr: Parameters
  ----------
  n_tasks: int
      Number of tasks
  n_atom_feat: int, optional (default 75)
      Number of features per atom. Note this is 75 by default and should be 78
      if chirality is used by `WeaveFeaturizer`.
  n_pair_feat: int, optional (default 14)
      Number of features per pair of atoms.
  n_hidden: int, optional (default 50)
      Number of units(convolution depths) in corresponding hidden layer
  n_graph_feat: int, optional (default 128)
      Number of output features for each molecule(graph)
  n_weave: int, optional (default 2)
      The number of weave layers in this model.
  fully_connected_layer_sizes: list (default `[2000, 100]`)
      The size of each dense layer in the network.  The length of
      this list determines the number of layers.
  conv_weight_init_stddevs: list or float (default 0.03)
      The standard deviation of the distribution to use for weight
      initialization of each convolutional layer. The length of this lisst
      should equal `n_weave`. Alternatively, this may be a single value instead
      of a list, in which case the same value is used for each layer.
  weight_init_stddevs: list or float (default 0.01)
      The standard deviation of the distribution to use for weight
      initialization of each fully connected layer.  The length of this list
      should equal len(layer_sizes).  Alternatively this may be a single value
      instead of a list, in which case the same value is used for every layer.
  bias_init_consts: list or float (default 0.0)
      The value to initialize the biases in each fully connected layer.  The
      length of this list should equal len(layer_sizes).
      Alternatively this may be a single value instead of a list, in
      which case the same value is used for every layer.
  dropouts: list or float (default 0.25)
      The dropout probablity to use for each fully connected layer.  The length of this list
      should equal len(layer_sizes).  Alternatively this may be a single value
      instead of a list, in which case the same value is used for every layer.
  final_conv_activation_fn: Optional[ActivationFn] (default `F.tanh`)
      The activation funcntion to apply to the final
      convolution at the end of the weave convolutions. If `None`, then no
      activate is applied (hence linear).
  activation_fns: str (default `relu`)
      The activation function to apply to each fully connected layer.  The length
      of this list should equal len(layer_sizes).  Alternatively this may be a
      single value instead of a list, in which case the same value is used for
      every layer.
  batch_normalize: bool, optional (default True)
      If this is turned on, apply batch normalization before applying
      activation functions on convolutional and fully connected layers.
  gaussian_expand: boolean, optional (default True)
      Whether to expand each dimension of atomic features by gaussian
      histogram
  compress_post_gaussian_expansion: bool, optional (default False)
      If True, compress the results of the Gaussian expansion back to the
      original dimensions of the input.
  mode: str (default "classification")
      Either "classification" or "regression" for type of model.
  n_classes: int (default 2)
      Number of classes to predict (only used in classification mode)
  batch_size: int (default 100)
      Batch size used by this model for training.
docstr_tok: ["Parameters","--","--","--","--","--","n_tasks",":","int","Number","of","tasks","n_atom_feat",":","int",",","optional","(","default","75",")","Number","of","features","per","atom",".","Note","this","is","75","by","default","and","should","be","78","if","chirality","is","used","by","`","WeaveFeaturizer","`",".","n_pair_feat",":","int",",","optional","(","default","14",")","Number","of","features","per","pair","of","atoms",".","n_hidden",":","int",",","optional","(","default","50",")","Number","of","units","(","convolution","depths",")","in","corresponding","hidden","layer","n_graph_feat",":","int",",","optional","(","default","128",")","Number","of","output","features","for","each","molecule","(","graph",")","n_weave",":","int",",","optional","(","default","2",")","The","number","of","weave","layers","in","this","model",".","fully_connected_layer_sizes",":","list","(","default","`","[","2000",",","100","]","`",")","The","size","of","each","dense","layer","in","the","network",".","The","length","of","this","list","determines","the","number","of","layers",".","conv_weight_init_stddevs",":","list","or","float","(","default","0.03",")","The","standard","deviation","of","the","distribution","to","use","for","weight","initialization","of","each","convolutional","layer",".","The","length","of","this","lisst","should","equal","`","n_weave","`",".","Alternatively",",","this","may","be","a","single","value","instead","of","a","list",",","in","which","case","the","same","value","is","used","for","each","layer",".","weight_init_stddevs",":","list","or","float","(","default","0.01",")","The","standard","deviation","of","the","distribution","to","use","for","weight","initialization","of","each","fully","connected","layer",".","The","length","of","this","list","should","equal","len","(","layer_sizes",")",".","Alternatively","this","may","be","a","single","value","instead","of","a","list",",","in","which","case","the","same","value","is","used","for","every","layer",".","bias_init_consts",":","list","or","float","(","default","0.0",")","The","value","to","initialize","the","biases","in","each","fully","connected","layer",".","The","length","of","this","list","should","equal","len","(","layer_sizes",")",".","Alternatively","this","may","be","a","single","value","instead","of","a","list",",","in","which","case","the","same","value","is","used","for","every","layer",".","dropouts",":","list","or","float","(","default","0.25",")","The","dropout","probablity","to","use","for","each","fully","connected","layer",".","The","length","of","this","list","should","equal","len","(","layer_sizes",")",".","Alternatively","this","may","be","a","single","value","instead","of","a","list",",","in","which","case","the","same","value","is","used","for","every","layer",".","final_conv_activation_fn",":","Optional","[","ActivationFn","]","(","default","`","F.tanh","`",")","The","activation","funcntion","to","apply","to","the","final","convolution","at","the","end","of","the","weave","convolutions",".","If","`","None","`",",","then","no","activate","is","applied","(","hence","linear",")",".","activation_fns",":","str","(","default","`","relu","`",")","The","activation","function","to","apply","to","each","fully","connected","layer",".","The","length","of","this","list","should","equal","len","(","layer_sizes",")",".","Alternatively","this","may","be","a","single","value","instead","of","a","list",",","in","which","case","the","same","value","is","used","for","every","layer",".","batch_normalize",":","bool",",","optional","(","default","True",")","If","this","is","turned","on",",","apply","batch","normalization","before","applying","activation","functions","on","convolutional","and","fully","connected","layers",".","gaussian_expand",":","boolean",",","optional","(","default","True",")","Whether","to","expand","each","dimension","of","atomic","features","by","gaussian","histogram","compress_post_gaussian_expansion",":","bool",",","optional","(","default","False",")","If","True",",","compress","the","results","of","the","Gaussian","expansion","back","to","the","original","dimensions","of","the","input",".","mode",":","str","(","default","``","classification","''",")","Either","``","classification","''","or","``","regression","''","for","type","of","model",".","n_classes",":","int","(","default","2",")","Number","of","classes","to","predict","(","only","used","in","classification","mode",")","batch_size",":","int","(","default","100",")","Batch","size","used","by","this","model","for","training","."]
code: def __init__(
      self,
      n_tasks: int,
      n_atom_feat: OneOrMany[int] = 75,
      n_pair_feat: OneOrMany[int] = 14,
      n_hidden: int = 50,
      n_graph_feat: int = 128,
      n_weave: int = 2,
      fully_connected_layer_sizes: List[int] = [2000, 100],
      conv_weight_init_stddevs: OneOrMany[float] = 0.03,
      weight_init_stddevs: OneOrMany[float] = 0.01,
      bias_init_consts: OneOrMany[float] = 0.0,
      dropouts: OneOrMany[float] = 0.25,
      final_conv_activation_fn=F.tanh,
      activation_fns: OneOrMany[ActivationFn] = "relu",
      batch_normalize: bool = True,
      gaussian_expand: bool = True,
      compress_post_gaussian_expansion: bool = False,
      mode: str = "classification",
      n_classes: int = 2,
      batch_size: int = 100,
  ):
      """
      Parameters
      ----------
      n_tasks: int
          Number of tasks
      n_atom_feat: int, optional (default 75)
          Number of features per atom. Note this is 75 by default and should be 78
          if chirality is used by `WeaveFeaturizer`.
      n_pair_feat: int, optional (default 14)
          Number of features per pair of atoms.
      n_hidden: int, optional (default 50)
          Number of units(convolution depths) in corresponding hidden layer
      n_graph_feat: int, optional (default 128)
          Number of output features for each molecule(graph)
      n_weave: int, optional (default 2)
          The number of weave layers in this model.
      fully_connected_layer_sizes: list (default `[2000, 100]`)
          The size of each dense layer in the network.  The length of
          this list determines the number of layers.
      conv_weight_init_stddevs: list or float (default 0.03)
          The standard deviation of the distribution to use for weight
          initialization of each convolutional layer. The length of this lisst
          should equal `n_weave`. Alternatively, this may be a single value instead
          of a list, in which case the same value is used for each layer.
      weight_init_stddevs: list or float (default 0.01)
          The standard deviation of the distribution to use for weight
          initialization of each fully connected layer.  The length of this list
          should equal len(layer_sizes).  Alternatively this may be a single value
          instead of a list, in which case the same value is used for every layer.
      bias_init_consts: list or float (default 0.0)
          The value to initialize the biases in each fully connected layer.  The
          length of this list should equal len(layer_sizes).
          Alternatively this may be a single value instead of a list, in
          which case the same value is used for every layer.
      dropouts: list or float (default 0.25)
          The dropout probablity to use for each fully connected layer.  The length of this list
          should equal len(layer_sizes).  Alternatively this may be a single value
          instead of a list, in which case the same value is used for every layer.
      final_conv_activation_fn: Optional[ActivationFn] (default `F.tanh`)
          The activation funcntion to apply to the final
          convolution at the end of the weave convolutions. If `None`, then no
          activate is applied (hence linear).
      activation_fns: str (default `relu`)
          The activation function to apply to each fully connected layer.  The length
          of this list should equal len(layer_sizes).  Alternatively this may be a
          single value instead of a list, in which case the same value is used for
          every layer.
      batch_normalize: bool, optional (default True)
          If this is turned on, apply batch normalization before applying
          activation functions on convolutional and fully connected layers.
      gaussian_expand: boolean, optional (default True)
          Whether to expand each dimension of atomic features by gaussian
          histogram
      compress_post_gaussian_expansion: bool, optional (default False)
          If True, compress the results of the Gaussian expansion back to the
          original dimensions of the input.
      mode: str (default "classification")
          Either "classification" or "regression" for type of model.
      n_classes: int (default 2)
          Number of classes to predict (only used in classification mode)
      batch_size: int (default 100)
          Batch size used by this model for training.
      """
      super(Weave, self).__init__()
      if mode not in ["classification", "regression"]:
          raise ValueError(
              "mode must be either 'classification' or 'regression'"
          )
  
      if not isinstance(n_atom_feat, SequenceCollection):
          n_atom_feat = [n_atom_feat] * n_weave
      if not isinstance(n_pair_feat, SequenceCollection):
          n_pair_feat = [n_pair_feat] * n_weave
      n_layers = len(fully_connected_layer_sizes)
      if not isinstance(conv_weight_init_stddevs, SequenceCollection):
          conv_weight_init_stddevs = [
              conv_weight_init_stddevs
          ] * n_weave
      if not isinstance(weight_init_stddevs, SequenceCollection):
          weight_init_stddevs = [weight_init_stddevs] * n_layers
      if not isinstance(bias_init_consts, SequenceCollection):
          bias_init_consts = [bias_init_consts] * n_layers
      if not isinstance(dropouts, SequenceCollection):
          dropouts = [dropouts] * n_layers
      if isinstance(activation_fns, str) or not isinstance(
          activation_fns, SequenceCollection
      ):
          activation_fns = [activation_fns] * n_layers
  
      self.n_tasks: int = n_tasks
      self.n_atom_feat: OneOrMany[int] = n_atom_feat
      self.n_pair_feat: OneOrMany[int] = n_pair_feat
      self.n_hidden: int = n_hidden
      self.n_graph_feat: int = n_graph_feat
      self.mode: str = mode
      self.n_classes: int = n_classes
      self.n_layers: int = n_layers
      self.fully_connected_layer_sizes: List[
          int
      ] = fully_connected_layer_sizes
      self.weight_init_stddevs: OneOrMany[float] = weight_init_stddevs
      self.bias_init_consts: OneOrMany[float] = bias_init_consts
      self.dropouts: Sequence[float] = dropouts
      self.activation_fns: OneOrMany[ActivationFn] = [
          get_activation(i) for i in activation_fns
      ]
      self.batch_normalize: bool = batch_normalize
      self.n_weave: int = n_weave
  
      torch.manual_seed(22)
      self.layers: nn.ModuleList = nn.ModuleList()
      for ind in range(n_weave):
          n_atom: int = self.n_atom_feat[ind]
          n_pair: int = self.n_pair_feat[ind]
          if ind < n_weave - 1:
              n_atom_next: int = self.n_atom_feat[ind + 1]
              n_pair_next: int = self.n_pair_feat[ind + 1]
          else:
              n_atom_next = n_hidden
              n_pair_next = n_hidden
          weave_layer = torch_layers.WeaveLayer(
              n_atom_input_feat=n_atom,
              n_pair_input_feat=n_pair,
              n_atom_output_feat=n_atom_next,
              n_pair_output_feat=n_pair_next,
              batch_normalize=batch_normalize,
          )
          nn.init.trunc_normal_(
              weave_layer.W_AA, 0, std=conv_weight_init_stddevs[ind]
          )
          nn.init.trunc_normal_(
              weave_layer.W_PA, 0, std=conv_weight_init_stddevs[ind]
          )
          nn.init.trunc_normal_(
              weave_layer.W_A, 0, std=conv_weight_init_stddevs[ind]
          )
          if weave_layer.update_pair:
              nn.init.trunc_normal_(
                  weave_layer.W_AP, 0, std=conv_weight_init_stddevs[ind]
              )
              nn.init.trunc_normal_(
                  weave_layer.W_PP, 0, std=conv_weight_init_stddevs[ind]
              )
              nn.init.trunc_normal_(
                  weave_layer.W_P, 0, std=conv_weight_init_stddevs[ind]
              )
          self.layers.append(weave_layer)
  
      self.dense1: nn.Linear = nn.Linear(n_hidden, self.n_graph_feat)
      self.dense1_act = final_conv_activation_fn
      self.dense1_bn: nn.BatchNorm1d = nn.BatchNorm1d(
          num_features=self.n_graph_feat,
          eps=1e-3,
          momentum=0.99,
          affine=True,
          track_running_stats=True,
      )
  
      self.weave_gather = torch_layers.WeaveGather(
          batch_size,
          n_input=self.n_graph_feat,
          gaussian_expand=gaussian_expand,
          compress_post_gaussian_expansion=compress_post_gaussian_expansion,
      )
  
      if n_layers > 0:
          self.layers2: nn.ModuleList = nn.ModuleList()
          in_size = self.n_graph_feat * 11
          for (
              ind,
              layer_size,
              weight_stddev,
              bias_const,
              dropout,
              activation_fn,
          ) in zip(
              [0, 1],
              fully_connected_layer_sizes,
              weight_init_stddevs,
              bias_init_consts,
              dropouts,
              self.activation_fns,
          ):
              self.layer: nn.Linear = nn.Linear(in_size, layer_size)
              nn.init.trunc_normal_(
                  self.layer.weight, 0, std=weight_stddev
              )
              if self.layer.bias is not None:
                  self.layer.bias = nn.Parameter(
                      torch.full(self.layer.bias.shape, bias_const)
                  )
              self.layer.layer_bn = nn.BatchNorm1d(
                  num_features=layer_size,
                  eps=1e-3,
                  momentum=0.99,
                  affine=True,
                  track_running_stats=True,
              )
              self.layer.weight_stddev = weight_stddev
              self.layer.bias_const = bias_const
              self.layer.dropout = nn.Dropout(dropout)
              self.layer.layer_act = activation_fn
              self.layers2.append(self.layer)
              in_size = layer_size
  
      n_tasks = self.n_tasks
      if self.mode == "classification":
          n_classes = self.n_classes
          self.layer_2 = nn.Linear(
              fully_connected_layer_sizes[1], n_tasks * n_classes
          )
  
      else:
          self.layer_2 = nn.Linear(
              fully_connected_layer_sizes[1], n_tasks
          )
  
file_path: deepchem/deepchem/models/torch_models/weavemodel_pytorch.py
imports: import numpy
  from collections.abc import Sequence
  from typing import List, Tuple, Iterable, Optional, Callable, Union, Sequence
  from deepchem.data import Dataset
  from deepchem.metrics import to_one_hot
  from deepchem.utils.typing import OneOrMany, ActivationFn
  from deepchem.models.losses import L2Loss, SoftmaxCrossEntropy
  from deepchem.models.torch_models.torch_model import TorchModel
  import deepchem.models.torch_models.layers
  from deepchem.utils.pytorch_utils import get_activation
label_desc: Use image node_id 1 to create a new Weave object from inherited base classes: nn with example: obj = Weave(n_tasks, n_atom_feat, n_pair_feat, n_hidden, n_graph_feat, n_weave, fully_connected_layer_sizes, conv_weight_init_stddevs, weight_init_stddevs, bias_init_consts, dropouts, final_conv_activation_fn, activation_fns, batch_normalize, gaussian_expand, compress_post_gaussian_expansion, mode, n_classes, batch_size)