Comments (7)
NMSLibAlternatingLeastSquares
is also unpickable because of error can't pickle nmslib.dist.FloatIndex objects
.
from implicit.
This isn't something that is explicitly supported - but should work for all the models except for the AnnoyAlternatingLeastSquares class (since annoy doesn't support pickle).
from implicit.
In case of NMSLibAlternatingLeastSquares, index and model can be saved/pickled separately. Following code works for me.
class NMSLibAlternatingLeastSquaresRecommender(implicit.approximate_als.NMSLibAlternatingLeastSquares):
def save(self, dirpath):
pkl_file = os.path.join(dirpath, 'model.pickle')
index_file = os.path.join(dirpath, 'search_index')
self.recommend_index.saveIndex(filename=index_file, save_data=True)
self.recommend_index = None
with open(pkl_file, 'wb') as pickle_out:
pickle.dump(self, pickle_out)
def load_model(dirpath):
pkl_file = os.path.join(dirpath, 'model.pickle')
index_file = os.path.join(dirpath, 'search_index')
with open(pkl_file, 'rb') as pickle_in:
model = pickle.load(pickle_in)
model.recommend_index = nmslib.init(method="hnsw", space="cosinesimil")
model.recommend_index.loadIndex(filename=index_file, load_data=True)
return model
from implicit.
With #47 , you can save the AnnoyAlternatingLeastSquares model using annoy's serialization methods.
from implicit.
Cant pickle FaissAlternatingLeastSquares model too.
error: can't pickle SwigPyObject objects
from implicit.
@benfred can you please add save and load as suggested above?
from implicit.
In case of NMSLibAlternatingLeastSquares, index and model can be saved/pickled separately. Following code works for me.
class NMSLibAlternatingLeastSquaresRecommender(implicit.approximate_als.NMSLibAlternatingLeastSquares): def save(self, dirpath): pkl_file = os.path.join(dirpath, 'model.pickle') index_file = os.path.join(dirpath, 'search_index') self.recommend_index.saveIndex(filename=index_file, save_data=True) self.recommend_index = None with open(pkl_file, 'wb') as pickle_out: pickle.dump(self, pickle_out) def load_model(dirpath): pkl_file = os.path.join(dirpath, 'model.pickle') index_file = os.path.join(dirpath, 'search_index') with open(pkl_file, 'rb') as pickle_in: model = pickle.load(pickle_in) model.recommend_index = nmslib.init(method="hnsw", space="cosinesimil") model.recommend_index.loadIndex(filename=index_file, load_data=True) return model
I get
class NMSLibAlternatingLeastSquaresRecommender(NMSLibAlternatingLeastSquares):
TypeError: function() argument 'code' must be code, not str
python-BaseException
since NMSLibAlternatingLeastSquares is actually a function?
from implicit.
Related Issues (20)
- Saving NmsLibModel HOT 1
- numpy has teriminated the `get_info` method HOT 4
- Evaluation module not working HOT 1
- Adding `numpy` to `requirements.txt`
- pip install implicit is not work to use GPU HOT 3
- Incremental update with old users but new items HOT 4
- als explain method bug
- Usage of the trained model on testing.
- ranking metrics fail when model trained on CPU but not GPU?; implicit 0.7.2 HOT 1
- Python issue HOT 4
- Is it possible to compare scores across multiple results?
- function get_lastfm() error
- getting index error while using recommend function while ALS algorithm
- What is a good enough Precision@K and MAP@K value?
- BPR results not reproducible using multiple threads
- gpu issue on colab (implicit==0.7.2 / cuda ==12.1) HOT 1
- Potential error in the calculation of precision@k HOT 2
- Early stopping for ALS
- How recommend method works in Nearest Neighbour Models? HOT 1
- Potential bug in calculation of gradient updates for BPR
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from implicit.