Skip to content

Instantly share code, notes, and snippets.

@gracecarrillo
Created January 27, 2020 15:26
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 gracecarrillo/45279ecc33f3a7d217ac76ff44273735 to your computer and use it in GitHub Desktop.
Save gracecarrillo/45279ecc33f3a7d217ac76ff44273735 to your computer and use it in GitHub Desktop.
#------------- DEEP LEARNING -----------------#
#-----LSTM Network with Keras------#
#--- Parameters----#
# encodes input sequence dense vectors
embed_dim = 128
# transforms the vector sequence into a single vector
lstm_out = 200
# batch size of 32 is a good starting point
batch_size = 32
# epochs
nb_epoch = 10
#------# Build the LSTM model #-----------------#
print('Building model...')
# Initialising the RNN
model = Sequential()
#adding an input layer and the first hidden layer
model.add(Embedding(2500, embed_dim,
input_length = features.shape[1],
dropout = 0.2))
# Adding the second hidden layer
model.add(LSTM(lstm_out, dropout_U = 0.2, dropout_W = 0.2))
# Adding the output layer
model.add(Dense(2, activation='softmax'))
# Compile model
model.compile( optimizer='adam', # optimazer
loss = 'categorical_crossentropy', # loss function
metrics = ['accuracy']) # list of metrics
model.name = 'LSTM model'
print(model.summary())
# Output:
Building model...
Model: "LSTM model"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
embedding_1 (Embedding) (None, 39, 128) 320000
_________________________________________________________________
lstm_1 (LSTM) (None, 200) 263200
_________________________________________________________________
dense_1 (Dense) (None, 2) 402
=================================================================
Total params: 583,602
Trainable params: 583,602
Non-trainable params: 0
_________________________________________________________________
None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment