Skip to content

Instantly share code, notes, and snippets.

@rohithteja
Created August 23, 2021 18:02
Show Gist options
  • Select an option

  • Save rohithteja/9c9998b3775b2727d01ed408abb4cda8 to your computer and use it in GitHub Desktop.

Select an option

Save rohithteja/9c9998b3775b2727d01ed408abb4cda8 to your computer and use it in GitHub Desktop.
LSTM Model
from keras.models import Sequential
from keras.layers.core import Dense, Dropout
from keras.layers import Dense, Embedding, LSTM, SpatialDropout1D
def lstm(optimizer,epochs,batchsize):
model = Sequential()
model.add(Embedding(input_dim=vocab_size,
output_dim=embedding_dim,
input_length=maxlen))
model.add(SpatialDropout1D(0.4))
model.add(LSTM(64, activation="tanh"))
model.add(Dense(3,activation='softmax'))
model.compile(optimizer=optimizer,
loss='categorical_crossentropy',
metrics=['accuracy'])
history = model.fit(X_train, y_train,
epochs=epochs,
verbose=0,
validation_data=(X_val, y_val),
batch_size=batchsize)
return history, model
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment