Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save metacritical/8f89cf1abf8bc1a3c7f17d762f74cd9d to your computer and use it in GitHub Desktop.
Save metacritical/8f89cf1abf8bc1a3c7f17d762f74cd9d to your computer and use it in GitHub Desktop.
Simplest sequence classifier with LSTM & softmax in Keras
"""
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