class_docstr: An internal TorchModel class.
  
  In this class, we define the various layers and establish a sequential model for the Molecular Attention Transformer.
  We also define the forward call of this model in the forward function.
  
  References
  ----------
  .. [1] Lukasz Maziarka et al. "Molecule Attention Transformer" Graph Representation Learning workshop and Machine Learning and the Physical Sciences workshop at NeurIPS 2019. 2020. https://arxiv.org/abs/2002.08264
  
  Examples
  --------
  >>> import deepchem as dc
  >>> import pandas as pd
  >>> import numpy as np
  >>> smiles = ['CC', 'CCC',  'CCCC', 'CCCCC', 'CCCCCCC']
  >>> vals = [1.35, 6.72, 5.67, 1.23, 1.76]
  >>> df = pd.DataFrame(list(zip(smiles, vals)), columns = ['smiles', 'y'])
  >>> loader = dc.data.CSVLoader(tasks=['y'], feature_field='smiles', featurizer=dc.feat.MATFeaturizer())
  >>> df.to_csv('test.csv')
  >>> dataset = loader.create_dataset('test.csv')
  >>> model = dc.models.torch_models.MAT()
  >>> # To simulate input data, we will generate matrices for a single molecule.
  >>> vals = dataset.X[0]
  >>> node = vals.node_features
  >>> adj = vals.adjacency_matrix
  >>> dist = vals.distance_matrix
  >>> # We will now utilize a helper function defined in MATModel to get our matrices ready, and convert them into a batch consisting of a single molecule.
  >>> helper = dc.models.torch_models.MATModel()
  >>> node_features = helper.pad_sequence(torch.tensor(node).unsqueeze(0).float())
  >>> adjacency = helper.pad_sequence(torch.tensor(adj).unsqueeze(0).float())
  >>> distance = helper.pad_sequence(torch.tensor(dist).unsqueeze(0).float())
  >>> inputs = [node_features, adjacency, distance]
  >>> inputs = [x.astype(np.float32) if x.dtype == np.float64 else x for x in inputs]
  >>> # Get the forward call of the model for this batch.
  >>> output = model(inputs)
class_docstr_tok: ["An","internal","TorchModel","class",".","In","this","class",",","we","define","the","various","layers","and","establish","a","sequential","model","for","the","Molecular","Attention","Transformer",".","We","also","define","the","forward","call","of","this","model","in","the","forward","function",".","References","--","--","--","--","--","..","[","1","]","Lukasz","Maziarka","et","al",".","``","Molecule","Attention","Transformer","''","Graph","Representation","Learning","workshop","and","Machine","Learning","and","the","Physical","Sciences","workshop","at","NeurIPS","2019",".","2020.","https",":","\/\/arxiv.org\/abs\/2002.08264","Examples","--","--","--","--",">",">",">","import","deepchem","as","dc",">",">",">","import","pandas","as","pd",">",">",">","import","numpy","as","np",">",">",">","smiles","=","[","'CC","'",",","'CCC","'",",","'CCCC","'",",","'CCCCC","'",",","'CCCCCCC","'","]",">",">",">","vals","=","[","1.35",",","6.72",",","5.67",",","1.23",",","1.76","]",">",">",">","df","=","pd.DataFrame","(","list","(","zip","(","smiles",",","vals",")",")",",","columns","=","[","'smiles","'",",","'","y","'","]",")",">",">",">","loader","=","dc.data.CSVLoader","(","tasks=","[","'","y","'","]",",","feature_field='smiles","'",",","featurizer=dc.feat.MATFeaturizer","(",")",")",">",">",">","df.to_csv","(","'test.csv","'",")",">",">",">","dataset","=","loader.create_dataset","(","'test.csv","'",")",">",">",">","model","=","dc.models.torch_models.MAT","(",")",">",">",">","#","To","simulate","input","data",",","we","will","generate","matrices","for","a","single","molecule",".",">",">",">","vals","=","dataset.X","[","0","]",">",">",">","node","=","vals.node_features",">",">",">","adj","=","vals.adjacency_matrix",">",">",">","dist","=","vals.distance_matrix",">",">",">","#","We","will","now","utilize","a","helper","function","defined","in","MATModel","to","get","our","matrices","ready",",","and","convert","them","into","a","batch","consisting","of","a","single","molecule",".",">",">",">","helper","=","dc.models.torch_models.MATModel","(",")",">",">",">","node_features","=","helper.pad_sequence","(","torch.tensor","(","node",")",".unsqueeze","(","0",")",".float","(",")",")",">",">",">","adjacency","=","helper.pad_sequence","(","torch.tensor","(","adj",")",".unsqueeze","(","0",")",".float","(",")",")",">",">",">","distance","=","helper.pad_sequence","(","torch.tensor","(","dist",")",".unsqueeze","(","0",")",".float","(",")",")",">",">",">","inputs","=","[","node_features",",","adjacency",",","distance","]",">",">",">","inputs","=","[","x.astype","(","np.float32",")","if","x.dtype","==","np.float64","else","x","for","x","in","inputs","]",">",">",">","#","Get","the","forward","call","of","the","model","for","this","batch",".",">",">",">","output","=","model","(","inputs",")"]
code: def forward(self, data: np.ndarray, **kwargs):
      node_features = torch.tensor(data[0]).float()
      adjacency_matrix = torch.tensor(data[1]).float()
      distance_matrix = torch.tensor(data[2]).float()
  
      mask = torch.sum(torch.abs(node_features), dim=-1) != 0
      output = self.embedding(node_features)
  
      for layer in self.encoder:
          output = layer(
              output, mask, adjacency_matrix, distance_matrix
          )
      output = self.generator(output, mask)
      return output
  
file_path: deepchem/deepchem/models/torch_models/mat.py
imports: import torch
  import torch.nn
  import numpy
  from deepchem.models.torch_models import layers
  from deepchem.models.torch_models.torch_model import TorchModel
  from deepchem.models.losses import L2Loss
  from typing import Any
label_desc: Use image node_id 2 for calling the MAT obj's underlying member method code with example usage: obj.forward(data) and returns: output