Skip to content

Commit 2f05cd1

Browse files
Merge pull request #275615 from v-thepet/rai2
243805 - Generate Responsible AI text insights
2 parents 8d5331a + f099c20 commit 2f05cd1

File tree

1 file changed

+69
-64
lines changed

1 file changed

+69
-64
lines changed
Lines changed: 69 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,140 +1,145 @@
11
---
2-
title: Generate Responsible AI text insights with YAML and Python in Azure Machine Learning
2+
title: Generate responsible AI text insights with YAML and Python
33
titleSuffix: Azure Machine Learning
4-
description: Learn how to generate Responsible AI text insights with Python and YAML in Azure Machine Learning.
4+
description: Learn how the Azure Machine Learning Responsible AI (RAI) text insights component generates a RAI text dashboard by using a pipeline in Python or YAML.
55
services: machine-learning
66
ms.service: machine-learning
77
ms.subservice: rai
88
ms.topic: how-to
99
ms.reviewer: lagayhar
1010
ms.author: wenxwei
1111
author: wenxwei
12-
ms.date: 5/10/2023
12+
ms.date: 5/15/2024
1313
ms.custom: responsible-ml, build-2023, devx-track-python
1414
---
1515

16-
# Generate Responsible AI text insights with YAML and Python (preview)
16+
# Generate responsible AI text insights with YAML and Python (preview)
1717

1818
[!INCLUDE [dev v2](includes/machine-learning-dev-v2.md)]
1919

20-
Understanding and assessing NLP models can be different from tabular data. The Responsible AI dashboard now supports text data by expanding the debugging capabilities and visualizations to be able to digest and visualize text data. The Responsible AI text dashboard provides several mature Responsible AI tools in the areas of error analysis, model interpretability, unfairness assessment and mitigation for a holistic assessment and debugging of NLP models and making informed business decisions. You can generate a Responsible AI text dashboard via a pipeline job by using Responsible AI components.
20+
The [Responsible AI (RAI) dashboard](concept-responsible-ai-dashboard.md) brings together several RAI tools in a single interface to help inform data-driven decisions about your models. Understanding natural language processing (NLP) models can be different from assessing tabular data. RAI dashboard model debugging and visualizations now support text data.
2121

22+
The Responsible AI text dashboard provides several mature RAI tools in the areas of error analysis, model interpretability, unfairness assessment, and mitigation. The dashboard supports holistic assessment and debugging of NLP models to aid in making informed business decisions.
2223

23-
Supported scenarios:
24-
25-
| Name | Description | Parameter name |
26-
|---------------------------------|-----------------------------------------------------|---------------------------------------------|
27-
| Multi-label Text Classification | Predict multiple classes for the given text content | `task_type="multilabel_text_classification` |
24+
This article describes the Responsible AI text insights component and how to use it in a pipeline job to generate a Responsible AI text dashboard. The following sections provide specifications and requirements for the text insights component and example code snippets in YAML and Python.
2825

