MCPcopy Create free account
hub / github.com/baidu/DDParser / __init__

Method __init__

ddparser/parser/data_struct/vocab.py:32–38  ·  view source on GitHub ↗
(self, counter, min_freq=1, specials=None, unk_index=0)

Source from the content-addressed store, hash-verified

30class 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"""

Callers

nothing calls this directly

Calls 2

extendMethod · 0.95
updateMethod · 0.80

Tested by

no test coverage detected