docs: def from_dict(cls, word2index, unk, counts=None):
          """Create Vocab from an existing string to integer dictionary.
  
          All counts are set to 0.
  
          :param word2index: a dictionary representing a bijection from N words to the integers 0 through N-1.
                  UNK must be assigned the 0 index.
  
          :param unk: the string representing unk in word2index.
  
          :param counts: (optional) a Counter object mapping words to counts
  
          :return: a created vocab object.
          """
          try:
              if word2index[unk] != 0:
                  raise ValueError('unk must be assigned index 0')
          except KeyError:
              raise ValueError('word2index must have an entry for unk.')
  
          # check that word2index is a bijection
          vals = set(word2index.values())  # unique indices
          n = len(vals)
  
          bijection = (len(word2index) == n) and (vals == set(range(n)))
          if not bijection:
              raise ValueError('word2index is not a bijection between N words and the integers 0 through N-1.')
  
          # reverse the dictionary
          index2word = {idx: word for word, idx in word2index.iteritems()}
  
          vocab = cls(unk=unk)
          for i in xrange(n):
              vocab.add(index2word[i])
  
          if counts:
              matching_entries = set(word2index.keys()) == set(counts.keys())
              if not matching_entries:
                  raise ValueError('entries of word2index do not match counts (did you include UNK?)')
              vocab._counts = counts
  
          return vocab