Skip to content

Instantly share code, notes, and snippets.

@lettergram lettergram/
Last active Jan 4, 2019

What would you like to do?
import keras
from keras.preprocessing import sequence
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation
from keras.layers import Embedding, Conv1D, GlobalMaxPooling1D
model = Sequential()
# Created Embedding (Input) Layer (max_words) --> Convolutional Layer
model.add(Embedding(max_words, embedding_dims, input_length=maxlen))
model.add(Dropout(0.2)) # masks various input values
# Create the convolutional layer
model.add(Conv1D(filters, kernel_size,padding='valid', activation='relu', strides=1))
# Create the pooling layer
# Create the fully connected layer
# Create the output layer (num_classes)
# Add optimization method, loss function and optimization value
optimizer='adam', metrics=['accuracy'])
# "Fit the model" (train model), using training data (80% of datset), y_train, batch_size=batch_size,
epochs=epochs, validation_data=(x_test, y_test))
# Evaluate 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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.