Skip to content

Instantly share code, notes, and snippets.

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

  • Save rohithteja/71561cac20ea9940cdc9f94429665721 to your computer and use it in GitHub Desktop.

Select an option

Save rohithteja/71561cac20ea9940cdc9f94429665721 to your computer and use it in GitHub Desktop.
Set Weights LSTM
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