2926
> [!IMPORTANT]
30-
> Responsible AI Text Insights is currently in public preview. This preview is provided without a service-level agreement, and are not recommended for production workloads. Certain features might not be supported or might have constrained capabilities.
31-
> For more information, see [Supplemental Terms of Use for Microsoft Azure Previews](https://azure.microsoft.com/support/legal/preview-supplemental-terms/).
27+
> The Responsible AI text insights component is currently in public preview. This preview is provided without a service-level agreement, and isn't recommended for production workloads. Certain features might not be supported or might have constrained capabilities. For more information, see [Supplemental Terms of Use for Microsoft Azure Previews](https://azure.microsoft.com/support/legal/preview-supplemental-terms/).
28+
29+
## Responsible AI text insights component
30+
31+
The Azure Machine Learning Responsible AI text insights component assembles generated insights into a single Responsible AI text dashboard, and is the only core component used for constructing the RAI text dashboard. This construction differs from the [Responsible AI pipeline for tabular data](how-to-responsible-ai-insights-sdk-cli.md#responsible-ai-components), which uses several components.
3232

33-
## Responsible AI component
33+
### Requirements and limitations
3434

35-
The core component for constructing the Responsible AI text dashboard in Azure Machine Learning is only the Responsible AI text insights component, which is different from how you construct the Responsible AI pipeline for tabular data.
35+
- All models must be registered in Azure Machine Learning.
36+
- MLflow models with a sklearn (scikit-learn) or PyTorch flavor and HuggingFace models are supported.
37+
- The training and test dataset inputs must be in `mltable` format.
38+
- The test dataset is restricted to 5,000 rows of the visualization UI, for performance reasons.
3639

37-
In the following sections are specifications of the Responsible AI text insights component and examples of code snippets in YAML and Python.
40+
### Parameters
41+
42+
The Responsible AI text insights component supports the following scenarios through the `task_type` parameter:
43+
44+
| Name | Description | Parameter value |
45+
|---------------------------------|-----------------------------------------------------|---------------------------------------------|
46+
| Text Classification | Predicts classes for the given text content | `task_type="text_classification"` |
47+
| Multi-label Text Classification | Predicts multiple classes for the given text content | `task_type="multilabel_text_classification"` |
48+
| Text Question Answering | Evaluates a question answering model on the text dataset | `task_type="question_answering"` |
3849

39-
### Limitation
50+
The component accepts the following optional parameters:
4051

41-
- All models must be registered in Azure Machine Learning.
42-
- Models in MLflow format and with a sklearn or PyTorch flavor are supported.
43-
- HuggingFace models are supported.
44-
- The dataset input must be in mltable format.
45-
- For performance reason, the test dataset is restricted to 5,000 rows of the visualization UI.
52+
| Parameter name | Description | Type |
53+
|----------------|-------------|------|
54+
| `title` | Brief description of the dashboard. | String |
55+
| `classes` | The full list of class labels in the training dataset. | List of strings |
56+
| `maximum_rows_for_test_dataset` | The maximum number of rows allowed in the test dataset. Defaults to 5,000. | Integer |
57+
| `target_column_name` | The name of the column in the input datasets that the model is trying to predict. | String |
58+
| `enable_explanation` | Enable generating an explanation for the model. | Boolean |
59+
| `enable_error_analysis` | Enable generating an error analysis for the model. | Boolean|
60+
| `use_model_dependency` | The Responsible AI environment doesn't include the model dependencies by default. When set to `True`, installs the model dependency packages. | Boolean |
61+
| `use_conda` | Installs the model dependency packages using `conda` if set to `True`, otherwise uses `pip`. | Boolean |
4662

47-
## Responsible AI text insights
63+
### Ports
4864

49-
This component has three major input ports:
65+
The Responsible AI text insights component has three major input ports:
5066

5167
- The machine learning model
5268
- The training dataset
5369
- The test dataset
5470

55-
The easiest way to supply the model is to register the input model and reference the same model in the model input port of Responsible AI text insights component.
56-
57-
The two datasets should be in mltable format. The training and test datasets provided don't have to be the same datasets that are used in training the model, but they can be the same.
71+
The training and test datasets don't have to be, but can be the same dataset. The easiest way to supply the model input is to register the model and reference the same model in the `model_input` port of the Responsible AI text insights component.
5872

59-
The Responsible AI text insights component also accepts the following parameters:
73+
There are two output ports:
6074

61-
| Parameter name | Description | Type |
62-
|----------------|-------------|------|
63-
| `title` | Brief description of the dashboard. | String |
64-
| `target_column_name` | The name of the column in the input datasets, which the model is trying to predict. | String |
65-
| `maximum_rows_for_test_dataset` | The maximum number of rows allowed in the test dataset, for performance reasons. | Integer, defaults to 5,000 |
66-
| `classes` | The full list of class labels in the training dataset. | Optional list of strings |
67-
| `enable_explanation` | Enable to generate an explanation for the model. | Boolean |
68-
| `enable_error_analysis` | Enable to generate an error analysis for the model. | Boolean|
69-
| `use_model_dependency` | The Responsible AI environment doesn't include the model dependency, install the model dependency packages when set to True. | Boolean |
70-
| `use_conda` | Install the model dependency packages using conda if True, otherwise using pip. | Boolean |
75+
- The `dashboard` port contains the completed `RAITextInsights` object.
76+
- The `ux_json` port contains the data required to display a minimal dashboard.
7177

72-
This component assembles the generated insights into a single Responsible AI text dashboard. There are two output ports:
78+
### Pipeline job
7379

74-
- The dashboard port contains the completed RAITextInsights object.
75-
- The ux_json port contains the data required to display a minimal dashboard.
80+
To create the Responsible AI text dashboard, you can define the RAI components in a pipeline and submit the pipeline job.
7681

7782
# [YAML](#tab/yaml)
7883

84+
You can specify the pipeline in a YAML file, as in the following example, and submit it by using the Azure CLI `az ml job create` command.
85+
7986
```yml
8087
analyse_model:
8188
type: command
82-
component: azureml://registries/AzureML-RAI-preview/components/rai_text_insights/versions/2
89+
component: azureml://registries/AzureML/components/rai_text_insights/versions/2
8390
inputs:
8491
title: From YAML
8592
task_type: text_classification
8693
model_input:
8794
type: mlflow_model
88-
path: azureml:<registered_model_name>:<registered model version>
89-
model_info: ${{parent.inputs.model_info}}
90-
train_dataset:
91-
type: mltable
92-
path: ${{parent.inputs.my_training_data}}
93-
test_dataset:
94-
type: mltable
95-
path: ${{parent.inputs.my_test_data}}
96-
target_column_name: ${{parent.inputs.target_column_name}}
95+
path: {azureml_model_id}
96+
model_info: ${{{{parent.inputs.model_info}}}}
97+
train_dataset: ${{{{parent.inputs.my_training_data}}}}
98+
test_dataset: ${{{{parent.inputs.my_test_data}}}}
99+
target_column_name: {target_column_name}
97100
maximum_rows_for_test_dataset: 5000
98101
classes: '[]'
99102
enable_explanation: True
100103
enable_error_analysis: True
101-
102104
```
103105
104106
# [Python SDK](#tab/python)
105107
108+
The Responsible AI text dashboard uses the [Responsible AI Text SDK for Python](https://github.com/microsoft/responsible-ai-toolbox/tree/main/responsibleai_text).
109+
110+
In your Python script, load the RAI text insights component:
111+
106112
```python
107-
#First load the RAI component:
108113
rai_text_insights_component = ml_client_registry.components.get(
109114
name="rai_text_insights", version=version_string
110-
111115
)
116+
```
117+
118+
Inside the pipeline, initiate the RAI text insights as in the following example:
112119

113-
#Then inside the pipeline:
114-
# Initiate the RAI Text Insights
120+
```python
115121
rai_text_job = rai_text_insights_component(
116122
title="From Python",
117123
task_type="text_classification",
118124
model_info=expected_model_id,
119-
model_input=Input(type=AssetTypes.MLFLOW_MODEL, path= "<azureml:model_name:model_id>"),
125+
model_input=Input(type=AssetTypes.MLFLOW_MODEL, path= azureml_model_id),
120126
train_dataset=train_data,
121127
test_dataset=test_data,
122128
target_column_name=target_column_name,
123129
classes=classes,
124130
)
131+
```
132+
133+
And assemble the output:
125134

126-
#Assemble the output
135+
```python
127136
rai_text_job.outputs.dashboard.mode = "upload"
128137
rai_text_job.outputs.ux_json.mode = "upload"
129138
```
130139
---
131140

132-
## Understand the Responsible AI text dashboard
133-
134-
To learn more about how to use the Responsible AI text dashboard, see [Responsible AI text dashboard Azure Machine Learning studio](how-to-responsible-ai-text-dashboard.md).
135-
136-
## Next steps
141+
## Related content
137142

143+
- Learn [how to use the Responsible AI text dashboard](how-to-responsible-ai-text-dashboard.md).
138144
- Learn more about the [concepts and techniques behind the Responsible AI dashboard](concept-responsible-ai-dashboard.md).
139-
- View sample [YAML and Python notebooks](https://github.com/Azure/azureml-examples/tree/main/sdk/python/responsible-ai) to generate a Responsible AI dashboard with YAML or Python.
140-
- Learn about how the Responsible AI text dashboard was used by ERM for a [business use case](https://aka.ms/erm-customer-story).
145+
- View sample [YAML and Python notebooks](https://github.com/Azure/azureml-examples/tree/main/sdk/python/responsible-ai) to generate a Responsible AI dashboard.

0 commit comments

Comments
 (0)