This repo contains a PyTorch implementation of ALS algorithm for Collaborative Filtering and its extentions — eALS and iALS. Additionally, it provides the implementation of NGCF — Neural Graph for Collaborative Filtering.
Project presentation
Project report
git clone https://github.com/Mr6one/recsys-project-2023.git && cd recsys-project-2023
pip install -r requirements.txt
For all models you need simply provide a single matrix X of user-item interactions in any sparse format supported by scipy.sparse. For NGCF you need additionally provide the number of users and items.
from src.models import ALS # eALS, iALS, NGCF
model = ALS().fit(X) # fit the model
model.recommend(user_ids, N=5) # generate top 5 recommendations for users
All models support GPU and may be easily transfered between devices
model = ALS(device='cuda').fit(X) # create and fit model on cuda
model = model.cpu() # switch to cpu
model = model.cuda() # back to gpu
You can save and load the pretrained models. Note: the models are allocated to cpu before saving, so don't forget to switch back to cuda after loading.
model = iALS(device='cuda').fit(X) # train model on large dataset with high-end GPU
model.save('ials.pkl') # save model
model = iALS.from_checkpoint('ials.pkl').cuda() # use it on weak laptop
Moreover, the NGCF model supports tensorboard for logging and you can track the training process with following command
tensorboard --logdir=lightning_logs --port=6009
Then go to localhost:6009
Metrics obtained on the MovieLens dataset
Metrics obtained on the Yelp dataset
Time complexities graphs for ALS, eALS, iALS models
For full reuslts see the notebook. The most straingtforward way to reproduce our results is
python main.py --config ./configs/{model_name}_base.json
Or use the pretrained models. Don't forget to choose the appropriate dataset.