hidasib / GRU4Rec

GRU4Rec is the original Theano implementation of the algorithm in "Session-based Recommendations with Recurrent Neural Networks" paper, published at ICLR 2016 and its follow-up "Recurrent Neural Networks with Top-k Gains for Session-based Recommendations". The code is optimized for execution on the GPU.
Other
754 stars 223 forks source link

How to save & load model? #12

Closed Gitpeggyask closed 7 years ago

Gitpeggyask commented 7 years ago

Hi Balazs,

Thank you very much for sharing the great article and implementation. It’s extremely helpful.

I’m wondering if there’s a way to save the model so that I can load it later. I tried to use pickle.dumps(), np.save() and all failed. If it’s possible, could you please let me know how to save and load the model.

Thanks Peggy

hidasib commented 7 years ago

Pickle works just fine.

Saving:

gru = gru4rec.GRU4Rec(...)
gru.fit(...)
with open('model.pickle', mode='wb') as f:
    pickle.dump(gru, f, protocol=pickle.HIGHEST_PROTOCOL)

Loading:

with open('model.pickle', mode='rb') as f:
    gru = pickle.load(f)