0
웹에서 제공되는 자습서를 사용하여이 RNN 텍스트 분류 시스템을 keras에 작성했습니다. 그것은 잘 작동하고 또한 출력을 보여줍니다. 하지만 내 코드를 확인하고 내 구현이 맞는지 아닌지를 말해 줄 수 있습니까?케라를 사용한 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