(self, counter, min_freq=1, specials=None, unk_index=0)
| 30 | class Vocab(object): |
| 31 | """Vocab""" |
| 32 | def __init__(self, counter, min_freq=1, specials=None, unk_index=0): |
| 33 | self.itos = list(specials) if specials else [] |
| 34 | self.stoi = defaultdict(lambda: unk_index) |
| 35 | self.stoi.update({token: i for i, token in enumerate(self.itos)}) |
| 36 | self.extend([token for token, freq in counter.items() if freq >= min_freq]) |
| 37 | self.unk_index = unk_index |
| 38 | self.n_init = len(self) |
| 39 | |
| 40 | def __len__(self): |
| 41 | """Returns the size of the vocabulary""" |