class_docstr: Implements Google-style Weave Graph Convolutions
  
  This model implements the Weave style graph convolutions
  from [1]_.
  
  The biggest difference between WeaveModel style convolutions
  and GraphConvModel style convolutions is that Weave
  convolutions model bond features explicitly. This has the
  side effect that it needs to construct a NxN matrix
  explicitly to model bond interactions. This may cause
  scaling issues, but may possibly allow for better modeling
  of subtle bond effects.
  
  Note that [1]_ introduces a whole variety of different architectures for
  Weave models. The default settings in this class correspond to the W2N2
  variant from [1]_ which is the most commonly used variant..
  
  Examples
  --------
  
  Here's an example of how to fit a `WeaveModel` on a tiny sample dataset.
  
  >>> import numpy as np
  >>> import deepchem as dc
  >>> featurizer = dc.feat.WeaveFeaturizer()
  >>> X = featurizer(["C", "CC"])
  >>> y = np.array([1, 0])
  >>> dataset = dc.data.NumpyDataset(X, y)
  >>> model = dc.models.WeaveModel(n_tasks=1, n_weave=2, fully_connected_layer_sizes=[2000, 1000], mode="classification")
  >>> loss = model.fit(dataset)
  
  Note
  ----
  In general, the use of batch normalization can cause issues with NaNs. If
  you're having trouble with NaNs while using this model, consider setting
  `batch_normalize_kwargs={"trainable": False}` or turning off batch
  normalization entirely with `batch_normalize=False`.
  
  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: ["Implements","Google-style","Weave","Graph","Convolutions","This","model","implements","the","Weave","style","graph","convolutions","from","[","1","]","_",".","The","biggest","difference","between","WeaveModel","style","convolutions","and","GraphConvModel","style","convolutions","is","that","Weave","convolutions","model","bond","features","explicitly",".","This","has","the","side","effect","that","it","needs","to","construct","a","NxN","matrix","explicitly","to","model","bond","interactions",".","This","may","cause","scaling","issues",",","but","may","possibly","allow","for","better","modeling","of","subtle","bond","effects",".","Note","that","[","1","]","_","introduces","a","whole","variety","of","different","architectures","for","Weave","models",".","The","default","settings","in","this","class","correspond","to","the","W2N2","variant","from","[","1","]","_","which","is","the","most","commonly","used","variant","..","Examples","--","--","--","--","Here","'s","an","example","of","how","to","fit","a","`","WeaveModel","`","on","a","tiny","sample","dataset",".",">",">",">","import","numpy","as","np",">",">",">","import","deepchem","as","dc",">",">",">","featurizer","=","dc.feat.WeaveFeaturizer","(",")",">",">",">","X","=","featurizer","(","[","``","C","''",",","``","CC","''","]",")",">",">",">","y","=","np.array","(","[","1",",","0","]",")",">",">",">","dataset","=","dc.data.NumpyDataset","(","X",",","y",")",">",">",">","model","=","dc.models.WeaveModel","(","n_tasks=1",",","n_weave=2",",","fully_connected_layer_sizes=","[","2000",",","1000","]",",","mode=","''","classification","''",")",">",">",">","loss","=","model.fit","(","dataset",")","Note","--","--","In","general",",","the","use","of","batch","normalization","can","cause","issues","with","NaNs",".","If","you","'re","having","trouble","with","NaNs","while","using","this","model",",","consider","setting","`","batch_normalize_kwargs=","{","``","trainable","''",":","False","}","`","or","turning","off","batch","normalization","entirely","with","`","batch_normalize=False","`",".","References","--","--","--","--","--","..","[","1","]","Kearnes",",","Steven",",","et","al",".","``","Molecular","graph","convolutions",":","moving","beyond","fingerprints",".","''","Journal","of","computer-aided","molecular","design","30.8","(","2016",")",":","595-608","."]
