对Newswire教科书示例进行分类-如何用一些句子对其进行测试?

我正在使用深度学习霍利特书中的教科书示例,作者在其中解释了如何构建模型以对路透社新闻数据集进行分类:

https://github.com/fchollet/deep-learning-with-python-notebooks/blob/master/3.6-classifying-newswires.ipynb

我的代码在训练模型后检查一些测试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的方式有问题吗?

lyyliu 回答:对Newswire教科书示例进行分类-如何用一些句子对其进行测试?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3131297.html

大家都在问