我正在使用深度学习霍利特书中的教科书示例,作者在其中解释了如何构建模型以对路透社新闻数据集进行分类:
我的代码在训练模型后检查一些测试sentences
:
from keras.datasets import reuters
import numpy as np
# this function is exactly as defined in the code in the example from the book in link above
def vectorize_sequences(sequences,dimension=10000):
results = np.zeros((len(sequences),dimension))
for i,sequence in enumerate(sequences):
results[i,sequence] = 1.
return results
# The sentences to test
sentences = ['The cyclone will hit the shores duirng','landfall rain cloud']
# Encoding of the words in the sentence
word_index = reuters.get_word_index()
x_test = [[word_index[w] for w in sentences if w in word_index]]
x_test = vectorize_sequences(x_test)
vector = np.array([x_test.flatten()])
# The model prediction
c = model.predict_classes(vector)
在c = [16]
上方的代码中,即使我尝试使用不同的句子,也使用相同的主题。
我输入用于模型预测的测试sentences
的方式有问题吗?