Saving and Loading Models
After a model has been built and its performance matches our expectations, we may want to save it for future use. This eliminates the time needed for rebuilding it. Models can be saved in the hard disk by using joblib and pickle.
To deploy saved models, we need to load them from the hard disk to the memory. In the next section, we will solve an exercise based on this to get a better understanding.
Exercise 39: Saving and Loading Models
In this exercise, first we will create a tf-idf representation of sentences. Then, we will save this model on disk. Later, we will load it from the disk. Follow these steps to implement this exercise:
- Open a Jupyter notebook.
- Insert a new cell and the following code to import the necessary packages:
import pickle from joblib import dump, load from sklearn.feature_extraction.text import TfidfVectorizer
- Defining a corpus consisting of four sentences, add the following code:
corpus = [ 'Data Science...