# Text Explanations

This demo helps you learn about:

* Launching a movie sentiment pipeline which takes text input
* Sending a request to get a sentiment prediction
* Creating an explainer for the model
* Sending the same request and then get an explanation

The explainer uses the [anchor technique](/seldon-enterprise-platform/product-tour/model-explanations.md) 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 Seldon Deployment

1. In the **Overview** page, click **Create new deployment**.
2. Type the following deployment details and click **Next**:

   | Parameter | Value             |
   | --------- | ----------------- |
   | Name      | movie             |
   | Namespace | seldon            |
   | Type      | Seldon Deployment |
3. Configure the default predictor as follows:

   | Parameter      | Value                                                        |
   | -------------- | ------------------------------------------------------------ |
   | Runtime        | Scikit Learn                                                 |
   | Model Project  | default                                                      |
   | Model URI      | `gs://seldon-models/scv2/examples/moviesentiment/classifier` |
   | Storage Secret | (leave blank/none)                                           |
   | Model Name     | `movies`                                                     |

{% hint style="warning" %}
The `Model Name` is linked to the name described in the `model-settings.json` file, located in the Google Cloud Storage location. Changing the name in the JSON file would also require changing the `Model Name`, and vice versa.
{% endhint %}

4. Click **Next** for the remaining steps in the **Deployment Creation Wizard** and then click **Launch**.

![Default predictor details](/files/ujs3fkZAt2FATbMoJUjg)

{% hint style="info" %}

* The `seldon` and `seldon-gitops` namespaces are installed by default, which may not always be available. Select a namespace which best describes your environment.
* A secret may be required for private buckets.
* Additional steps may be required for your specific model.
  {% endhint %}

## Get Predictions

1. Click the **movie** deployment that you created.
2. In the **Deployment Dashboard**, click **Predict** in the left pane.
3. In the **Predict** page, click **Enter JSON** and paste the following text:

   ```JSON
   {
     "parameters": {
       "content_type": "str"
     },
     "inputs": [{
       "name": "text review",
       "shape": [1],
       "datatype": "BYTES",
       "data": ["this film has bad actors"]
     }]
   }
   ```
4. Click **Predict**.

![the Predict page with the textarea prepopulated](/files/0WOXJIunR3ZLKIaeCUgE)

## Add an Anchor Text Explainer

1. In the **Deployment Dashboard** page for the deployment `movie`, click **Add** inside the **MODEL EXPLANATION** card.
2. In the **Explainer Configuration Wizard**, choose **Text** and click **Next**.
3. In the **Explainer Types** step, choose the **Anchor** option and click **Next**.
4. In the **Explainer URI** step, set the following details:

   ```
   - Explainer URI: gs://seldon-models/scv2/examples/moviesentiment/explainer
   - Explainer Project: default
   ```
5. Click **Next** for the remaining steps without changing any fields, and click **Launch**.

After sometime, the explainer should become available.

{% hint style="info" %}

* It is only possible to create one explainer for each deployment.
* You can also enter a comment here for a gitops enabled namespace.
  {% endhint %}

![Explainer URI details](/files/JcDBz4N9ETeDInhs9b5U)

## Get Explanation for one Request

1. In the **Deployment Dashboard** for the deployment named `movie`, click **Predict** in the left pane.
2. In the **Predict** page, click **Enter JSON** and once again paste the following text and click **Predict**:

   ```JSON
   {
     "parameters": {
       "content_type": "str"
     },
     "inputs": [{
       "name": "text review",
       "shape": [1],
       "datatype": "BYTES",
       "data": ["this film has bad actors"]
     }]
   }
   ```
3. Click **Explain** to generate explanations for the request.

![Resending the prediction](/files/5uNfC2qa9w0RRzXPnrEj)

![Explaining the request](/files/a0MkwQTcp5Kc6w3wPfWm)

{% hint style="info" %}
**Note**: If the explainer is making use of `parameters.content_type` field, `View explanation` button from the **Requests dashboard** then it leads to the server error. The `/explain` API works as expected if `parameters.content_type` is included in the request input.
{% endhint %}

## Next Steps

Try the other [demos](/seldon-enterprise-platform/demos.md) or read our [operations guide](/seldon-enterprise-platform/operations.md) to learn more about how to use Seldon Enterprise Platform.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.seldon.ai/seldon-enterprise-platform/demos/seldon-core-v1/explainer-anchor-text.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
