This repository contains code to instantiate and deploy a recommender model. This model can be trained on a dataset containing users, items, ratings, and timestamps and make personalized item recommendations for a given user. Once trained, the input to the model is a user IDs and the output is a list of recommended item IDs sorted by probability in descending order. For demo purposes this model has been trained on a subset of the MovieTweetings Dataset, containing 457 users with their IDs mapped from 0 to 457 for convenience.
The model is based on the Neural Collaborative Filtering model. The model files are hosted on IBM Cloud Object Storage. The code in this repository deploys the model as a web service in a Docker container. This repository was developed as part of the IBM Developer Model Asset Exchange and the public API is powered by IBM Cloud.
Domain | Application | Industry | Framework | Training Data | Input Data Format |
---|---|---|---|---|---|
Information Retrieval | Recommendations | Commerce | TensorFlow | MovieTweetings | CSV |
- X. He, L. Liao, H. Zhang, L. Nie, X. Hu, T. Chua, "Neural Collaborative Filtering", WWW 2017.
- Microsoft Recommender Systems GitHub Repo
Component | License | Link |
---|---|---|
This repository | Apache 2.0 | LICENSE |
Model Weights | Apache 2.0 | LICENSE |
Model Code (3rd party) | MIT | Microsoft Recommender Systems GitHub Repo |
docker
: The Docker command-line interface. Follow the installation instructions for your system.- The minimum recommended resources for this model is 4GB Memory and 2 CPUs.
To run the docker image, which automatically starts the model serving API, run:
$ docker run -it -p 5000:5000 quay.io/codait/max-recommender
This will pull a pre-built image from the Quay.io container registry (or use an existing image if already cached locally) and run it. If you'd rather checkout and build the model locally you can follow the run locally steps below.
You can also deploy the model on Kubernetes using the latest docker image on Quay.
On your Kubernetes cluster, run the following commands:
$ kubectl apply -f https://github.com/IBM/MAX-Recommender/raw/master/max-recommender.yaml
The model will be available internally at port 5000
, but can also be accessed externally through the NodePort
.
A more elaborate tutorial on how to deploy this MAX model to production on IBM Cloud can be found here.
Follow the instructions for the OpenShift web console or the OpenShift Container Platform CLI in this tutorial and specify quay.io/codait/max-recommender
as the image name.
Clone this repository locally. In a terminal, run the following command:
$ git clone https://github.com/IBM/MAX-Recommender.git
Change directory into the repository base folder:
$ cd MAX-Recommender
To build the docker image locally, run:
$ docker build -t max-recommender .
All required model assets will be downloaded during the build process. Note that currently this docker image is CPU only (we will add support for GPU images later).
To run the docker image, which automatically starts the model serving API, run:
$ docker run -it -p 5000:5000 max-recommender
The API server automatically generates an interactive Swagger documentation page. Go to http://localhost:5000
to load it. From there you can explore the API and also create test requests.
User the model/predict
endpoint to retrieve recommendations for a user ID. The number of predictions returned can be specified with num_results
, by default the model returns 5 predictions.
You can also test it on the command line, for example:
$ curl -X POST "http://localhost:5000/model/predict?user_id=1&num_results=5" -H "accept: application/json"
You should see a JSON response like that below:
{
"status": "ok",
"predictions": [
{
"user": "1",
"item": "1454468",
"prediction": 0.995230495929718
},
{
"user": "1",
"item": "1300854",
"prediction": 0.9938176274299622
},
{
"user": "1",
"item": "77413",
"prediction": 0.9930911064147949
},
{
"user": "1",
"item": "1731141",
"prediction": 0.9929673671722412
},
{
"user": "1",
"item": "363226",
"prediction": 0.9914621710777283
}
]
}
To run the Flask API app in debug mode, edit config.py
to set DEBUG = True
under the application settings. You will then need to rebuild the docker image (see step 1).
To stop the Docker container, type CTRL
+ C
in your terminal.