09.05.2023 Views

pdfcoffee

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

accuracy: 0.9962 - val_loss: 0.7770 - val_accuracy: 0.7500

Epoch 10/10

29/29 [==============================] - 3s 99ms/step - loss: 0.0062 -

accuracy: 0.9988 - val_loss: 0.8344 - val_accuracy: 0.7450

Chapter 8

Figure 5: Accuracy and loss plots from TensorBoard for sentiment analysis network training

Our checkpoint callback has saved the best model based on the lowest value of

validation loss, and we can now reload this for evaluation against our held out test

set:

best_model = SentimentAnalysisModel(vocab_size+1, max_seqlen)

best_model.build(input_shape=(batch_size, max_seqlen))

best_model.load_weights(best_model_file)

best_model.compile(

loss="binary_crossentropy",

optimizer="adam",

metrics=["accuracy"]

)

The easiest high-level way to evaluate a model against a dataset is to use the model.

evaluate() call:

test_loss, test_acc = best_model.evaluate(test_dataset)

print("test loss: {:.3f}, test accuracy: {:.3f}".format(

test_loss, test_acc))

This gives us the following output:

test loss: 0.487, test accuracy: 0.782

[ 305 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!