class_docstr: Vocab model builder.
  
  Parameters
  ----------
  data_set: iterable
      A list of instances where each instance is a list of str.
  tokenizer: function, optional
      Word tokenization function, default: ``nltk.tokenize.word_tokenize``.
  max_word_vocab_size: int, optional
      Maximal word vocab size, default: ``None``.
  min_word_vocab_freq: int, optional
      Minimal word vocab frequency, default: ``1``.
  pretrained_word_emb_name: str, optional, default="840B"
      The name of pretrained word embedding in ``torchtext``.
      If it is set ``None``, we will randomly set the initial word embedding values.
  pretrained_word_emb_url: str optional, default: ``None``
      The url for downloading pretrained word embedding.
      Note that we only prepare the default ``url`` for English with ``pretrained_word_emb_name``
      as ``"42B"``, ``"840B"``, 'twitter.27B' and '6B'.
  target_pretrained_word_emb_name: str, optional, default=None
      The name of pretrained word embedding in ``torchtext`` for target language.
      If it is set ``None``, we will use ``pretrained_word_emb_name``.
  target_pretrained_word_emb_url: str optional, default: ``None``
      The url for downloading pretrained word embedding for target language.
      Note that we only prepare the default ``url`` for English with ``pretrained_word_emb_name``
      as ``"42B"``, ``"840B"``, 'twitter.27B' and '6B'.
  pretrained_word_emb_cache_dir: str, optional, default: ``".vector_cache/"``
      The path of directory saving the temporary word embedding file.
  word_emb_size: int, optional
      Word embedding size, default: ``None``.
  share_vocab : boolean
      Specify whether to share vocab between input and output text, default: ``True``.
  
  Examples
  -------
  # Build a vocab model from scratch
  >>> vocab_model = VocabModel([['I like nlp.', 'Same here!'],
                      ['I like graph.', 'Same here!']],
                      max_word_vocab_size=None,
                      min_word_vocab_freq=1,
                      word_emb_size=300)
  >>> print(vocab_model.word_vocab.get_vocab_size())
  
  # Restore a vocab model from disk if exists or build one from scratch.
  >>> vocab_model = VocabModel.build('vocab_model.pkl', [['I like nlp.', 'Same here!'],
                          ['I like graph.', 'Same here!']],
                          max_word_vocab_size=None,
                          min_word_vocab_freq=1,
                          word_emb_size=300)
  >>> print(vocab_model.word_vocab.get_vocab_size())
docstr: Static method for loading a VocabModel from disk.
  
  Parameters:
  -------
  saved_vocab_file : str
      Path to the saved vocab file.
  data_set: iterable
      A list of instances where each instance is a list of str.
  tokenizer: function, optional
      Word tokenization function, default: nltk.tokenize.word_tokenize.
  max_word_vocab_size: int, optional
      Maximal word vocab size, default: ``None``.
  min_word_vocab_freq: int, optional
      Minimal word vocab frequency, default: ``1``.
  pretrained_word_emb_name: str, optional, default="840B"
      The name of pretrained word embedding in ``torchtext``.
      If it is set ``None``, we will randomly set the initial word embedding values.
  pretrained_word_emb_url: str optional, default: ``None``
      The url for downloading pretrained word embedding.
      Note that we only prepare the default ``url`` for English with
      ``pretrained_word_emb_name`` as ``"42B"``, ``"840B"``, 'twitter.27B' and '6B'.
  target_pretrained_word_emb_name: str, optional, default=None
      The name of pretrained word embedding in ``torchtext`` for target language.
      If it is set ``None``, we will use ``pretrained_word_emb_name``.
  target_pretrained_word_emb_url: str optional, default: ``None``
      The url for downloading pretrained word embedding for target language.
      Note that we only prepare the default ``url`` for English with
      ``pretrained_word_emb_name`` as ``"42B"``, ``"840B"``, 'twitter.27B' and '6B'.
  pretrained_word_emb_cache_dir: str, optional, default: ``".vector_cache/"``
      The path of directory saving the temporary word embedding file.
  word_emb_size: int, optional
      Word embedding size, default: ``None``.
  share_vocab : boolean
      Specify whether to share vocab between input and output text, default: ``True``.
  
  Returns:
  -------
  VocabModel
      Loaded Vocabulary.
