Forked from bzamecnik/simples_lstm_softmax_classifier_keras.py
Created
May 8, 2023 05:28
-
-
Save metacritical/8f89cf1abf8bc1a3c7f17d762f74cd9d to your computer and use it in GitHub Desktop.
Simplest sequence classifier with LSTM & softmax in Keras
This file contains 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