Created
December 24, 2016 07:11
-
-
Save bzamecnik/14f25daa25b113587acc3ef2c37aa2de to your computer and use it in GitHub Desktop.
Simplest sequence classifier with LSTM & softmax in Keras
This file contains hidden or 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
""" | |
Classifies sequences of length 10 with 20 features into 2 classes | |
with a single LSTM layer with 32 neurons. | |
See also a more involved example: | |
https://gist.github.com/bzamecnik/dccc1c4fdcf1c7a31757168b19c827a7 | |
""" | |
from keras.layers import Input, LSTM, Dense | |
from keras.models import Model | |
seq_length = 10 | |
feature_count = 20 | |
class_count = 2 | |
rnn_width = 32 | |
input = Input(shape=(seq_length, feature_count)) | |
LSTM(class_count, activation='softmax')(input) | |
model = Model(input, x) | |
model.summary() | |
#____________________________________________________________________________________________________ | |
#Layer (type) Output Shape Param # Connected to | |
#==================================================================================================== | |
#input_6 (InputLayer) (None, 10, 20) 0 | |
#____________________________________________________________________________________________________ | |
#lstm_15 (LSTM) (None, 2) 184 input_6[0][0] | |
#==================================================================================================== | |
#Total params: 184 | |
#____________________________________________________________________________________________________ | |
model.compile(loss='categorical_crossentropy', optimizer='adam') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment