MCPcopy Create free account
hub / github.com/clab/dynet / Vocab

Class Vocab

examples/python-utils/util.py:3–17  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1import mmap
2
3class Vocab:
4 def __init__(self, w2i):
5 self.w2i = dict(w2i)
6 self.i2w = {i:w for w,i in w2i.items()}
7
8 @classmethod
9 def from_corpus(cls, corpus):
10 w2i = {}
11 for sent in corpus:
12 for word in sent:
13 w2i.setdefault(word, len(w2i))
14 return Vocab(w2i)
15
16 def size(self):
17 return len(self.w2i.keys())
18
19#This corpus reader can be used when reading large text file into a memory can solve IO bottleneck of training.
20#Use it exactly as the regular CorpusReader from the rnnlm.py

Callers 1

from_corpusMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected