Классифицирующий пример учебника в новостной ленте - как проверить это с некоторыми предложениями? - PullRequest
0 голосов
/ 10 ноября 2019

Я использую учебник из книги Deep Learning Chollet, где автор объясняет, как построить модель для классификации набора данных Reuter News:

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 для прогнозирования модели.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...