SKLearn Spacy NLP

In this example we will be buiding a text classifier using the reddit content moderation dataset.

For this, we will be using SpaCy for the word tokenization and lemmatization.

The classification will be done with a Logistic Regression binary classifier.

For more information please visit: https://towardsdatascience.com/real-time-stream-processing-for-machine-learning-at-scale-with-spacy-kafka-seldon-core-6360f2fedbe

The steps in this tutorial include:

  1. Train and build your NLP model

  2. Build your containerized model

  3. Test your model as a docker container

  4. Run Seldon in your kubernetes cluster

  5. Deploy your model with Seldon

  6. Interact with your model through API

  7. Clean your environment

Before you start

Make sure you install the following dependencies, as they are critical for this example to work:

  • Helm v3.0.0+

  • A Kubernetes cluster running v1.13 or above (minkube / docker-for-windows work well if enough RAM)

  • kubectl v1.14+

  • Python 3.6+

  • Python DEV requirements (we'll install them below)

Let's get started! 🚀🔥

1) Train and build your NLP model

prev_idx
parent_idx
body
removed

0

8756

8877

Always be wary of news articles that cite unpu...

0

1

7330

7432

The problem I have with this is that the artic...

0

2

15711

15944

This is indicative of a typical power law, and...

0

3

1604

1625

This doesn't make sense. Chess obviously trans...

0

4

13327

13520

1. I dispute that gene engineering is burdenso...

0

png

2) Build your containerized model

Create Docker Image with the S2i utility

Using the S2I command line interface we wrap our current model to seve it through the Seldon interface

To create a docker image we need to creat s2i folder configuration as below:

3) Test your model as a docker container

4) Run Seldon in your kubernetes cluster

Setup Seldon Core

Use the setup notebook to Setup Cluster with Ambassador Ingress or Istio and Install Seldon Core. Instructions also online.

5) Deploy your model with Seldon

We can now deploy our model by using the Seldon graph definition:

Note: if you are using kind preload image first with

6) Interact with your model through API

Now that our Seldon Deployment is live, we are able to interact with it through its API.

There are two options in which we can interact with our new model. These are:

a) Using CURL from the CLI (or another rest client like Postman)

b) Using the Python SeldonClient

a) Using CURL from the CLI

b) Using the Python SeldonClient

7) Clean your environment

Last updated

Was this helpful?