A Comparative Framework for Multimodal Recommender Systems
Project description
Cornac
Cornac is a comparative framework for multimodal recommender systems. It focuses on making it convenient to work with models leveraging auxiliary data (e.g., item descriptive text and image, social network, etc). Cornac enables fast experiments and straightforward implementations of new models. It is highly compatible with existing machine learning libraries (e.g., TensorFlow, PyTorch).
Cornac is one of the frameworks recommended by ACM RecSys 2023 for the evaluation and reproducibility of recommendation algorithms.
Quick Links
Website | Documentation | Tutorials | Examples | Models | Datasets | Paper | Preferred.AI
Installation
Currently, we are supporting Python 3. There are several ways to install Cornac:
-
From PyPI (recommended):
pip3 install cornac
-
From Anaconda:
conda install cornac -c conda-forge
-
From the GitHub source (for latest updates):
pip3 install Cython numpy scipy pip3 install git+https://github.com/PreferredAI/cornac.git
Note:
Additional dependencies required by models are listed here.
Some algorithm implementations use OpenMP
to support multi-threading. For Mac OS users, in order to run those algorithms efficiently, you might need to install gcc
from Homebrew to have an OpenMP compiler:
brew install gcc | brew link gcc
Getting started: your first Cornac experiment
Flow of an Experiment in Cornac
import cornac
from cornac.eval_methods import RatioSplit
from cornac.models import MF, PMF, BPR
from cornac.metrics import MAE, RMSE, Precision, Recall, NDCG, AUC, MAP
# load the built-in MovieLens 100K and split the data based on ratio
ml_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 BPR
mf = 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 models
metrics = [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:
MAE | RMSE | AUC | MAP | NDCG@10 | Precision@10 | Recall@10 | Train (s) | Test (s) | |
---|---|---|---|---|---|---|---|---|---|
MF | 0.7430 | 0.8998 | 0.7445 | 0.0548 | 0.0761 | 0.0675 | 0.0463 | 0.13 | 1.57 |
PMF | 0.7534 | 0.9138 | 0.7744 | 0.0671 | 0.0969 | 0.0813 | 0.0639 | 2.18 | 1.64 |
BPR | N/A | N/A | 0.8695 | 0.1042 | 0.1500 | 0.1110 | 0.1195 | 3.74 | 1.49 |
Model serving
Here, we provide a simple way to serve a Cornac model by launching a standalone web service with Flask. It is very handy for testing or creating a demo application. First, we install the dependency:
$ pip3 install Flask
Supposed 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' \
flask run --host localhost --port 8080
# Running on http://localhost:8080
Here we go, our model service is now ready. Let's get top-5
item recommendations for the user "63"
:
$ curl -X GET "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 provide TRAIN_SET
which has been saved with the model earlier, when starting the serving app. We can also leverage WSGI server for model deployment in production. Please refer to this guide for more details.
Efficient retrieval with ANN search
One important aspect of deploying recommender model is efficient retrieval via Approximate Nearest Neighbor (ANN) search in vector space. Cornac integrates several vector similarity search frameworks for the ease of deployment. This example demonstrates how ANN search will work seamlessly with any recommender models supporting it (e.g., matrix factorization).
Supported Framework | Cornac Wrapper | Example |
---|---|---|
spotify/annoy | AnnoyANN | quick-start, deep-dive |
meta/faiss | FaissANN | quick-start, deep-dive |
nmslib/hnswlib | HNSWLibANN | quick-start, hnsw-lib, deep-dive |
google/scann | ScaNNANN | quick-start, deep-dive |
Models
The table below lists the recommendation models/algorithms featured in Cornac. Examples are provided as quick-start showcasing an easy to run script, or as deep-dive explaining the math and intuition behind each model. Why don't you join us to lengthen the list?
Resources
- Cornac Examples
- Cornac Tutorials
- RecSys Tutorials by Preferred.AI
- Running Cornac Model with Microsoft Recommenders (BPR), (BiVAE)
- Multimodal RecSys Tutorial at TheWebConf/WWW 2023, earlier version at RecSys 2021
Contributing
This project welcomes contributions and suggestions. Before contributing, please see our contribution guidelines.
Citation
If you use Cornac in a scientific publication, we would appreciate citations to the following papers:
Cornac: A Comparative Framework for Multimodal Recommender Systems, Salah et 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, Truong et 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, Truong et 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}
}
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for cornac-2.2.2-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | da39399c2eff9f4d6d6b478e15dcc077dcdaeed3b73e00306d1a3ff92426eb2a |
|
MD5 | 5647aa6f5bb1e207406083a19110af27 |
|
BLAKE2b-256 | b73d7e76935453a335abf77a0460e8316c099ce4a530822fc306fbfac2168acc |
Hashes for cornac-2.2.2-cp312-cp312-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f167ecbda66905b7d9172c672390f477fea6f871eaf5d73e1834c4214070b104 |
|
MD5 | c157e506e84625b46f26044048fdecbf |
|
BLAKE2b-256 | f1e83676a22de971f8839cdbc0f043e4ba3209008a9119a74ef714b045ce417c |
Hashes for cornac-2.2.2-cp312-cp312-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b709166d9f0520b791cb99f219f1748ae08b62b9df3de2b4f03b8c651ccfddb |
|
MD5 | d0b4e7a78f3ccf42aa449809cf9292ec |
|
BLAKE2b-256 | 4443c2f8f65f7fce5a1466403e9c31a24a71600eb900b3491a344a38679a77bd |
Hashes for cornac-2.2.2-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b08a29f810a9cbbe1bb7a9c039c047e25b82e9692efeb2f12ea0000c7e0d9a90 |
|
MD5 | 1ad2b5ed2a9faf9e5311dc78a4ddce4a |
|
BLAKE2b-256 | f6919f89ef4a1f4c330334064e69a8ee3db7bbb964cfdc74fc16f02b186023a6 |
Hashes for cornac-2.2.2-cp311-cp311-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d19c1116792b997ea4f32e95e4dfbda02afb196e07c8c74ca70471da08104e0 |
|
MD5 | 1617b17f4b52a707bd75d0206ce2ef94 |
|
BLAKE2b-256 | 11f4d8623b544235267173d4a342082669e77ad0a83b98751cf9854a9d5979ea |
Hashes for cornac-2.2.2-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 271e0de15f2e746da1d2f5ea208c81b88436f895014546f503899e728d239c4a |
|
MD5 | 19487c853e72153815188ca22f279693 |
|
BLAKE2b-256 | e898af50111e11f65d0aced373c2350c60056aae1dff00c954aa96c6092bb67b |
Hashes for cornac-2.2.2-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8f6d0e360aaec95e1a8bee1453b79464910d3563cb4218ed31ee8234173b66d |
|
MD5 | 39b9bc6e3d3ec5c329b3c82a6e8cc8fc |
|
BLAKE2b-256 | e5d1fcf6e4c367cc37413d2c3d8e3dd573357568571219ce3ffeaf6fcd0f0a69 |
Hashes for cornac-2.2.2-cp310-cp310-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5cd691eae4f6c8de9a960fd1692908bf268528773b7ecefdf85043ccd011c5e |
|
MD5 | 6e6a301b77ba4b64793cd92712dc0bb2 |
|
BLAKE2b-256 | 52d358f597d69f02ada531c18da4aff84161e0b097d264f43903dd2646291a63 |
Hashes for cornac-2.2.2-cp310-cp310-macosx_12_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f083dafec57e1fa5bd0aaa72faacba93e8b03802e3c432c5616a50c5e200e6d |
|
MD5 | 30054066b42305de43572a5a4143858d |
|
BLAKE2b-256 | 1287f1b36a505c63643d6aaedac917e5b938cf277825321c8719a0cd7bcac70e |
Hashes for cornac-2.2.2-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6408cefad0be76ec699844a248bdda3fbf748ca52d94c82d22cdc20f79ac514c |
|
MD5 | 331a4a2b59c7bb44c03820745ae975bb |
|
BLAKE2b-256 | 0f6c8639796efa69c4ea1fe4235414ae59cfa3b2d758e3c44b529aac4af21e32 |
Hashes for cornac-2.2.2-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1210332b8bd6e77759fb9ae6fcc4ac10a2e1df104d6a33e9a77b12966289cfd0 |
|
MD5 | 89cd58482acb4fe78d5d9a533c7aa0c6 |
|
BLAKE2b-256 | 6e041f5c8f02c782f82753ce5226b8141584559b29d582c51642b334c74189a9 |
Hashes for cornac-2.2.2-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68600d555f5108a3b78ce8b6aa7ead7d4c20893f2369fbd8657fbf7604a72b0c |
|
MD5 | df09c06309d0fc016eb2c3f213a11182 |
|
BLAKE2b-256 | a86d6b554a0eb3d79ae2b50c5318b2ca7c96f5cfbdb12f6678b4cf2bd95d38cc |
Hashes for cornac-2.2.2-cp39-cp39-macosx_14_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45e8fdb04b9b1f6bedebda99a10b74ce8f0490029cb32f02d7c3a0eb3c92fd74 |
|
MD5 | da4fbb0e5e2c252a490a52aa518c3809 |
|
BLAKE2b-256 | 71402db524cde53fe4b5ad098515059231e36825e28672e1355ac0a59db69153 |
Hashes for cornac-2.2.2-cp39-cp39-macosx_12_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01005551be9150050cdbbe263df2209092181734ba3e4f04bd11cc55d6764933 |
|
MD5 | 958ad7b60b91412f7b36737f7346fd2b |
|
BLAKE2b-256 | 99c0fd9e25b9994fef3a164409077f7f12773c988cf28ded0b332fe658b4d5ab |
Hashes for cornac-2.2.2-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c8a7a2383342dc51d24f9935aa0857cf2c4002361e6057b4e7274ffde67de34 |
|
MD5 | 6232e6f1346543062a12194229871f7d |
|
BLAKE2b-256 | c27cc320a3d4be6d9714b94fb6cd0a5135f1ebea01666f7ecf52eadc8f26197c |
Hashes for cornac-2.2.2-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aacaa466ad7d010ed45ee129334de80a0e982129aabb69e6c3d0753adaa8767b |
|
MD5 | 46d80f2c6b558af399d58718e7fd1c33 |
|
BLAKE2b-256 | 09592ca9ae87dc7c8c0f742f5093cc11900242628a78fe19ff7af1f4cbb193cb |
Hashes for cornac-2.2.2-cp38-cp38-macosx_14_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2d8c5c76e785a52d74c5b4223b0690bef2c43b840b5f3376c28873a0fe57a81 |
|
MD5 | edc348244b1c13e6f7549dd35c6c0d8b |
|
BLAKE2b-256 | 4d54d8f58e2f696b28d4fc7835024510b0ec79f3b1fc22a732f3f8710aedeb8c |
Hashes for cornac-2.2.2-cp38-cp38-macosx_12_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 062959f04368606aa984c27e0e92c053bc21519352f9ad1c66730a91a229b0d4 |
|
MD5 | 1c55ac1d973d2bb49298937cfd010ea9 |
|
BLAKE2b-256 | 557f992377271169845767f76a3fc76a96ba8fa60e76055e9b20a4c9c8fe4553 |