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: Parameters
  ----------
  char_to_idx: dict,
      char_to_idx contains character to index mapping for SMILES characters
  embedding_dim: int, default 50
      Size of character embeddings used.
  use_bidir: bool, default True
      Whether to use BiDirectional RNN Cells
  use_conv: bool, default True
      Whether to use a conv-layer
  kernel_size: int, default 3
      Kernel size for convolutions
  filters: int, default 192
      Number of filters
  strides: int, default 1
      Strides used in convolution
  rnn_sizes: list[int], default [224, 384]
      Number of hidden units in the RNN cells
  mode: str, default regression
      Whether to use model for regression or classification
docstr_tok: ["Parameters","--","--","--","--","--","char_to_idx",":","dict",",","char_to_idx","contains","character","to","index","mapping","for","SMILES","characters","embedding_dim",":","int",",","default","50","Size","of","character","embeddings","used",".","use_bidir",":","bool",",","default","True","Whether","to","use","BiDirectional","RNN","Cells","use_conv",":","bool",",","default","True","Whether","to","use","a","conv-layer","kernel_size",":","int",",","default","3","Kernel","size","for","convolutions","filters",":","int",",","default","192","Number","of","filters","strides",":","int",",","default","1","Strides","used","in","convolution","rnn_sizes",":","list","[","int","]",",","default","[","224",",","384","]","Number","of","hidden","units","in","the","RNN","cells","mode",":","str",",","default","regression","Whether","to","use","model","for","regression","or","classification"]
code: def __init__(
      self,
      char_to_idx,
      n_tasks=10,
      max_seq_len=270,
      embedding_dim=50,
      n_classes=2,
      use_bidir=True,
      use_conv=True,
      filters=192,
      kernel_size=3,
      strides=1,
      rnn_sizes=[224, 384],
      rnn_types=["GRU", "GRU"],
      mode="regression",
      **kwargs,
  ):
      """
      Parameters
      ----------
      char_to_idx: dict,
          char_to_idx contains character to index mapping for SMILES characters
      embedding_dim: int, default 50
          Size of character embeddings used.
      use_bidir: bool, default True
          Whether to use BiDirectional RNN Cells
      use_conv: bool, default True
          Whether to use a conv-layer
      kernel_size: int, default 3
          Kernel size for convolutions
      filters: int, default 192
          Number of filters
      strides: int, default 1
          Strides used in convolution
      rnn_sizes: list[int], default [224, 384]
          Number of hidden units in the RNN cells
      mode: str, default regression
          Whether to use model for regression or classification
      """
  
      self.char_to_idx = char_to_idx
      self.n_classes = n_classes
      self.max_seq_len = max_seq_len
      self.embedding_dim = embedding_dim
      self.use_bidir = use_bidir
      self.use_conv = use_conv
      if use_conv:
          self.kernel_size = kernel_size
          self.filters = filters
          self.strides = strides
      self.rnn_types = rnn_types
      self.rnn_sizes = rnn_sizes
      assert len(rnn_sizes) == len(
          rnn_types
      ), "Should have same number of hidden units as RNNs"
      self.n_tasks = n_tasks
      self.mode = mode
  
      model, loss, output_types = self._build_graph()
      super(Smiles2Vec, self).__init__(
          model=model, loss=loss, output_types=output_types, **kwargs
      )
  
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 1 to create a new Smiles2Vec object from inherited base classes: KerasModel with example: obj = Smiles2Vec(char_to_idx, n_tasks, max_seq_len, embedding_dim, n_classes, use_bidir, use_conv, filters, kernel_size, strides, rnn_sizes, rnn_types, mode)