Skip to content

Mr6one/recsys-project-2023

Repository files navigation

PyTorch RecSys

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

Installation

git clone https://github.com/Mr6one/recsys-project-2023.git && cd recsys-project-2023
pip install -r requirements.txt

Usage

Basics

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

GPU Utilization

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

Checkpointing

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

Logging

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

Results

Metrics obtained on the MovieLens dataset

image

Metrics obtained on the Yelp dataset

image

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.

About

Skoltech Project for Recommendation Systems Course

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published