0
私は、このRNNテキスト分類システムをWebで利用可能なチュートリアルでケラで書いています。それは正常に動作しており、出力も表示されます。しかし、ある人が自分のコードをチェックして、私の実装が正しいかどうかを教えてもらえますか?ケラを使用したRNNテキスト分類
# LSTM with dropout for sequence classification
import numpy
from keras.models import Sequential
from keras.layers import Dense, Activation
from keras.layers import LSTM
from keras.preprocessing import sequence,text
from keras.layers.embeddings import Embedding
import pandas as pd
# fix random seed for reproducibility
numpy.random.seed(7)
#fetching sms spam dataset
url = 'https://raw.githubusercontent.com/justmarkham/pydata-dc-2016-tutorial/master/sms.tsv'
sms = pd.read_table(url, header=None, names=['label', 'message'])
#binarizing
sms['label_num'] = sms.label.map({'ham':0, 'spam':1})
sms.head()
X = sms.message
y = sms.label_num
print(X.shape)
print(y.shape)
###################################
tk = text.Tokenizer(nb_words=200, lower=True)
tk.fit_on_texts(X)
x = tk.texts_to_sequences(X)
print len(tk.word_counts)
###################################
max_len = 80
print "max_len ", max_len
print('Pad sequences (samples x time)')
x = sequence.pad_sequences(x, maxlen=max_len)
max_features = 200
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=500, nb_epoch=1, verbose=1, validation_split=0.2, show_accuracy=True, shuffle=True)
試し思わhttps://codereview.stackexchange.com/ – jcubic
codereview.stackexchange.comに属しているため、この質問を議論の対象外としています – jcubic