MCPcopy Create free account
hub / github.com/pytorch/examples / Dictionary

Class Dictionary

word_language_model/data.py:5–17  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3import torch
4
5class Dictionary(object):
6 def __init__(self):
7 self.word2idx = {}
8 self.idx2word = []
9
10 def add_word(self, word):
11 if word not in self.word2idx:
12 self.idx2word.append(word)
13 self.word2idx[word] = len(self.idx2word) - 1
14 return self.word2idx[word]
15
16 def __len__(self):
17 return len(self.idx2word)
18
19
20class Corpus(object):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected