考虑以下代码:
from keras.preprocessing.text import Tokenizer
tokenizer = Tokenizer(num_words = 5000)
tokenizer.fit_on_texts(texts)
print('Found %d unique words.' % len(tokenizer.word_index))
当我运行它时,它会打印:
Found 88582 unique words.
我的问题是,num_words控制映射字典中单词数量的参数不是称为tokenizer.word_index吗?那为什么88582当我明确要求它只保留单词时它仍然保留5000单词?