目标:把text中每条语句中的单词转化为数字
例如:I like you.---->1 3 5
过程:
1 告诉token我要建立一个2000个单词的字典
token = Tonkenizer(num_words=2000)
2告诉token现在开始读文章(train_text),并且对文章里面的单词出现过的次数做统计,从高到低依次排列。
token.fit_on_texts(train_text)
运行完这一句token就将所有单词的出现过的次数统计好了1代表出现频率最高的单词,2代表出现频率第二高的单词,3代表.....
可以用token.word_index查看单词排列顺序。
3告诉token把文章(train_text,test_text)里的内容替换成数字
x_train_seq=token.texts_to_sequences(train_text)
x_test_seq=token.texts_to_sequences(test_text)
运行完这一句,train_text和test_text里的单词就转成了数字
4告诉token将文章中的每句话单词的长度统一到定长
x_trai