Reuters Newswire Recommendation

This example will take you through creating a simple recommendation service for the the Reuters-21578 newswire dataset. It will create a simple static document similarity algorithm run as a microservice through the Seldon API server.

Prerequisites

Create Reuters client

The first step is to create a Reuters Seldon client and import the meta-data for the items we want to recommend into the Seldon database. These tasks are all packaged into a Docker container seldonio/examples-reuters-data whose source can be found in docker/examples/reuters/data. The tasks run are:

The Docker container can be run as a one-off Kubernetes job to carry out the tasks:

cd kubernetes/conf/examples/reuters/
kubectl create -f import-data-job.json

Check for successful completion using kubectl get jobs -l job-name=reuters-import-data which should show:

NAME                  DESIRED   SUCCESSFUL   AGE
reuters-import-data   1         1            1m

You can delete the job once its run with kubectl delete -f import-data-job.json

Create Recommendation Model

For this simple example we will build a document similarity model to provide recommendations for newswire article given the current newswire article a user is reading. For this we will build a gensim document similarity model. The detailed steps to build the model can be followed in a Jupyter notebook. These have been packaged into a docker container seldonio/reuters-example.

In general, Seldon provides several content recommendation models in Spark as well as python based modules.

Create Microservice

To serve predictions from our model we need to run the prepackaged docker image which exposes a microservice endpoint for the model scoring. To start any microservice and connect it to a client using the script kubernetes/bin/start-microservice.

The script creates a Kubernetes deployment for the microservice in kubernetes/conf/microservices. If the microserice is already running, Kubernetes will roll-down the previous version and roll-up the new version.

To start the Reuters gensim model serving run:

start-microservice --type recommendation --client reuters -i reuters-example seldonio/reuters-example:2.0.7 rest 1.0

The script will create the Kubernetes Deployment and use the seldon-cli to update the “reuters” client to add the microservice as a runtime algorithm. Check with kubectl get pods -l name=reuters-example that the pod running the mircroservice is running.

Serve Recommendations

You can now call the Seldon server using the Seldon CLI to test recommendations:

seldon-cli --quiet api --client-name reuters --endpoint  /js/recommendations --item 6020 --limit 3

The response should be like:

{
  "size": 3,
  "requested": 3,
  "list": [
    {
      "id": "5762",
      "name": "",
      "type": 1,
      "first_action": 1460480919000,
      "last_action": 1460480919000,
      "popular": false,
      "demographics": [],
      "attributes": {},
      "attributesName": {
        "recommendationUuid": "3",
        "title": "AERO SERVICES <AEROE> IN PACT FOR NOMINATIONS",
        "body": "Aero Services International Inc\nsaid it signed an agreement with Dibo Attar, who controls about\n39 pct of its common stock, under which three nominees to\nAero's board have been selected by Attar.\n    In addition to Attar, the nominees are Stephen L. Peistner,\nchairman and chief executive officer of <McCrory Corp> and\nJames N.C. Moffat III, vice president and secretary of\n<Eastover Corp>.\n Reuter\n\u0003"
      }
    },
    {
      "id": "11348",
      "name": "",
      "type": 1,
      "first_action": 1460480919000,
      "last_action": 1460480919000,
      "popular": false,
      "demographics": [],
      "attributes": {},
      "attributesName": {
        "recommendationUuid": "3",
        "title": "GANDALF <GANDF> ACQUIRES STAKE IN DATA/VOICE",
        "body": "Gandalf Technologies Inc said it\nacquired a significant minority equity interest in privately\nheld Data/Voice Solutions Corp, of Newport Beach, Calif., for\nundisclosed terms.\n    Gandalf did not specify the size of the interest.\n    Data/Voice is a three-year-old designer and manufacturer of\na multiprocessor, multiuser MS-DOS computing system that\nGandalf plans to integrate with its private automatic computer\nexchange information system, Gandalf said.\n Reuter\n\u0003"
      }
    },
    {
      "id": "7816",
      "name": "",
      "type": 1,
      "first_action": 1460480919000,
      "last_action": 1460480919000,
      "popular": false,
      "demographics": [],
      "attributes": {},
      "attributesName": {
        "recommendationUuid": "3",
        "title": "CELINA <CELNA> SHAREHOLDERS APPROVE SALE",
        "body": "Celina Financial Corp said\nshareholders at a special meeting approved a transaction in\nwhich the company transferred its interest in three insurance\ncompanies to a wholly owned subsidiary which then sold the\nthree companies to an affiliated subsidiary.\n    It said the company's interests in West Virginia Fire and\nCasualty Co, Congregation Insurance co and National Term Life\nInsurance Co had been transferred to First National Indemnity\nCo, which sold the three to Celina Mutual for cash, an office\nbuilding and related real estate.\n Reuter\n\u0003"
      }
    }
  ]
}

Troubleshooting

Check your Kuberentes DNS is working correctly and the reuters-example hostname can be found. Open a bash terminal into the seldon-control container and check using nslookup:

kubectl exec -ti seldon-control -- /bin/bash
root@seldon-control:/home/seldon# nslookup reuters-example
Server:				  	   10.0.0.10
Address:				   10.0.0.10#53

Name:					   reuters-example.default.svc.cluster.local
Address: 10.0.0.25

Next Steps