Model Explanations with Text Data

In this demo we will:

  • Launch a movie sentiment model which takes text input

  • Send a request to get a sentiment prediction

  • Create an explainer for the model

  • Send the same request and then get an explanation for it

The explainer uses the anchors technique to provide insight into why a particular classification was made by the model. We’ll see patterns in input text that are most relevant to the prediction outcome.

Create a V1 Seldon Deployment

  1. On the Overview page, click on Create new deployment.

  2. Enter the deployment details as follows, then click Next:

    Parameter

    Value

    Name

    movie

    Namespace

    seldon [1]

    Type

    Seldon Deployment

    Protocol

    Seldon

  3. Configure the default predictor as follows:

    Parameter

    Value

    Runtime

    Scikit Learn

    Model Project

    default

    Model URI

    gs://seldon-models/v1.18.1/sklearn/moviesentiment

    Storage Secret

    (leave blank/none) [2]

    Model Name

    (leave blank)

  4. Click Next for the remaining steps[3], then click Launch.

1. The
seldon
and
seldon-gitops
namespaces are installed by default, which may not always be available. Please select a namespace which best describes your environment.

2. A secret may be required for private buckets.
3. Additional steps may be required for your specific model.
Expand to see default predictor details

create_model

Get Predictions

  1. Click on the movie deployment created in the previous section to enter the deployment dashboard.

  2. Inside the deployment dashboard, click on the Predict button.

  3. On the Predict page, enter the following text:

    {
      "data": {
        "names": [
          "Text review"
        ],
        "ndarray": [
          "this film has bad actors"
        ]
      }
    }
    
  4. Click the Predict button.

Expand to see running prediction request

A screenshot showing the Predict page with the textarea prepopulated

Add an Anchor Text Explainer

To create an explainer[1], enter the deployment dashboard and click on Add within the Model Explanation widget to open the explainer creation wizard.

Step

Description

1

Click Text, then click Next.

2

Click Anchor, then click Next.

3

Click Next (do not fill in any fields).

4

Click Next (do not change any fields).

5

Click Next (do not change any fields). [2]

6

Click Launch.

After a short while, the explainer should become available.

1. It is only possible to create one explainer per deployment.
2. You may wish to enter a comment here for a gitops enabled namespace.
Expand to see explainer creation

Set explainer mode to Text Set explainer type to Anchors

Get Explanation for one Request

  1. Return to the Predict page described in the section Get Predictions.

  2. Resend a single request using the JSON below and then explain it:

    {
      "data": {
        "names": [
          "Text review"
        ],
        "ndarray": [
          "this film has bad actors"
        ]
      }
    }
    
  3. Click Explain to generate explanations for the request.

Expand to see explainer generation

Resending the prediction Explaining the request

Congratulations, you’ve created an explanation for the request! 🥳

Next Steps

Why not try our other demos? Ready to dive in? Read our operations guide to learn more about how to use Enterprise Platform.