Package: cornac
CornacCornacis a comparative framework for multimodal recommender systems. It focuses on making itconvenientto work with models leveragingauxiliary data(e.g., item descriptive text and image, social network, etc).Cornacenablesfastexperiments andstraightforwardimplementations of new models. It ishighly compatiblewith existing machine learning libraries (e.g., TensorFlow, PyTorch).Cornac is one of the frameworks recommended byACM RecSys 2023for the evaluation and reproducibility of recommendation algorithms.Quick LinksWebsite|Documentation|Tutorials|Examples|Models|Datasets|Paper|Preferred.AIInstallationCurrently, we are supporting Python 3. There are several ways to install Cornac:From PyPI (recommended):pip3installcornacFrom Anaconda:condainstallcornac-cconda-forgeFrom the GitHub source (for latest updates):pip3installCythonnumpyscipy
pip3installgit+https://github.com/PreferredAI/cornac.gitNote:Additional dependencies required by models are listedhere.Some algorithm implementations useOpenMPto support multi-threading. For Mac OS users, in order to run those algorithms efficiently, you might need to installgccfrom Homebrew to have an OpenMP compiler:brewinstallgcc|brewlinkgccGetting started: your first Cornac experimentFlow of an Experiment in Cornacimportcornacfromcornac.eval_methodsimportRatioSplitfromcornac.modelsimportMF,PMF,BPRfromcornac.metricsimportMAE,RMSE,Precision,Recall,NDCG,AUC,MAP# load the built-in MovieLens 100K and split the data based on ratioml_100k=cornac.datasets.movielens.load_feedback()rs=RatioSplit(data=ml_100k,test_size=0.2,rating_threshold=4.0,seed=123)# initialize models, here we are comparing: Biased MF, PMF, and BPRmf=MF(k=10,max_iter=25,learning_rate=0.01,lambda_reg=0.02,use_bias=True,seed=123)pmf=PMF(k=10,max_iter=100,learning_rate=0.001,lambda_reg=0.001,seed=123)bpr=BPR(k=10,max_iter=200,learning_rate=0.001,lambda_reg=0.01,seed=123)models=[mf,pmf,bpr]# define metrics to evaluate the modelsmetrics=[MAE(),RMSE(),Precision(k=10),Recall(k=10),NDCG(k=10),AUC(),MAP()]# put it together in an experiment, voilà!cornac.Experiment(eval_method=rs,models=models,metrics=metrics,user_based=True).run()Output:MAERMSEAUCMAPNDCG@10Precision@10Recall@10Train (s)Test (s)MF0.74300.89980.74450.05480.07610.06750.04630.131.57PMF0.75340.91380.77440.06710.09690.08130.06392.181.64BPRN/AN/A0.86950.10420.15000.11100.11953.741.49For more details, please take a look at ourexamplesas well astutorials. For learning purposes, this list oftutorials on recommender systemswill be more organized and comprehensive.Model servingHere, we provide a simple way to serve a Cornac model by launching a standalone web service withFlask. It is very handy for testing or creating a demo application. First, we install the dependency:$pip3installFlaskSupposed that we want to serve the trained BPR model from previous example, we need to save it:bpr.save("save_dir",save_trainset=True)After that, the model can be deployed easily by running Cornac serving app as follows:$FLASK_APP='cornac.serving.app'\MODEL_PATH='save_dir/BPR'\MODEL_CLASS='cornac.models.BPR'\flaskrun--hostlocalhost--port8080# Running on http://localhost:8080Here we go, our model service is now ready. Let's gettop-5item recommendations for the user"63":$curl-XGET"http://localhost:8080/recommend?uid=63&k=5&remove_seen=false"# Response: {"recommendations": ["50", "181", "100", "258", "286"], "query": {"uid": "63", "k": 5, "remove_seen": false}}If we want to remove seen items during training, we need to provideTRAIN_SETwhich has been saved with the model earlier, when starting the serving app. We can also leverageWSGIserver for model deployment in production. Please refer tothisguide for more details.Efficient retrieval with ANN searchOne important aspect of deploying recommender model is efficient retrieval via Approximate Nearest Neighor (ANN) search in vector space. Cornac integrates several vector similarity search frameworks for the ease of deployment.This exampledemonstrates how ANN search will work seamlessly with any recommender models supporting it (e.g., MF).Supported frameworkCornac wrapperExamplesspotify/annoyAnnoyANNann_all.ipynbmeta/faissFaissANNann_all.ipynbnmslib/hnswlibHNSWLibANNann_hnswlib.ipynb,ann_all.ipynbgoogle/scannScaNNANNann_all.ipynbModelsThe recommender models supported by Cornac are listed below. Why don't you join us to lengthen the list?YearModel and paperAdditional dependenciesExamples2021Bilateral Variational Autoencoder for Collaborative Filtering (BiVAECF),paperrequirements.txtPreferredAI/bi-vaeCausal Inference for Visual Debiasing in Visually-Aware Recommendation (CausalRec),paperrequirements.txtcausalrec_clothing.pyExplainable Recommendation with Comparative Constraints on Product Aspects (ComparER),paperN/APreferredAI/ComparER2020Adversarial Training Towards Robust Multimedia Recommender System (AMR),paperrequirements.txtamr_clothing.pyHybrid neural recommendation with joint deep representation learning of ratings and reviews (HRDR),paperrequirements.txthrdr_example.pyLightGCN: Simplifying and Powering Graph Convolution Network for Recommendation,paperrequirements.txtlightgcn_example.py2019Embarrassingly Shallow Autoencoders for Sparse Data (EASEᴿ),paperN/Aease_movielens.pyNeural Graph Collaborative Filtering (NGCF),paperrequirements.txtngcf_example.py2018Collaborative Context Poisson Factorization (C2PF),paperN/Ac2pf_exp.pyGraph Convolutional Matrix Completion (GCMC),paperrequirements.txtgcmc_example.pyMulti-Task Explainable Recommendation (MTER),paperN/Amter_exp.pyNeural Attention Rating Regression with Review-level Explanations (NARRE),paperrequirements.txtnarre_example.pyProbabilistic Collaborative Representation Learning (PCRL),paperrequirements.txtpcrl_exp.pyVariational Autoencoder for Collaborative Filtering (VAECF),paperrequirements.txtvaecf_citeulike.py2017Collaborative Variational Autoencoder (CVAE),paperrequirements.txtcvae_exp.pyConditional Variational Autoencoder for Collaborative Filtering (CVAECF),paperrequirements.txtcvaecf_filmtrust.pyGeneralized Matrix Factorization (GMF),paperrequirements.txtncf_exp.pyIndexable Bayesian Personalized Ranking (IBPR),paperrequirements.txtibpr_exp.pyMatrix Co-Factorization (MCF),paperN/Amcf_office.pyMulti-Layer Perceptron (MLP),paperrequirements.txtncf_exp.pyNeural Matrix Factorization (NeuMF) / Neural Collaborative Filtering (NCF),paperrequirements.txtncf_exp.pyOnline Indexable Bayesian Personalized Ranking (Online IBPR),paperrequirements.txtVisual Matrix Factorization (VMF),paperrequirements.txtvmf_clothing.py2016Collaborative Deep Ranking (CDR),paperrequirements.txtcdr_exp.pyCollaborative Ordinal Embedding (COE),paperrequirements.txtConvolutional Matrix Factorization (ConvMF),paperrequirements.txtconvmf_exp.pyLearn to Rank user Preferences based on Phrase-level sentiment analysis across Multiple categories (LRPPM),paperN/Alrppm_example.pySpherical K-means (SKM),paperN/Askm_movielens.pyVisual Bayesian Personalized Ranking (VBPR),paperrequirements.txtvbpr_tradesy.py2015Collaborative Deep Learning (CDL),paperrequirements.txtcdl_exp.pyHierarchical Poisson Factorization (HPF),paperN/Ahpf_movielens.pyTriRank: Review-aware Explainable Recommendation by Modeling Aspects,paperN/Atrirank_example.py2014Explicit Factor Model (EFM),paperN/Aefm_example.pySocial Bayesian Personalized Ranking (SBPR),paperN/Asbpr_epinions.py2013Hidden Factors and Hidden Topics (HFT),paperN/Ahft_exp.py2012Weighted Bayesian Personalized Ranking (WBPR),paperN/Abpr_netflix.py2011Collaborative Topic Regression (CTR),paperN/Actr_citeulike.pyEarlierBaseline Only,paperN/Asvd_exp.pyBayesian Personalized Ranking (BPR),paperN/Abpr_netflix.pyFactorization Machines (FM),paperLinux onlyfm_example.pyGlobal Average (GlobalAvg),paperN/Abiased_mf.pyGlobal Personalized Top Frequent (GPTop),paperN/Agp_top_tafeng.pyItem K-Nearest-Neighbors (ItemKNN),paperN/Aknn_movielens.pyMatrix Factorization (MF),paperN/Abiased_mf.py,given_data.pyMaximum Margin Matrix Factorization (MMMF),paperN/Ammmf_exp.pyMost Popular (MostPop),paperN/Abpr_netflix.pyNon-negative Matrix Factorization (NMF),paperN/Anmf_exp.pyProbabilistic Matrix Factorization (PMF),paperN/Apmf_ratio.pySingular Value Decomposition (SVD),paperN/Asvd_exp.pySocial Recommendation using PMF (SoRec),paperN/Asorec_filmtrust.pyUser K-Nearest-Neighbors (UserKNN),paperN/Aknn_movielens.pyWeighted Matrix Factorization (WMF),paperrequirements.txtwmf_exp.pyContributingThis project welcomes contributions and suggestions. Before contributing, please see ourcontribution guidelines.CitationIf you use Cornac in a scientific publication, we would appreciate citations to the following papers:Cornac: A Comparative Framework for Multimodal Recommender Systems, Salahet al., Journal of Machine Learning Research, 21(95):1–5, 2020.@article{salah2020cornac,
  title={Cornac: A Comparative Framework for Multimodal Recommender Systems},
  author={Salah, Aghiles and Truong, Quoc-Tuan and Lauw, Hady W},
  journal={Journal of Machine Learning Research},
  volume={21},
  number={95},
  pages={1--5},
  year={2020}
}Exploring Cross-Modality Utilization in Recommender Systems, Truonget al., IEEE Internet Computing, 25(4):50–57, 2021.@article{truong2021exploring,
  title={Exploring Cross-Modality Utilization in Recommender Systems},
  author={Truong, Quoc-Tuan and Salah, Aghiles and Tran, Thanh-Binh and Guo, Jingyao and Lauw, Hady W},
  journal={IEEE Internet Computing},
  year={2021},
  publisher={IEEE}
}Multi-Modal Recommender Systems: Hands-On Exploration, Truonget al., ACM Conference on Recommender Systems, 2021.@inproceedings{truong2021multi,
  title={Multi-modal recommender systems: Hands-on exploration},
  author={Truong, Quoc-Tuan and Salah, Aghiles and Lauw, Hady},
  booktitle={Fifteenth ACM Conference on Recommender Systems},
  pages={834--837},
  year={2021}
}LicenseApache License 2.0