>>> 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
只包含前三个词。我做错了什么吗?
回答:
你做的事情没有任何问题。word_index
的计算方式与你稍后将使用的最高频词的数量无关(你可以在这里看到)。因此,当你调用任何转换方法时,Tokenizer
只会使用三个最常见的词,同时它会保留所有词的计数器——即使显然它以后不会使用这些计数器。