Open schua16 opened 2 years ago
I have the same problem. I want to save model and then want to load it without retraining for prediction
I used model.save(path) to save the model, and got 4 files:
checkpoint model.ckpt.data-00000-of-00001 model.ckpt.index model.ckpt.meta
To load the model, I tried model = NCF(parameters) model.load(neumf_dir = model_path)
it worked, but when I run model.predict()
There's error: AttributeError: 'NCF' object has no attribute 'user2id'
Have no idea how to fix this.
It would help if you fed it data
parameters as shown in this notebook example
https://github.com/microsoft/recommenders/blob/main/examples/02_model_collaborative_filtering/ncf_deep_dive.ipynb
3.5.2 Load pre-trained GMF and MLP model for NeuMF
Does this mean that one cannot save NeuMF model, but have to train and save the GMF and MLP separately?
No, you can save the NeuMF model by providing the path
model.save('dir_path')
and then while loading depending on the type of your model in this case neumf
pass it that dir parameter
model.load(neumf_dir='dir_path')
Note: you have to create your model before loading with the same parameters, as shown in the example.
I still get 'NCF' object has no attribute 'user2id'
What I did:
model.fit(data)
modl.save('dir_path')
then opened a new console
data = NCFDataset(train_file = train_file, test_file = test_file, seed = SEED) #as the saved model
model = NCF ( the same parameters as the saved model)
model.load(neumf_dir='dir_path')
model.predict(users, items, is_list = True)
After loading you will have to specifically assign these attributes to NCF class
model.user2id = data.user2id
model.item2id = data.item2id
model.id2user = data.id2user
model.id2item = data.id2item
Thank you!Finally succeeded!
Description
I want to save the entire NCF model and use it without requiring the original model building code to run. How can I do that? The example in the deep dive notebook only shows how to save the model for further training which is not what I am looking for. Appreciate any reponses.
Other Comments