def _load_word_freq(self, threshold: int) -> Tuple[Dict[str, int], int]:
n_total_words = 0
word_freq = {}
with open(self.rnnlm_model_path, mode='r') as f:
for line in f:
n_total_words += 1
word, freq = line.split(' ')
freq = int(freq)
if freq > threshold:
word_freq[word] = freq
else:
word_freq['<unk/>'] = word_freq.get('<unk/>', 0) + 1
return (word_freq, n_total_words)
评论列表
文章目录