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())
code: def __init__(
      self,
      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/",
      #  pretrained_word_emb_file=None,
      word_emb_size=None,
      share_vocab=True,
  ):
      super(VocabModel, self).__init__()
      self.tokenizer = tokenizer
  
      print("Building vocabs...")
      all_words = VocabModel.collect_vocabs(
          data_set,
          self.tokenizer,
          lower_case=lower_case,
          share_vocab=share_vocab,
      )
      # print('Number of words: {}'.format(len(all_words)))
      if share_vocab:
          in_all_words, out_all_words = all_words, None
          if (
              pretrained_word_emb_name is not None
              and target_pretrained_word_emb_name is not None
          ):
              warnings.warn(
                  "Warning: share vocabulary for source and target language but use different"
                  "pretrained word embeddings"
              )
      else:
          in_all_words, out_all_words = all_words
          if (
              pretrained_word_emb_name is not None
              and target_pretrained_word_emb_name is None
          ):
              warnings.warn(
                  "Warning: use separate vocabularies for source and target language but same"
                  "pretrained word embeddings"
              )
  
      self.in_word_vocab = Vocab(
          lower_case=lower_case, tokenizer=self.tokenizer
      )
      self.in_word_vocab.build_vocab(
          in_all_words,
          max_vocab_size=max_word_vocab_size,
          min_vocab_freq=min_word_vocab_freq,
      )
  
      if pretrained_word_emb_name is not None:
          self.in_word_vocab.load_embeddings(
              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,
              pretrained_word_emb_dim=word_emb_size,
          )
          print("Using pretrained word embeddings")
      else:
          self.in_word_vocab.randomize_embeddings(word_emb_size)
  
      if out_all_words is not None:
          self.out_word_vocab = Vocab(
              lower_case=lower_case, tokenizer=self.tokenizer
          )
          self.out_word_vocab.build_vocab(
              out_all_words,
              max_vocab_size=max_word_vocab_size,
              min_vocab_freq=min_word_vocab_freq,
          )
  
          if target_pretrained_word_emb_name is not None:
              self.out_word_vocab.load_embeddings(
                  pretrained_word_emb_name=target_pretrained_word_emb_name,
                  pretrained_word_emb_url=target_pretrained_word_emb_url,
                  pretrained_word_emb_cache_dir=pretrained_word_emb_cache_dir,
                  pretrained_word_emb_dim=word_emb_size,
              )
              print("Using pretrained word embeddings")
          elif pretrained_word_emb_name is not None:
              self.out_word_vocab.load_embeddings(
                  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,
                  pretrained_word_emb_dim=word_emb_size,
              )
              print("Using pretrained word embeddings")
          else:
              self.out_word_vocab.randomize_embeddings(word_emb_size)
      else:
          self.out_word_vocab = self.in_word_vocab
  
      if share_vocab:
          print(
              "[ Initialized word embeddings: {} ]".format(
                  self.in_word_vocab.embeddings.shape
              )
          )
      else:
          print(
              "[ Using separate word vocabs for input & output text ]"
          )
          print(
              "[ Initialized input word embeddings: {} ]".format(
                  self.in_word_vocab.embeddings.shape
              )
          )
          print(
              "[ Initialized output word embeddings: {} ]".format(
                  self.out_word_vocab.embeddings.shape
              )
          )
  
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 1 to create a new VocabModel object from inherited base classes: object with example: obj = VocabModel(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)