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.
@bumsun
Copy link

bumsun commented Apr 20, 2017

text = "From: lerxst@wam.umd.edu (where's my thing) Subject: WHAT car is this!? Nntp-Posting-Host: rac3.wam.umd.edu Organization: University of Maryland, College Park Lines: 15 I was wondering if anyone out there could enlighten me on this car I saw the other day. It was a 2-door sports car, looked to be from the late 60s/ early 70s. It was called a Bricklin. The doors were really small. In addition, the front bumper was separate from the rest of the body. This is  all I know. If anyone can tellme a model name, engine specs, years of production, where this car is made, history, or whatever info you have on this funky looking car, please e-mail.  Thanks, - IL ---- brought to you by your neighborhood Lerxst ----"
prediction = model.predict(np.array(tokenizer.texts_to_matrix(text, mode='binary')))
print(prediction.shape)

Я новичок в машинном обучении. Подскажите пожалуйста, как сделать прогноз для данного сообщения? Потому что у меня что-то странное выдается, т.к. я скорее всего не правильно обрабатываю текст)

@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