code: def build(
      cls,
      saved_vocab_file,
      data_set=None,
      tokenizer=word_tokenize,
      lower_case=True,
      max_word_vocab_size=None,
      min_word_vocab_freq=1,
      pretrained_word_emb_name="840B",
      pretrained_word_emb_url=None,
      target_pretrained_word_emb_name=None,
      target_pretrained_word_emb_url=None,
      pretrained_word_emb_cache_dir=".vector_cache/",
      word_emb_size=None,
      share_vocab=True,
  ):
      """Static method for loading a VocabModel from disk.
  
      Parameters:
      -------
      saved_vocab_file : str
          Path to the saved vocab file.
      data_set: iterable
          A list of instances where each instance is a list of str.
      tokenizer: function, optional
          Word tokenization function, default: nltk.tokenize.word_tokenize.
      max_word_vocab_size: int, optional
          Maximal word vocab size, default: ``None``.
      min_word_vocab_freq: int, optional
          Minimal word vocab frequency, default: ``1``.
      pretrained_word_emb_name: str, optional, default="840B"
          The name of pretrained word embedding in ``torchtext``.
          If it is set ``None``, we will randomly set the initial word embedding values.
      pretrained_word_emb_url: str optional, default: ``None``
          The url for downloading pretrained word embedding.
          Note that we only prepare the default ``url`` for English with
          ``pretrained_word_emb_name`` as ``"42B"``, ``"840B"``, 'twitter.27B' and '6B'.
      target_pretrained_word_emb_name: str, optional, default=None
          The name of pretrained word embedding in ``torchtext`` for target language.
          If it is set ``None``, we will use ``pretrained_word_emb_name``.
      target_pretrained_word_emb_url: str optional, default: ``None``
          The url for downloading pretrained word embedding for target language.
          Note that we only prepare the default ``url`` for English with
          ``pretrained_word_emb_name`` as ``"42B"``, ``"840B"``, 'twitter.27B' and '6B'.
      pretrained_word_emb_cache_dir: str, optional, default: ``".vector_cache/"``
          The path of directory saving the temporary word embedding file.
      word_emb_size: int, optional
          Word embedding size, default: ``None``.
      share_vocab : boolean
          Specify whether to share vocab between input and output text, default: ``True``.
  
      Returns:
      -------
      VocabModel
          Loaded Vocabulary.
      """
      if os.path.exists(saved_vocab_file):
          print(
              "Loading pre-built vocab model stored in {}".format(
                  saved_vocab_file
              )
          )
          with open(saved_vocab_file, "rb") as f:
              vocab_model = pickle.load(f)
  
      else:
          vocab_model = cls(
              data_set=data_set,
              tokenizer=tokenizer,
              max_word_vocab_size=max_word_vocab_size,
              min_word_vocab_freq=min_word_vocab_freq,
              pretrained_word_emb_name=pretrained_word_emb_name,
              pretrained_word_emb_url=pretrained_word_emb_url,
              pretrained_word_emb_cache_dir=pretrained_word_emb_cache_dir,
              target_pretrained_word_emb_name=target_pretrained_word_emb_name,
              target_pretrained_word_emb_url=target_pretrained_word_emb_url,
              word_emb_size=word_emb_size,
              lower_case=lower_case,
              share_vocab=share_vocab,
          )
          print("Saving vocab model to {}".format(saved_vocab_file))
          pickle.dump(vocab_model, open(saved_vocab_file, "wb"))
  
      return vocab_model
  
imports: import os
  import pickle
  import re
  import warnings
  from collections import Counter
  from functools import lru_cache
  import numpy
  import torch
  from nltk.tokenize import word_tokenize
  from torchtext.vocab import GloVe, Vectors
  from .None import constants
label_desc: Use image node_id 2 for calling the VocabModel obj's underlying member method code with example usage: obj.build(cls, saved_vocab_file, data_set, tokenizer, lower_case, max_word_vocab_size, min_word_vocab_freq, pretrained_word_emb_name, pretrained_word_emb_url, target_pretrained_word_emb_name, target_pretrained_word_emb_url, pretrained_word_emb_cache_dir, word_emb_size, share_vocab) and returns: vocab_model