> For the complete documentation index, see [llms.txt](https://docs.nannyml.com/cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nannyml.com/cloud/v0.20.2/model-monitoring/tutorials/monitoring-a-text-classification-model.md).

# Monitoring a text classification model

Tutorial explaining how to monitor text classification models with NannyML

In this tutorial, we will use nannyML cloud to monitor a sentiment analysis text classification model where the model's goal is to predict the sentiment (Negative, Neutral, Positive) of a review left on Amazon.

## The model and dataset

We will use a model trained on a subset of the [Multilingual Amazon Reviews Dataset](https://huggingface.co/datasets/amazon_reviews_multi). The trained model can be found in the [nannyML's hugging face hub](https://huggingface.co/NannyML/amazon-reviews-sentiment-bert-base-uncased-6000-samples).&#x20;

For details of how this model was produced, check out the blog post: [Are your NLP models deteriorating post-deployment? Let’s use unlabelled data to find out](https://huggingface.co/blog/santiviquez/performance-estimation-nlp-nannyml).

## Reference and analysis sets

To evaluate the model in production, we have two sets:

* **Reference set** - which contains all model inputs along with the model’s predictions and labels. This set establishes a baseline for every metric we want to monitor. Find the reference set: <https://raw.githubusercontent.com/NannyML/sample_datasets/main/amazon_reviews/amazon_reviews_reference.csv>
* **Analysis set** - which contains all model inputs extracted from a production set with the model’s prediction, and in this case, labels. The analysis set is where NannyML analyzes/monitors the model’s performance and data drift of the model using the knowledge gained from the reference set. Find the analysis set: <https://raw.githubusercontent.com/NannyML/sample_datasets/main/amazon_reviews/amazon_reviews_analysis_targets.csv>

## Monitoring with nannyML Cloud

### Step 1: Add a new model

Click the Add model button to create a new model on your nannyML cloud dashboard.

<figure><img src="https://2363051145-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWcs3xQupCdtvmF6k2Sun%2Fuploads%2FIXKLYOI6bsILElhBSO6X%2FScreenshot%202023-11-16%20at%2011.59.19.png?alt=media&amp;token=b3cf1a92-8a90-4ba8-8085-f4cc31b4ddbb" alt=""><figcaption></figcaption></figure>

### Step 2: Define the problem type and main metric

Each review that we are classifying can be Negative, Positive, or Neutral. For this reason, we will set the problem type as **Multiclass classification.**

We will be monitoring the model's F1-score on a weekly basis.

<figure><img src="https://2363051145-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWcs3xQupCdtvmF6k2Sun%2Fuploads%2F3NA7JnbmEysi81UAnFxi%2FScreenshot%202023-11-21%20at%2008.40.06.png?alt=media&amp;token=e9b8e0d6-86c5-4aec-8cc5-8e170c15805d" alt=""><figcaption></figcaption></figure>

### Step 3: Configure the Reference set

Select "Upload via public link".

<figure><img src="https://2363051145-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWcs3xQupCdtvmF6k2Sun%2Fuploads%2FuHqrkzDXn0SNwPF9Jyuv%2FScreenshot%202023-11-20%20at%2014.39.37.png?alt=media&amp;token=f70f5688-d4ef-4044-ab8f-3e59f1fc12fb" alt=""><figcaption></figcaption></figure>

Use the following public URL to link the Reference dataset: <https://raw.githubusercontent.com/NannyML/sample_datasets/main/amazon_reviews/amazon_reviews_reference.csv>

<figure><img src="https://2363051145-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWcs3xQupCdtvmF6k2Sun%2Fuploads%2FwdG79ERjwWJH2P1Out9S%2FScreenshot%202023-11-21%20at%2009.04.21.png?alt=media&amp;token=4a23471f-4d71-4fd1-a169-2f6587407679" alt=""><figcaption></figcaption></figure>

### Step 4: Define the reference dataset schema

1. Select the column **timestamp** as the Timestamp column
2. Select the column **predicted\_sentiment** as the Prediction column
3. Select the **real\_sentiment** as the Target column
4. Flag the columns **negative\_sentiment\_pred\_proba, neutral\_sentiment\_pred\_proba, positive\_sentiment\_pred\_proba** as Prediction Scores.

<figure><img src="https://2363051145-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWcs3xQupCdtvmF6k2Sun%2Fuploads%2F2bPweBycnrCoDmBi5yvx%2FScreenshot%202023-11-21%20at%2008.41.51.png?alt=media&amp;token=4f67b9e2-6f43-4d69-8371-e74d5b7b147f" alt=""><figcaption></figcaption></figure>

### Step 5: Configure the Analysis set

Select "Upload via public link".

<figure><img src="https://2363051145-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWcs3xQupCdtvmF6k2Sun%2Fuploads%2FeHQ7hmdjruxZo5Rs96nH%2FScreenshot%202023-11-21%20at%2008.53.37.png?alt=media&amp;token=558c35dc-5b17-414e-bfb0-c3746bae43db" alt=""><figcaption></figcaption></figure>

Use the following public URL to link the Analysis dataset: <https://raw.githubusercontent.com/NannyML/sample_datasets/main/amazon_reviews/amazon_reviews_analysis_targets.csv>

<figure><img src="https://2363051145-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWcs3xQupCdtvmF6k2Sun%2Fuploads%2F6HRmnnWHOEVLjs59igb2%2FScreenshot%202023-11-21%20at%2008.53.48.png?alt=media&amp;token=9db7a406-864f-4f60-955e-029868de3500" alt=""><figcaption></figcaption></figure>

### Step 6: Start monitoring

<figure><img src="https://2363051145-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWcs3xQupCdtvmF6k2Sun%2Fuploads%2FyGbkC9mjtvzzU7ESnorC%2FScreenshot%202023-11-21%20at%2008.54.01.png?alt=media&amp;token=f87cdf76-5816-4e14-91a7-8092b7be4570" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2363051145-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWcs3xQupCdtvmF6k2Sun%2Fuploads%2FiDUwTExCMicnm9pHAF8s%2FScreenshot%202023-11-21%20at%2009.06.45.png?alt=media&amp;token=bf8b81be-0181-44b3-bec2-158b111acc2d" alt=""><figcaption></figcaption></figure>
