Putting the model into production
Recall that in LSI Gensim we loaded four objects: the dictionary list, the model, the BoW object, and the TF-IDF object. In Doc2Vec, we only need to load the model object. This is because Doc2Vec does not build on BoW or TF-IDF. I also load the training data just for convenience. It is not required in real-time production.
How do we use Doc2Vec in production? It can be used just like a search engine to retrieve relevant documents based on keyword search. It can also be used to return similar articles to an article of choice. I will demonstrate both use cases. Before that, let’s see how to load your model and training data.
Loading the model
Gensim has a get_tmpfile
utility function that points to the physical location of the file. We will use it to reference the location of the model to load the model:
from gensim.test.utils import get_tmpfilefname = get_tmpfile(path + "/doc2vec.model") model = Doc2Vec.load(fname)