dorianbrown / rank_bm25

A Collection of BM25 Algorithms in Python
Apache License 2.0
1.05k stars 89 forks source link

How to save the model? #14

Closed lavarthan closed 3 years ago

lavarthan commented 3 years ago

How we can save the trained model and load it?

lavarthan commented 3 years ago

I found the solution. You can save the model using Pickle

import pickle

# model
bm25 = bm25 = BM25Okapi(tok_text)

# save model
file_name = "model.pkl"
with open(file_name, 'wb') as file:
    pickle.dump(bm25, file)

then you can load it using pickle as well

# load  model
with open(file_name, 'rb') as file:
    model = pickle.load(file)