2017-09-13 148 views
2
>>> t = Tokenizer(num_words=3) 
>>> l = ["Hello, World! This is so&#$ fantastic!", "There is no other world like this one"] 
>>> t.fit_on_texts(l) 
>>> t.word_index 
{'fantastic': 6, 'like': 10, 'no': 8, 'this': 2, 'is': 3, 'there': 7, 'one': 11, 'other': 9, 'so': 5, 'world': 1, 'hello': 4} 

我預計t.word_index只有前3個單詞。我究竟做錯了什麼?Keras Tokenizer num_words似乎沒有工作

+0

另請參見此問題:https://github.com/fchollet/keras/issues/7836 – petezurich

+1

謝謝!以下內容也有助於https://github.com/fchollet/keras/issues/7551 –

回答

2

你在做什麼沒有錯。 word_index以相同的方式計算,無論您將在以後使用多少個最頻繁的單詞(如您可能會看到here)。因此,當你打電話給任何轉化方法 - Tokenizer將只使用三個最常見的單詞,同時,它將保留所有單詞的計數器 - 即使明顯它不會在以後使用它。