class_docstr: Directed Message Passing Neural Network
  
  This class implements the Directed Message Passing Neural Network (D-MPNN) [1]_.
  
  The DMPNN model has 2 phases, message-passing phase and read-out phase.
  
  - The goal of the message-passing phase is to generate 'hidden states of all the atoms in the molecule' using encoders.
  - Next in read-out phase, the features are passed into feed-forward neural network to get the task-based prediction.
  
  For additional information:
  
  - `Mapper class <https://github.com/deepchem/deepchem/blob/31676cc2497d5f2de65d648c09fc86191b594501/deepchem/models/torch_models/dmpnn.py#L10-L92>`_
  - `Encoder layer class <https://github.com/deepchem/deepchem/blob/31676cc2497d5f2de65d648c09fc86191b594501/deepchem/models/torch_models/layers.py#L1223-L1374>`_
  - `Feed-Forward class <https://github.com/deepchem/deepchem/blob/31676cc2497d5f2de65d648c09fc86191b594501/deepchem/models/torch_models/layers.py#L689-L700>`_
  
  Example
  -------
  >>> import deepchem as dc
  >>> import os
  >>> model_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  >>> input_file = os.path.join(model_dir, 'tests/assets/freesolv_sample_5.csv')
  >>> loader = dc.data.CSVLoader(tasks=['y'], feature_field='smiles', featurizer=dc.feat.DMPNNFeaturizer())
  >>> dataset = loader.create_dataset(input_file)
  >>> model = DMPNNModel()
  >>> out = model.fit(dataset, nb_epoch=1)
  
  References
  ----------
  .. [1] Analyzing Learned Molecular Representations for Property Prediction https://arxiv.org/pdf/1904.01561.pdf
class_docstr_tok: ["Directed","Message","Passing","Neural","Network","This","class","implements","the","Directed","Message","Passing","Neural","Network","(","D-MPNN",")","[","1","]","_",".","The","DMPNN","model","has","2","phases",",","message-passing","phase","and","read-out","phase",".","-","The","goal","of","the","message-passing","phase","is","to","generate","'hidden","states","of","all","the","atoms","in","the","molecule","'","using","encoders",".","-","Next","in","read-out","phase",",","the","features","are","passed","into","feed-forward","neural","network","to","get","the","task-based","prediction",".","For","additional","information",":","-","`","Mapper","class","<","https",":","\/\/github.com\/deepchem\/deepchem\/blob\/31676cc2497d5f2de65d648c09fc86191b594501\/deepchem\/models\/torch_models\/dmpnn.py","#","L10-L92",">","`","_","-","`","Encoder","layer","class","<","https",":","\/\/github.com\/deepchem\/deepchem\/blob\/31676cc2497d5f2de65d648c09fc86191b594501\/deepchem\/models\/torch_models\/layers.py","#","L1223-L1374",">","`","_","-","`","Feed-Forward","class","<","https",":","\/\/github.com\/deepchem\/deepchem\/blob\/31676cc2497d5f2de65d648c09fc86191b594501\/deepchem\/models\/torch_models\/layers.py","#","L689-L700",">","`","_","Example","--","--","--","-",">",">",">","import","deepchem","as","dc",">",">",">","import","os",">",">",">","model_dir","=","os.path.dirname","(","os.path.dirname","(","os.path.abspath","(","__file__",")",")",")",">",">",">","input_file","=","os.path.join","(","model_dir",",","'tests\/assets\/freesolv_sample_5.csv","'",")",">",">",">","loader","=","dc.data.CSVLoader","(","tasks=","[","'","y","'","]",",","feature_field='smiles","'",",","featurizer=dc.feat.DMPNNFeaturizer","(",")",")",">",">",">","dataset","=","loader.create_dataset","(","input_file",")",">",">",">","model","=","DMPNNModel","(",")",">",">",">","out","=","model.fit","(","dataset",",","nb_epoch=1",")","References","--","--","--","--","--","..","[","1","]","Analyzing","Learned","Molecular","Representations","for","Property","Prediction","https",":","\/\/arxiv.org\/pdf\/1904.01561.pdf"]
docstr: Method to prepare pytorch-geometric batches from inputs.
  
  Overrides the existing ``_prepare_batch`` method to customize how model batches are
  generated from the inputs.
  
  .. note::
      This method requires PyTorch Geometric to be installed.
  
  Parameters
  ----------
  batch: Tuple[List, List, List]
      batch data from ``default_generator``
  
  Returns
  -------
  Tuple[Batch, List[torch.Tensor], List[torch.Tensor]]
docstr_tok: ["Method","to","prepare","pytorch-geometric","batches","from","inputs",".","Overrides","the","existing","``","_prepare_batch","``","method","to","customize","how","model","batches","are","generated","from","the","inputs",".","..","note",":",":","This","method","requires","PyTorch","Geometric","to","be","installed",".","Parameters","--","--","--","--","--","batch",":","Tuple","[","List",",","List",",","List","]","batch","data","from","``","default_generator","``","Returns","--","--","--","-","Tuple","[","Batch",",","List","[","torch.Tensor","]",",","List","[","torch.Tensor","]","]"]
code: def _prepare_batch(
      self, batch: Tuple[List, List, List]
  ) -> Tuple[Batch, List[torch.Tensor], List[torch.Tensor]]:
      """Method to prepare pytorch-geometric batches from inputs.
  
      Overrides the existing ``_prepare_batch`` method to customize how model batches are
      generated from the inputs.
  
      .. note::
          This method requires PyTorch Geometric to be installed.
  
      Parameters
      ----------
      batch: Tuple[List, List, List]
          batch data from ``default_generator``
  
      Returns
      -------
      Tuple[Batch, List[torch.Tensor], List[torch.Tensor]]
      """
      graphs_list: List
      labels: List
      weights: List
  
      graphs_list, labels, weights = batch
      pyg_batch: Batch = Batch()
      pyg_batch = pyg_batch.from_data_list(graphs_list)
  
      _, labels, weights = super(DMPNNModel, self)._prepare_batch(
          ([], labels, weights)
      )
      return pyg_batch, labels, weights
  
imports: import numpy
  import torch
  import torch.nn
  from deepchem.models.losses import Loss, L2Loss, SparseSoftmaxCrossEntropy
  from deepchem.models.torch_models import layers
  from deepchem.models.torch_models import TorchModel
  from torch_geometric.data import Data, Batch
  from deepchem.feat import GraphData
  from deepchem.data import Dataset
  from typing import Union, List, Sequence, Optional, Iterable, Tuple
label_desc: Use image node_id 3 for calling the DMPNNModel obj's underlying member method code with example usage: obj._prepare_batch(batch) and returns: pyg_batch,  labels,  weights