docstr: Compute tensors that will be input into the model from featurized representation.
  
  The featurized input to `WeaveModel` is instances of `WeaveMol` created by
  `WeaveFeaturizer`. This method converts input `WeaveMol` objects into
  tensors used by the Keras implementation to compute `WeaveModel` outputs.
  
  Parameters
  ----------
  X_b: np.ndarray
      A numpy array with dtype=object where elements are `WeaveMol` objects.
  
  Returns
  -------
  atom_feat: np.ndarray
      Of shape `(N_atoms, N_atom_feat)`.
  pair_feat: np.ndarray
      Of shape `(N_pairs, N_pair_feat)`. Note that `N_pairs` will depend on
      the number of pairs being considered. If `max_pair_distance` is
      `None`, then this will be `N_atoms**2`. Else it will be the number
      of pairs within the specifed graph distance.
  pair_split: np.ndarray
      Of shape `(N_pairs,)`. The i-th entry in this array will tell you the
      originating atom for this pair (the "source"). Note that pairs are
      symmetric so for a pair `(a, b)`, both `a` and `b` will separately be
      sources at different points in this array.
  atom_split: np.ndarray
      Of shape `(N_atoms,)`. The i-th entry in this array will be the molecule
      with the i-th atom belongs to.
  atom_to_pair: np.ndarray
      Of shape `(N_pairs, 2)`. The i-th row in this array will be the array
      `[a, b]` if `(a, b)` is a pair to be considered. (Note by symmetry, this
      implies some other row will contain `[b, a]`.
docstr_tok: ["Compute","tensors","that","will","be","input","into","the","model","from","featurized","representation",".","The","featurized","input","to","`","WeaveModel","`","is","instances","of","`","WeaveMol","`","created","by","`","WeaveFeaturizer","`",".","This","method","converts","input","`","WeaveMol","`","objects","into","tensors","used","by","the","Keras","implementation","to","compute","`","WeaveModel","`","outputs",".","Parameters","--","--","--","--","--","X_b",":","np.ndarray","A","numpy","array","with","dtype=object","where","elements","are","`","WeaveMol","`","objects",".","Returns","--","--","--","-","atom_feat",":","np.ndarray","Of","shape","`","(","N_atoms",",","N_atom_feat",")","`",".","pair_feat",":","np.ndarray","Of","shape","`","(","N_pairs",",","N_pair_feat",")","`",".","Note","that","`","N_pairs","`","will","depend","on","the","number","of","pairs","being","considered",".","If","`","max_pair_distance","`","is","`","None","`",",","then","this","will","be","`","N_atoms","*","*","2","`",".","Else","it","will","be","the","number","of","pairs","within","the","specifed","graph","distance",".","pair_split",":","np.ndarray","Of","shape","`","(","N_pairs",",",")","`",".","The","i-th","entry","in","this","array","will","tell","you","the","originating","atom","for","this","pair","(","the","``","source","''",")",".","Note","that","pairs","are","symmetric","so","for","a","pair","`","(","a",",","b",")","`",",","both","`","a","`","and","`","b","`","will","separately","be","sources","at","different","points","in","this","array",".","atom_split",":","np.ndarray","Of","shape","`","(","N_atoms",",",")","`",".","The","i-th","entry","in","this","array","will","be","the","molecule","with","the","i-th","atom","belongs","to",".","atom_to_pair",":","np.ndarray","Of","shape","`","(","N_pairs",",","2",")","`",".","The","i-th","row","in","this","array","will","be","the","array","`","[","a",",","b","]","`","if","`","(","a",",","b",")","`","is","a","pair","to","be","considered",".","(","Note","by","symmetry",",","this","implies","some","other","row","will","contain","`","[","b",",","a","]","`","."]
code: def compute_features_on_batch(self, X_b):
      """Compute tensors that will be input into the model from featurized representation.
  
      The featurized input to `WeaveModel` is instances of `WeaveMol` created by
      `WeaveFeaturizer`. This method converts input `WeaveMol` objects into
      tensors used by the Keras implementation to compute `WeaveModel` outputs.
  
      Parameters
      ----------
      X_b: np.ndarray
          A numpy array with dtype=object where elements are `WeaveMol` objects.
  
      Returns
      -------
      atom_feat: np.ndarray
          Of shape `(N_atoms, N_atom_feat)`.
      pair_feat: np.ndarray
          Of shape `(N_pairs, N_pair_feat)`. Note that `N_pairs` will depend on
          the number of pairs being considered. If `max_pair_distance` is
          `None`, then this will be `N_atoms**2`. Else it will be the number
          of pairs within the specifed graph distance.
      pair_split: np.ndarray
          Of shape `(N_pairs,)`. The i-th entry in this array will tell you the
          originating atom for this pair (the "source"). Note that pairs are
          symmetric so for a pair `(a, b)`, both `a` and `b` will separately be
          sources at different points in this array.
      atom_split: np.ndarray
          Of shape `(N_atoms,)`. The i-th entry in this array will be the molecule
          with the i-th atom belongs to.
      atom_to_pair: np.ndarray
          Of shape `(N_pairs, 2)`. The i-th row in this array will be the array
          `[a, b]` if `(a, b)` is a pair to be considered. (Note by symmetry, this
          implies some other row will contain `[b, a]`.
      """
      atom_feat = []
      pair_feat = []
      atom_split = []
      atom_to_pair = []
      pair_split = []
      start = 0
      for im, mol in enumerate(X_b):
          n_atoms = mol.get_num_atoms()
          # pair_edges is of shape (2, N)
          pair_edges = mol.get_pair_edges()
          # number of atoms in each molecule
          atom_split.extend([im] * n_atoms)
          # index of pair features
          C0, C1 = np.meshgrid(np.arange(n_atoms), np.arange(n_atoms))
          atom_to_pair.append(pair_edges.T + start)
          # Get starting pair atoms
          pair_starts = pair_edges.T[:, 0]
          # number of pairs for each atom
          pair_split.extend(pair_starts + start)
          start = start + n_atoms
  
          # atom features
          atom_feat.append(mol.get_atom_features())
          # pair features
          pair_feat.append(mol.get_pair_features())
  
      return (
          np.concatenate(atom_feat, axis=0),
          np.concatenate(pair_feat, axis=0),
          np.array(pair_split),
          np.array(atom_split),
          np.concatenate(atom_to_pair, axis=0),
      )
  
imports: from collections.abc import Sequence
  import deepchem
  import numpy
  import tensorflow
  from typing import List, Union, Tuple, Iterable, Dict, Optional
  from deepchem.utils.typing import OneOrMany, LossFn, ActivationFn
  from deepchem.data import Dataset, pad_features
  from deepchem.feat.mol_graphs import ConvMol
  from deepchem.metrics import to_one_hot
  from deepchem.models import KerasModel, layers
  from deepchem.models.losses import L2Loss, SoftmaxCrossEntropy, Loss
  from tensorflow.keras.layers import Input, Dense, Reshape, Softmax, Dropout, Activation, BatchNormalization
  import warnings
label_desc: Use image node_id 2 for calling the WeaveModel obj's underlying member method code with example usage: obj.compute_features_on_batch(X_b) and returns: np,  np,  np,  np,  np