class_docstr: Vocabulary class that loads vocabulary from file, and maintains mapping
  tables between token strings and indexes.
  
  Each line of the vocab file should contains one vocabulary token, e.g.,::
  
      vocab_token_1
      vocab token 2
      vocab       token | 3 .
      ...
  
  Args:
      filename (str): Path to the vocabulary file where each line contains
          one token.
      bos_token (str): A special token that will be added to the beginning of
          sequences.
      eos_token (str): A special token that will be added to the end of
          sequences.
      unk_token (str): A special token that will replace all unknown tokens
          (tokens not included in the vocabulary).
      pad_token (str): A special token that is used to do padding.
class_docstr_tok: ["Vocabulary","class","that","loads","vocabulary","from","file",",","and","maintains","mapping","tables","between","token","strings","and","indexes",".","Each","line","of","the","vocab","file","should","contains","one","vocabulary","token",",","e.g.",",",":",":","vocab_token_1","vocab","token","2","vocab","token","|","3",".","...","Args",":","filename","(","str",")",":","Path","to","the","vocabulary","file","where","each","line","contains","one","token",".","bos_token","(","str",")",":","A","special","token","that","will","be","added","to","the","beginning","of","sequences",".","eos_token","(","str",")",":","A","special","token","that","will","be","added","to","the","end","of","sequences",".","unk_token","(","str",")",":","A","special","token","that","will","replace","all","unknown","tokens","(","tokens","not","included","in","the","vocabulary",")",".","pad_token","(","str",")",":","A","special","token","that","is","used","to","do","padding","."]
docstr: Loads the vocabulary from the file.
  
  Args:
      filename (str): Path to the vocabulary file.
  
  Returns:
      A tuple of TF and python mapping tables between word string and
      index, (:attr:`id_to_token_map`, :attr:`token_to_id_map`,
      :attr:`id_to_token_map_py`, :attr:`token_to_id_map_py`), where
      :attr:`id_to_token_map` and :attr:`token_to_id_map` are
      TF :tf_main:`HashTable <contrib/lookup/HashTable>` instances,
      and :attr:`id_to_token_map_py` and
      :attr:`token_to_id_map_py` are python `defaultdict` instances.
docstr_tok: ["Loads","the","vocabulary","from","the","file",".","Args",":","filename","(","str",")",":","Path","to","the","vocabulary","file",".","Returns",":","A","tuple","of","TF","and","python","mapping","tables","between","word","string","and","index",",","(",":","attr",":","`","id_to_token_map","`",",",":","attr",":","`","token_to_id_map","`",",",":","attr",":","`","id_to_token_map_py","`",",",":","attr",":","`","token_to_id_map_py","`",")",",","where",":","attr",":","`","id_to_token_map","`","and",":","attr",":","`","token_to_id_map","`","are","TF",":","tf_main",":","`","HashTable","<","contrib\/lookup\/HashTable",">","`","instances",",","and",":","attr",":","`","id_to_token_map_py","`","and",":","attr",":","`","token_to_id_map_py","`","are","python","`","defaultdict","`","instances","."]
code: def load(self, filename):
      """Loads the vocabulary from the file.
  
      Args:
          filename (str): Path to the vocabulary file.
  
      Returns:
          A tuple of TF and python mapping tables between word string and
          index, (:attr:`id_to_token_map`, :attr:`token_to_id_map`,
          :attr:`id_to_token_map_py`, :attr:`token_to_id_map_py`), where
          :attr:`id_to_token_map` and :attr:`token_to_id_map` are
          TF :tf_main:`HashTable <contrib/lookup/HashTable>` instances,
          and :attr:`id_to_token_map_py` and
          :attr:`token_to_id_map_py` are python `defaultdict` instances.
      """
      with gfile.GFile(filename) as vocab_file:
          # Converts to 'unicode' (Python 2) or 'str' (Python 3)
          vocab = list(
              tf.compat.as_text(line.strip()) for line in vocab_file
          )
  
      warnings.simplefilter("ignore", UnicodeWarning)
  
      if self._bos_token in vocab:
          raise ValueError(
              "Special begin-of-seq token already exists in the "
              "vocabulary: '%s'" % self._bos_token
          )
      if self._eos_token in vocab:
          raise ValueError(
              "Special end-of-seq token already exists in the "
              "vocabulary: '%s'" % self._eos_token
          )
      if self._unk_token in vocab:
          raise ValueError(
              "Special UNK token already exists in the "
              "vocabulary: '%s'" % self._unk_token
          )
      if self._pad_token in vocab:
          raise ValueError(
              "Special padding token already exists in the "
              "vocabulary: '%s'" % self._pad_token
          )
  
      warnings.simplefilter("default", UnicodeWarning)
  
      # Places _pad_token at the beginning to make sure it take index 0.
      vocab = [
          self._pad_token,
          self._bos_token,
          self._eos_token,
          self._unk_token,
      ] + vocab
      # Must make sure this is consistent with the above line
      unk_token_idx = 3
      vocab_size = len(vocab)
      vocab_idx = np.arange(vocab_size)
  
      # Creates TF maps
      id_to_token_map = tf.contrib.lookup.HashTable(
          tf.contrib.lookup.KeyValueTensorInitializer(
              vocab_idx,
              vocab,
              key_dtype=tf.int64,
              value_dtype=tf.string,
          ),
          self._unk_token,
      )
  
      token_to_id_map = tf.contrib.lookup.HashTable(
          tf.contrib.lookup.KeyValueTensorInitializer(
              vocab,
              vocab_idx,
              key_dtype=tf.string,
              value_dtype=tf.int64,
          ),
          unk_token_idx,
      )
  
      # Creates python maps to interface with python code
      id_to_token_map_py = _make_defaultdict(
          vocab_idx, vocab, self._unk_token
      )
      token_to_id_map_py = _make_defaultdict(
          vocab, vocab_idx, unk_token_idx
      )
  
      return (
          id_to_token_map,
          token_to_id_map,
          id_to_token_map_py,
          token_to_id_map_py,
      )
  
imports: import warnings
  from collections import defaultdict
  import tensorflow
  from tensorflow import gfile
  import numpy
  from texar.tf.utils.utils import dict_lookup
label_desc: Use image node_id 2 for calling the Vocab obj's underlying member method code with example usage: obj.load(filename) and returns: id_to_token_map,  token_to_id_map,  id_to_token_map_py,  token_to_id_map_py