Created
August 23, 2021 18:02
-
-
Save rohithteja/9c9998b3775b2727d01ed408abb4cda8 to your computer and use it in GitHub Desktop.
LSTM Model
This file contains hidden or 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
| 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