docstr: Create a dictionary from a vocabulary file.
docstr_tok: ["Create","a","dictionary","from","a","vocabulary","file","."]
code: def read_vocab(vocab_path):
      """
      Create a dictionary from a vocabulary file.
      """
      skipped = 0
      assert PathManager.isfile(vocab_path), vocab_path
      word2id = {BOS_WORD: 0, EOS_WORD: 1, PAD_WORD: 2, UNK_WORD: 3}
      for i in range(SPECIAL_WORDS):
          word2id[SPECIAL_WORD % i] = 4 + i
      counts = {k: 0 for k in word2id.keys()}
      f = PathManager.open(vocab_path, "r", encoding="utf-8")
      for i, line in enumerate(f):
          if "\u2028" in line:
              skipped += 1
              continue
          line = line.rstrip().split()
          if len(line) != 2:
              skipped += 1
              continue
          assert len(line) == 2, (i, line)
          # assert line[0] not in word2id and line[1].isdigit(), (i, line)
          assert line[1].isdigit(), (i, line)
          if line[0] in word2id:
              skipped += 1
              print("%s already in vocab" % line[0])
              continue
          if not line[1].isdigit():
              skipped += 1
              print("Empty word at line %s with count %s" % (i, line))
              continue
          # shift because of extra words
          word2id[line[0]] = 4 + SPECIAL_WORDS + i - skipped
          counts[line[0]] = int(line[1])
      f.close()
      id2word = {v: k for k, v in word2id.items()}
      dico = Dictionary(id2word, word2id, counts)
      logger.info("Read %i words from the vocabulary file." % len(dico))
      if skipped > 0:
          logger.warning("Skipped %i empty lines!" % skipped)
      return dico
  
file_path: pytext/pytext/data/xlm_dictionary.py
imports: import os
  from logging import getLogger
  import numpy
  import torch
  from pytext.utils.file_io import PathManager
label_desc: Use image node_id 10 for calling the Dictionary obj's underlying member method code with example usage: obj.read_vocab(vocab_path) and returns: dico