docstr: Use this vocab class when you have a custom vocabulary class but you
  want to use pretrained embedding vectos for it. This will only load
  the vectors which intersect with your vocabulary. Use the
  embedding_name specified in torchtext's pretrained aliases:
  ['charngram.100d', 'fasttext.en.300d', 'fasttext.simple.300d',
   'glove.42B.300d', 'glove.840B.300d', 'glove.twitter.27B.25d',
   'glove.twitter.27B.50d', 'glove.twitter.27B.100d',
   'glove.twitter.27B.200d', 'glove.6B.50d', 'glove.6B.100d',
   'glove.6B.200d', 'glove.6B.300d']
  
  Parameters
  ----------
  vocab_file : str
      Vocabulary file containing list of words with one word per line
      which will be used to collect vectors
  embedding_name : str
      Embedding name picked up from the list of the pretrained aliases
      mentioned above
docstr_tok: ["Use","this","vocab","class","when","you","have","a","custom","vocabulary","class","but","you","want","to","use","pretrained","embedding","vectos","for","it",".","This","will","only","load","the","vectors","which","intersect","with","your","vocabulary",".","Use","the","embedding_name","specified","in","torchtext","'s","pretrained","aliases",":","[","'charngram.100d","'",",","'fasttext.en.300d","'",",","'fasttext.simple.300d","'",",","'glove.42B.300d","'",",","'glove.840B.300d","'",",","'glove.twitter.27B.25d","'",",","'glove.twitter.27B.50d","'",",","'glove.twitter.27B.100d","'",",","'glove.twitter.27B.200d","'",",","'glove.6B.50d","'",",","'glove.6B.100d","'",",","'glove.6B.200d","'",",","'glove.6B.300d","'","]","Parameters","--","--","--","--","--","vocab_file",":","str","Vocabulary","file","containing","list","of","words","with","one","word","per","line","which","will","be","used","to","collect","vectors","embedding_name",":","str","Embedding","name","picked","up","from","the","list","of","the","pretrained","aliases","mentioned","above"]
code: def __init__(self, vocab_file, embedding_name, *args, **kwargs):
      """Use this vocab class when you have a custom vocabulary class but you
      want to use pretrained embedding vectos for it. This will only load
      the vectors which intersect with your vocabulary. Use the
      embedding_name specified in torchtext's pretrained aliases:
      ['charngram.100d', 'fasttext.en.300d', 'fasttext.simple.300d',
       'glove.42B.300d', 'glove.840B.300d', 'glove.twitter.27B.25d',
       'glove.twitter.27B.50d', 'glove.twitter.27B.100d',
       'glove.twitter.27B.200d', 'glove.6B.50d', 'glove.6B.100d',
       'glove.6B.200d', 'glove.6B.300d']
  
      Parameters
      ----------
      vocab_file : str
          Vocabulary file containing list of words with one word per line
          which will be used to collect vectors
      embedding_name : str
          Embedding name picked up from the list of the pretrained aliases
          mentioned above
      """
      super().__init__(vocab_file, *args, **kwargs)
  
      self.type = "intersected"
  
      name = embedding_name.split(".")[0]
      dim = embedding_name.split(".")[2][:-1]
      middle = embedding_name.split(".")[1]
  
      class_name = EMBEDDING_NAME_CLASS_MAPPING[name]
  
      if not hasattr(vocab, class_name):
          raise RuntimeError(f"Unknown embedding type: {name}")
  
      params = [middle]
  
      if name == "glove":
          params.append(int(dim))
  
      vector_cache = get_mmf_cache_dir()
  
      # First test loading the vectors in master so that everybody doesn't
      # download it in case it doesn't exist
      if is_main():
          vocab.pretrained_aliases[embedding_name](cache=vector_cache)
      synchronize()
  
      embedding = getattr(vocab, class_name)(
          *params, cache=vector_cache
      )
  
      self.vectors = torch.empty(
          (self.get_size(), len(embedding.vectors[0])),
          dtype=torch.float,
      )
  
      self.embedding_dim = len(embedding.vectors[0])
  
      for i in range(0, 4):
          self.vectors[i] = torch.ones_like(self.vectors[i]) * 0.1 * i
  
      for i in range(4, self.get_size()):
          word = self.itos[i]
          embedding_index = embedding.stoi.get(word, None)
  
          if embedding_index is None:
              self.vectors[i] = self.vectors[self.UNK_INDEX]
          else:
              self.vectors[i] = embedding.vectors[embedding_index]
  
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 IntersectedVocab object from inherited base classes: BaseVocab with example: obj = IntersectedVocab(vocab_file, embedding_name)