Spaces:
Sleeping
Sleeping
| # Language Model | |
| SOS_token = 0 | |
| EOS_token = 1 | |
| class Language: | |
| def __init__(self, name): | |
| self.name = name | |
| self.word2index = {} | |
| self.word2count = {} | |
| self.index2word = {SOS_token: "<", EOS_token: ">"} | |
| self.n_chars = 2 # Count SOS and EOS | |
| def addWord(self, word): | |
| for char in word: | |
| self.addChar(char) | |
| def addChar(self, char): | |
| if char not in self.word2index: | |
| self.word2index[char] = self.n_chars | |
| self.word2count[char] = 1 | |
| self.index2word[self.n_chars] = char | |
| self.n_chars += 1 | |
| else: | |
| self.word2count[char] += 1 |