Skip to content

Instantly share code, notes, and snippets.

@ashokc
Created January 16, 2019 01:22
Show Gist options
  • Save ashokc/63db0e48c5300efe4d66bb02bb36d3f7 to your computer and use it in GitHub Desktop.
Save ashokc/63db0e48c5300efe4d66bb02bb36d3f7 to your computer and use it in GitHub Desktop.
Build a Simple LSTM Model
# Build the LSTM model
def getModel():
units1, units2 = int (nWords/4), int (nWords/8)
model = keras.models.Sequential()
model.add(keras.layers.embeddings.Embedding(input_dim = len(kTokenizer.word_index)+1,output_dim=units1,input_length=sequenceLength, trainable=True)) # Line 5
model.add(keras.layers.LSTM(units = units2, return_sequences =False)) # Line 6
model.add(keras.layers.Dense(len(labelToName), activation ='softmax')) # Line 7
model.compile(optimizer='adam', loss = 'categorical_crossentropy', metrics=['acc'])
return model
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment