def _build_vocab(self, file_path, vocab_path):
counter = Counter(self._read_text(file_path).split())
count_pairs = sorted(counter.items(), key=lambda x: (-x[1], x[0]))
words, _ = list(zip(*count_pairs))
self.vocab = dict(zip(words, range(len(words))))
save_pkl(vocab_path, self.vocab)
评论列表
文章目录