How to save the best model?

Suppose that I train my model for n epochs, and that I want to save the model with the highest accuracy on the development set. Could I use this code to save the model:

for epoch in range(n_epochs): 


 if    accuracy > best_accuracy:, ''), '')

For instance if I want to test this model later on a test set :).

1 Like

Hi, Talita:
You can save your model by either of the following methods.

# Method 1, '') 
# Method 2, '') # official recommended

The difference between two methods is that the first one saves the whole model which includes project-specific classes and your best parameters, while the second one just saves your best parameters.:smiley:

By the way, you can load the model by these codes.

the_model = TheModelClass(*args, **kwargs)


  1. recommend-saving-models