class_docstr: Implements the Smiles2Vec model, that learns neural representations of SMILES
  strings which can be used for downstream tasks.
  
  The model is based on the description in Goh et al., "SMILES2vec: An
  Interpretable General-Purpose Deep Neural Network for Predicting Chemical
  Properties" (https://arxiv.org/pdf/1712.02034.pdf). The goal here is to take
  SMILES strings as inputs, turn them into vector representations which can then
  be used in predicting molecular properties.
  
  The model consists of an Embedding layer that retrieves embeddings for each
  character in the SMILES string. These embeddings are learnt jointly with the
  rest of the model. The output from the embedding layer is a tensor of shape
  (batch_size, seq_len, embedding_dim). This tensor can optionally be fed
  through a 1D convolutional layer, before being passed to a series of RNN cells
  (optionally bidirectional). The final output from the RNN cells aims
  to have learnt the temporal dependencies in the SMILES string, and in turn
  information about the structure of the molecule, which is then used for
  molecular property prediction.
  
  In the paper, the authors also train an explanation mask to endow the model
  with interpretability and gain insights into its decision making. This segment
  is currently not a part of this implementation as this was
  developed for the purpose of investigating a transfer learning protocol,
  ChemNet (which can be found at https://arxiv.org/abs/1712.02734).
class_docstr_tok: ["Implements","the","Smiles2Vec","model",",","that","learns","neural","representations","of","SMILES","strings","which","can","be","used","for","downstream","tasks",".","The","model","is","based","on","the","description","in","Goh","et","al.",",","``","SMILES2vec",":","An","Interpretable","General-Purpose","Deep","Neural","Network","for","Predicting","Chemical","Properties","''","(","https",":","\/\/arxiv.org\/pdf\/1712.02034.pdf",")",".","The","goal","here","is","to","take","SMILES","strings","as","inputs",",","turn","them","into","vector","representations","which","can","then","be","used","in","predicting","molecular","properties",".","The","model","consists","of","an","Embedding","layer","that","retrieves","embeddings","for","each","character","in","the","SMILES","string",".","These","embeddings","are","learnt","jointly","with","the","rest","of","the","model",".","The","output","from","the","embedding","layer","is","a","tensor","of","shape","(","batch_size",",","seq_len",",","embedding_dim",")",".","This","tensor","can","optionally","be","fed","through","a","1D","convolutional","layer",",","before","being","passed","to","a","series","of","RNN","cells","(","optionally","bidirectional",")",".","The","final","output","from","the","RNN","cells","aims","to","have","learnt","the","temporal","dependencies","in","the","SMILES","string",",","and","in","turn","information","about","the","structure","of","the","molecule",",","which","is","then","used","for","molecular","property","prediction",".","In","the","paper",",","the","authors","also","train","an","explanation","mask","to","endow","the","model","with","interpretability","and","gain","insights","into","its","decision","making",".","This","segment","is","currently","not","a","part","of","this","implementation","as","this","was","developed","for","the","purpose","of","investigating","a","transfer","learning","protocol",",","ChemNet","(","which","can","be","found","at","https",":","\/\/arxiv.org\/abs\/1712.02734",")","."]
docstr: Build the model.
docstr_tok: ["Build","the","model","."]
code: def _build_graph(self):
      """Build the model."""
      smiles_seqs = Input(
          dtype=tf.int32, shape=(self.max_seq_len,), name="Input"
      )
      rnn_input = tf.keras.layers.Embedding(
          input_dim=len(self.char_to_idx), output_dim=self.embedding_dim
      )(smiles_seqs)
  
      if self.use_conv:
          rnn_input = Conv1D(
              filters=self.filters,
              kernel_size=self.kernel_size,
              strides=self.strides,
              activation=tf.nn.relu,
              name="Conv1D",
          )(rnn_input)
  
      rnn_embeddings = rnn_input
      for idx, rnn_type in enumerate(self.rnn_types[:-1]):
          rnn_layer = RNN_DICT[rnn_type]
          layer = rnn_layer(
              units=self.rnn_sizes[idx], return_sequences=True
          )
          if self.use_bidir:
              layer = Bidirectional(layer)
  
          rnn_embeddings = layer(rnn_embeddings)
  
      # Last layer sequences not returned.
      layer = RNN_DICT[self.rnn_types[-1]](units=self.rnn_sizes[-1])
      if self.use_bidir:
          layer = Bidirectional(layer)
      rnn_embeddings = layer(rnn_embeddings)
  
      if self.mode == "classification":
          logits = Dense(self.n_tasks * self.n_classes)(rnn_embeddings)
          logits = Reshape((self.n_tasks, self.n_classes))(logits)
          if self.n_classes == 2:
              output = Activation(activation="sigmoid")(logits)
              loss = SigmoidCrossEntropy()
          else:
              output = Softmax()(logits)
              loss = SoftmaxCrossEntropy()
          outputs = [output, logits]
          output_types = ["prediction", "loss"]
  
      else:
          output = Dense(self.n_tasks * 1, name="Dense")(rnn_embeddings)
          output = Reshape((self.n_tasks, 1), name="Reshape")(output)
          outputs = [output]
          output_types = ["prediction"]
          loss = L2Loss()
  
      model = tf.keras.Model(inputs=[smiles_seqs], outputs=outputs)
      return model, loss, output_types
  
imports: import numpy
  import tensorflow
  from typing import Dict
  from deepchem.data.datasets import pad_batch
  from deepchem.models import KerasModel
  from deepchem.models.losses import L2Loss, SoftmaxCrossEntropy, SigmoidCrossEntropy
  from deepchem.metrics import to_one_hot
  from deepchem.models import chemnet_layers
  from tensorflow.keras.layers import Input, Dense, Reshape, Softmax, Activation
  from tensorflow.keras.layers import Conv1D, GRU, LSTM, Bidirectional
  from tensorflow.keras.layers import GlobalAveragePooling2D
label_desc: Use image node_id 2 for calling the Smiles2Vec obj's underlying member method code with example usage: obj._build_graph() and returns: model,  loss,  output_types