tutorials
tutorials copied to clipboard
Error in class Voc of chatbot_tutorial.py
In the class Voc (line 283), the trim function(line 306) does not correctly reinitialize the word2count dictionary:
def trim(self, min_count):
if self.trimmed:
return
self.trimmed = True
keep_words = []
for k, v in self.word2count.items():
if v >= min_count:
keep_words.append(k)
print('keep_words {} / {} = {:.4f}'.format(
len(keep_words), len(self.word2index), len(keep_words) / len(self.word2index)
))
# Reinitialize dictionaries
self.word2index = {}
self.word2count = {}
self.index2word = {PAD_token: "PAD", SOS_token: "SOS", EOS_token: "EOS"}
self.num_words = 3 # Count default tokens
for word in keep_words:
self.addWord(word)
As the word2count dictionary is reinitialized, self.addWord(word) will only make all the word counts equal to 1, since keep_words will contain the unique words from word2count. The counts from the original conversations are lost. Could you please verify this?