Skip to content

Instantly share code, notes, and snippets.

@lettergram lettergram/mlp_design.py
Last active Dec 31, 2018

Embed
What would you like to do?
import keras
model = Sequential()
# Input (max_words) --(W1)-> Hidden Layer (512)
model.add(Dense(512, input_shape=(max_words,)))
model.add(Activation('tanh'))
model.add(Dropout(0.5))
# Hidden Layer (512) --(W2)--> Output Layer (num_classes)
model.add(Dense(num_classes))
model.add(Activation('softmax'))
# Add optimization method, loss function, and optimization value
model.compile(loss='categorical_crossentropy',
optimizer='adam', metrics=['accuracy'])
# "Fit model" (train model), using training data (80% of data)
model.fit(x_train, y_train, batch_size=batch_size, epochs=epochs)
# Evaluate the trained model, using the test data (20% of data)
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.