Created
August 23, 2021 18:12
-
-
Save rohithteja/71561cac20ea9940cdc9f94429665721 to your computer and use it in GitHub Desktop.
Set Weights LSTM
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
| embedding_dim = 100 | |
| optimizer = best_params['optimizer'] | |
| model = Sequential() | |
| model.add(layers.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']) | |
| best_model_weights = study.user_attrs['best_model_weights'] | |
| # setting the saved weights to new model | |
| model.set_weights(best_model_weights) | |
| # evaluating on the test set | |
| test_acc = model.evaluate(X_test,y_test)[1] | |
| print(test_acc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment