Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Fix duplicate entries in vocab #721

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions pytext/data/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,21 +213,26 @@ def add(self, value) -> None:

def make_vocab(self) -> Vocabulary:
"""Build a Vocabulary object from the values seen by the builder."""
vocab_list = list(self._counter)

tokens_to_insert: List[Tuple[int, object]] = []
if self.use_unk:
tokens_to_insert.append((self.unk_index, UNK))
del self._counter[UNK]
if self.use_pad:
tokens_to_insert.append((self.pad_index, self.pad_token))
del self._counter[self.pad_token]
if self.use_bos:
tokens_to_insert.append((self.bos_index, BOS))
del self._counter[BOS]
if self.use_eos:
tokens_to_insert.append((self.eos_index, EOS))
del self._counter[EOS]
if self.use_bol:
tokens_to_insert.append((self.bol_index, BOL))
del self._counter[BOL]
if self.use_eol:
tokens_to_insert.append((self.eol_index, EOL))
del self._counter[EOL]
vocab_list = list(self._counter)
for index, token in sorted(tokens_to_insert):
vocab_list.insert(index, token)

Expand Down