class_docstr: A Convolutional neural network on smiles strings
  
  Reimplementation of the discriminator module in ORGAN [1]_ .
  Originated from [2]_.
  
  This model applies multiple 1D convolutional filters to
  the padded strings, then max-over-time pooling is applied on
  all filters, extracting one feature per filter.  All
  features are concatenated and transformed through several
  hidden layers to form predictions.
  
  This model is initially developed for sentence-level
  classification tasks, with words represented as vectors. In
  this implementation, SMILES strings are dissected into
  characters and transformed to one-hot vectors in a similar
  way. The model can be used for general molecular-level
  classification or regression tasks. It is also used in the
  ORGAN model as discriminator.
  
  Training of the model only requires SMILES strings input,
  all featurized datasets that include SMILES in the `ids`
  attribute are accepted. PDBbind, QM7 and QM7b are not
  supported. To use the model, `build_char_dict` should be
  called first before defining the model to build character
  dict of input dataset, example can be found in
  examples/delaney/delaney_textcnn.py
  
  References
  ----------
  .. [1]  Guimaraes, Gabriel Lima, et al. "Objective-reinforced generative adversarial networks (ORGAN) for sequence generation models." arXiv preprint arXiv:1705.10843 (2017).
  .. [2] Kim, Yoon. "Convolutional neural networks for sentence classification." arXiv preprint arXiv:1408.5882 (2014).
class_docstr_tok: ["A","Convolutional","neural","network","on","smiles","strings","Reimplementation","of","the","discriminator","module","in","ORGAN","[","1","]","_",".","Originated","from","[","2","]","_",".","This","model","applies","multiple","1D","convolutional","filters","to","the","padded","strings",",","then","max-over-time","pooling","is","applied","on","all","filters",",","extracting","one","feature","per","filter",".","All","features","are","concatenated","and","transformed","through","several","hidden","layers","to","form","predictions",".","This","model","is","initially","developed","for","sentence-level","classification","tasks",",","with","words","represented","as","vectors",".","In","this","implementation",",","SMILES","strings","are","dissected","into","characters","and","transformed","to","one-hot","vectors","in","a","similar","way",".","The","model","can","be","used","for","general","molecular-level","classification","or","regression","tasks",".","It","is","also","used","in","the","ORGAN","model","as","discriminator",".","Training","of","the","model","only","requires","SMILES","strings","input",",","all","featurized","datasets","that","include","SMILES","in","the","`","ids","`","attribute","are","accepted",".","PDBbind",",","QM7","and","QM7b","are","not","supported",".","To","use","the","model",",","`","build_char_dict","`","should","be","called","first","before","defining","the","model","to","build","character","dict","of","input","dataset",",","example","can","be","found","in","examples\/delaney\/delaney_textcnn.py","References","--","--","--","--","--","..","[","1","]","Guimaraes",",","Gabriel","Lima",",","et","al",".","``","Objective-reinforced","generative","adversarial","networks","(","ORGAN",")","for","sequence","generation","models",".","''","arXiv","preprint","arXiv:1705.10843","(","2017",")",".","..","[","2","]","Kim",",","Yoon",".","``","Convolutional","neural","networks","for","sentence","classification",".","''","arXiv","preprint","arXiv:1408.5882","(","2014",")","."]
docstr: Collect all unique characters(in smiles) from the dataset.
  This method should be called before defining the model to build appropriate char_dict
docstr_tok: ["Collect","all","unique","characters","(","in","smiles",")","from","the","dataset",".","This","method","should","be","called","before","defining","the","model","to","build","appropriate","char_dict"]
code: def build_char_dict(dataset, default_dict=default_dict):
      """Collect all unique characters(in smiles) from the dataset.
      This method should be called before defining the model to build appropriate char_dict
      """
      # SMILES strings
      X = dataset.ids
      # Maximum length is expanded to allow length variation during train and inference
      seq_length = int(max([len(smile) for smile in X]) * 1.2)
      # '_' served as delimiter and padding
      all_smiles = "_".join(X)
      tot_len = len(all_smiles)
      # Initialize common characters as keys
      keys = list(default_dict.keys())
      out_dict = copy.deepcopy(default_dict)
      current_key_val = len(keys) + 1
      # Include space to avoid extra keys
      keys.extend([" "])
      extra_keys = []
      i = 0
      while i < tot_len:
          # For 'Cl', 'Br', etc.
          if all_smiles[i : i + 2] in keys:
              i = i + 2
          elif all_smiles[i : i + 1] in keys:
              i = i + 1
          else:
              # Character not recognized, add to extra_keys
              extra_keys.append(all_smiles[i])
              keys.append(all_smiles[i])
              i = i + 1
      # Add all extra_keys to char_dict
      for extra_key in extra_keys:
          out_dict[extra_key] = current_key_val
          current_key_val += 1
      return out_dict, seq_length
  
file_path: deepchem/deepchem/models/text_cnn.py
imports: import numpy
  import tensorflow
  import copy
  import sys
  from deepchem.metrics import to_one_hot
  from deepchem.models import KerasModel, layers
  from deepchem.models.losses import L2Loss, SoftmaxCrossEntropy
  from tensorflow.keras.layers import Input, Dense, Reshape, Softmax, Dropout, Conv1D, Concatenate, Lambda
  import warnings
label_desc: Use image node_id 2 for calling the TextCNNModel obj's underlying member method code with example usage: obj.build_char_dict(dataset, default_dict) and returns: out_dict,  seq_length