Skip to content

Instantly share code, notes, and snippets.

@lettergram
Last active December 31, 2018 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lettergram/a330f4e54983583ef36090c7021c9913 to your computer and use it in GitHub Desktop.
Save lettergram/a330f4e54983583ef36090c7021c9913 to your computer and use it in GitHub Desktop.
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