docstr: Vocab class to be used when you want to train word embeddings from
  scratch based on a custom vocab. This will initialize the random
  vectors for the vocabulary you pass. Get the vectors using
  `get_vectors` function. This will also create random embeddings for
  some predefined words like PAD - <pad>, SOS - <s>, EOS - </s>,
  UNK - <unk>.
  
  Parameters
  ----------
  vocab_file : str
      Path of the vocabulary file containing one word per line
  embedding_dim : int
      Size of the embedding
docstr_tok: ["Vocab","class","to","be","used","when","you","want","to","train","word","embeddings","from","scratch","based","on","a","custom","vocab",".","This","will","initialize","the","random","vectors","for","the","vocabulary","you","pass",".","Get","the","vectors","using","`","get_vectors","`","function",".","This","will","also","create","random","embeddings","for","some","predefined","words","like","PAD","-","<","pad",">",",","SOS","-","<","s",">",",","EOS","-","<","\/s",">",",","UNK","-","<","unk",">",".","Parameters","--","--","--","--","--","vocab_file",":","str","Path","of","the","vocabulary","file","containing","one","word","per","line","embedding_dim",":","int","Size","of","the","embedding"]
code: def __init__(
      self,
      vocab_file=None,
      embedding_dim=300,
      data_dir=None,
      *args,
      **kwargs,
  ):
      """Vocab class to be used when you want to train word embeddings from
      scratch based on a custom vocab. This will initialize the random
      vectors for the vocabulary you pass. Get the vectors using
      `get_vectors` function. This will also create random embeddings for
      some predefined words like PAD - <pad>, SOS - <s>, EOS - </s>,
      UNK - <unk>.
  
      Parameters
      ----------
      vocab_file : str
          Path of the vocabulary file containing one word per line
      embedding_dim : int
          Size of the embedding
  
      """
      self.type = "base"
      self.word_dict = {}
      self.itos = {}
  
      self.itos[self.PAD_INDEX] = self.PAD_TOKEN
      self.itos[self.SOS_INDEX] = self.SOS_TOKEN
      self.itos[self.EOS_INDEX] = self.EOS_TOKEN
      self.itos[self.UNK_INDEX] = self.UNK_TOKEN
  
      self.word_dict[self.SOS_TOKEN] = self.SOS_INDEX
      self.word_dict[self.EOS_TOKEN] = self.EOS_INDEX
      self.word_dict[self.PAD_TOKEN] = self.PAD_INDEX
      self.word_dict[self.UNK_TOKEN] = self.UNK_INDEX
  
      index = len(self.itos.keys())
  
      self.total_predefined = len(self.itos.keys())
  
      if vocab_file is not None:
          if not os.path.isabs(vocab_file) and data_dir is not None:
              vocab_file = os.path.join(data_dir, vocab_file)
              vocab_file = get_absolute_path(vocab_file)
  
          if not PathManager.exists(vocab_file):
              raise RuntimeError("Vocab not found at " + vocab_file)
  
          with PathManager.open(vocab_file, "r") as f:
              for line in f:
                  self.itos[index] = line.strip()
                  self.word_dict[line.strip()] = index
                  index += 1
  
      self.word_dict[self.SOS_TOKEN] = self.SOS_INDEX
      self.word_dict[self.EOS_TOKEN] = self.EOS_INDEX
      self.word_dict[self.PAD_TOKEN] = self.PAD_INDEX
      self.word_dict[self.UNK_TOKEN] = self.UNK_INDEX
      # Return unk index by default
      self.stoi = defaultdict(self.get_unk_index)
      self.stoi.update(self.word_dict)
  
      self.vectors = torch.FloatTensor(self.get_size(), embedding_dim)
  
imports: import logging
  import os
  from collections import defaultdict
  import numpy
  import torch
  from mmf.utils.configuration import get_mmf_cache_dir
  from mmf.utils.distributed import is_main, synchronize
  from mmf.utils.file_io import PathManager
  from mmf.utils.general import get_absolute_path
  from torchtext import vocab
label_desc: Use image node_id 1 to create a new BaseVocab object  with example: obj = BaseVocab(vocab_file, embedding_dim, data_dir)