Skip to content

Instantly share code, notes, and snippets.

@madrugado
Last active December 13, 2022 16:51
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save madrugado/63c068b52a135c6fdbbb6fe17acbc0c8 to your computer and use it in GitHub Desktop.
Save madrugado/63c068b52a135c6fdbbb6fe17acbc0c8 to your computer and use it in GitHub Desktop.
Keras usage example, simple text classification
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@feeeper
Copy link

feeeper commented May 15, 2017

@bumsun, похоже, что проблема в том, что tokenizer.texts_to_matrix принимает массив объектов. Если передаётся строка, то метод считает, что это массив символов и творит ерунду. У меня такой код работает, похоже, правильно:

prediction = model.predict(np.array(tokenizer.texts_to_matrix([text], mode='binary'))) # text заменил на [text]
print(prediction.shape) # (1, 20)
print(prediction) # массив из двадцати значений. i-ый элемент массива указывает вероятность того, что текст относится к i-ой категории.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment