MCPcopy Index your code
hub / github.com/pytorch/tutorials / trim

Method trim

beginner_source/chatbot_tutorial.py:291–313  ·  view source on GitHub ↗
(self, min_count)

Source from the content-addressed store, hash-verified

289
290 # Remove words below a certain count threshold
291 def trim(self, min_count):
292 if self.trimmed:
293 return
294 self.trimmed = True
295
296 keep_words = []
297
298 for k, v in self.word2count.items():
299 if v >= min_count:
300 keep_words.append(k)
301
302 print('keep_words {} / {} = {:.4f}'.format(
303 len(keep_words), len(self.word2index), len(keep_words) / len(self.word2index)
304 ))
305
306 # Reinitialize dictionaries
307 self.word2index = {}
308 self.word2count = {}
309 self.index2word = {PAD_token: "PAD", SOS_token: "SOS", EOS_token: "EOS"}
310 self.num_words = 3 # Count default tokens
311
312 for word in keep_words:
313 self.addWord(word)
314
315
316######################################################################

Callers 1

trimRareWordsFunction · 0.80

Calls 1

addWordMethod · 0.95

Tested by

no test coverage detected