This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import keras | |
from keras.preprocessing import sequence | |
from keras.models import Sequential | |
from keras.layers import Dense, Embedding, lSTM | |
model = Sequential() | |
# Create Embedding (Input) Layer (max_words) --> LSTM Layer (128) | |
model.add(Embedding(max_words, 128)) | |
model.add(LSTM(128, dropout=0.2, recurrent_dropout=0.2)) | |
# LSTM Layer (128) --> Output Layer (num_classes) | |
model.add(Dense(num_classes, activation='softmax')) | |
# Add optimization method, loss function and optimization value | |
model.compile(loss='categorical_crossentropy', | |
optimizer='adam', metrics=['accuracy']) | |
# "Fit the model" (train model), using training data (80% of dataset) | |
model.fit(x_train, y_train, batch_size=batch_size, | |
epochs=epochs, validation_data=(x_test, y_test)) | |
# Evalute the trained model, using the test data (20% of the dataset) | |
score = model.evaluate(x_test, y_test, batch_size=batch_size) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment