私は持っている特定のデータセットを分類するためにLSTMを使用する方法を理解しようとしています。ケラス - テキスト分類 - LSTM - テキストの入力方法は?
私はkerasとIMDBのこの例を調査した: https://github.com/fchollet/keras/blob/master/examples/imdb_lstm.py
ただし、データセットは、入力に処理されなければならないかについて混乱してイム。
私はkerasが前処理のテキストメソッドを持っていることを知っていますが、使用するかどうかはわかりません。
xはn行のテキストを含み、yは幸福/悲しみでテキストを分類します。基本的に1.0は100%満足、0.0は全く悲しいことを意味します。数は、たとえば0.25〜〜など変化することがあります。
私の質問は、どうやってxとyを正しく入力するのですか?私は言葉の袋を使わなければならないのですか? ヒントありがとうございます!
私はこれを以下のコード化されたが、私は同じエラーにあなたがしてテキストを読むためにあなたのCSVパーサーを使用しているか#('Bad input argument to theano function with name ... at index 1(0-based)', 'could not convert string to float: negative')
import keras.preprocessing.text
import numpy as np
np.random.seed(1337) # for reproducibility
from keras.preprocessing import sequence
from keras.models import Sequential
from keras.layers.core import Dense, Activation
from keras.layers.embeddings import Embedding
from keras.layers.recurrent import LSTM
print('Loading data...')
import pandas
thedata = pandas.read_csv("dataset/text.csv", sep=', ', delimiter=',', header='infer', names=None)
x = thedata['text']
y = thedata['sentiment']
x = x.iloc[:].values
y = y.iloc[:].values
###################################
tk = keras.preprocessing.text.Tokenizer(nb_words=2000, filters=keras.preprocessing.text.base_filter(), lower=True, split=" ")
tk.fit_on_texts(x)
x = tk.texts_to_sequences(x)
###################################
max_len = 80
print "max_len ", max_len
print('Pad sequences (samples x time)')
x = sequence.pad_sequences(x, maxlen=max_len)
#########################
max_features = 20000
model = Sequential()
print('Build model...')
model = Sequential()
model.add(Embedding(max_features, 128, input_length=max_len, dropout=0.2))
model.add(LSTM(128, dropout_W=0.2, dropout_U=0.2))
model.add(Dense(1))
model.add(Activation('sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='rmsprop')
model.fit(x, y=y, batch_size=200, nb_epoch=1, verbose=1, validation_split=0.2, show_accuracy=True, shuffle=True)
# at index 1(0-based)', 'could not convert string to float: negative')
テキストを読み込むためにCSVパーサを使用しています。あなたのデータセット/ text.csvはSentence、Sentimentとして設定されていますか?もしそうでなければ、あなたはそれをそうするか、またはあなたが持っている構造から2つの成分をどのように解析するか再考する必要があります。 –
あなたは正しかった!それは私がラベルをロードしていた方法でした! – KenobiShan
回答を追加します。私はそれを正しいものにします! – KenobiShan