-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLSTM Model
More file actions
25 lines (21 loc) · 894 Bytes
/
LSTM Model
File metadata and controls
25 lines (21 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Required Libraries
from keras.datasets import imdb
from keras.models import Sequential
from tensorflow.keras.preprocessing.sequence import pad_sequences
from keras.layers import Dense, LSTM, Embedding
# Loading Dataset
(x_train, y_train), (x_test, y_test) = imdb.load_data(num_words=10000)
# Padding the Sequence
max_length = 500
x_train = pad_sequences(x_train, maxlen=max_length)
x_test = pad_sequences(x_test, maxlen=max_length)
# Embedding, Modelling LSTM and Compiling the Model
embedding_vector_length = 32
model = Sequential()
model.add(Embedding(10000, embedding_vector_length, input_length=max_length))
model.add(LSTM(100))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
print(model.summary())
# Training the Model
model.fit(x_train, y_train, validation_data=(x_test, y_test), epochs=3, batch_size=64)