|
1 | 1 | ---
|
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 |
3 | 3 | 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. |
5 | 5 | services: machine-learning
|
6 | 6 | ms.service: machine-learning
|
7 | 7 | ms.subservice: rai
|
8 | 8 | ms.topic: how-to
|
9 | 9 | ms.reviewer: lagayhar
|
10 | 10 | ms.author: wenxwei
|
11 | 11 | author: wenxwei
|
12 |
| -ms.date: 5/10/2023 |
| 12 | +ms.date: 5/15/2024 |
13 | 13 | ms.custom: responsible-ml, build-2023, devx-track-python
|
14 | 14 | ---
|
15 | 15 |
|
16 |
| -# Generate Responsible AI text insights with YAML and Python (preview) |
| 16 | +# Generate responsible AI text insights with YAML and Python (preview) |
17 | 17 |
|
18 | 18 | [!INCLUDE [dev v2](includes/machine-learning-dev-v2.md)]
|
19 | 19 |
|
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. |
21 | 21 |
|
| 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. |
22 | 23 |
|
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. |
28 | 25 |
|
29 | 26 | > [!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. |
32 | 32 |
|
33 |
| -## Responsible AI component |
| 33 | +### Requirements and limitations |
34 | 34 |
|
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. |
36 | 39 |
|
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"` | |
38 | 49 |
|
39 |
| -### Limitation |
| 50 | +The component accepts the following optional parameters: |
40 | 51 |
|
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 | |
46 | 62 |
|
47 |
| -## Responsible AI text insights |
| 63 | +### Ports |
48 | 64 |
|
49 |
| -This component has three major input ports: |
| 65 | +The Responsible AI text insights component has three major input ports: |
50 | 66 |
|
51 | 67 | - The machine learning model
|
52 | 68 | - The training dataset
|
53 | 69 | - The test dataset
|
54 | 70 |
|
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. |
58 | 72 |
|
59 |
| -The Responsible AI text insights component also accepts the following parameters: |
| 73 | +There are two output ports: |
60 | 74 |
|
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. |
71 | 77 |
|
72 |
| -This component assembles the generated insights into a single Responsible AI text dashboard. There are two output ports: |
| 78 | +### Pipeline job |
73 | 79 |
|
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. |
76 | 81 |
|
77 | 82 | # [YAML](#tab/yaml)
|
78 | 83 |
|
| 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 | + |
79 | 86 | ```yml
|
80 | 87 | analyse_model:
|
81 | 88 | 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 |
83 | 90 | inputs:
|
84 | 91 | title: From YAML
|
85 | 92 | task_type: text_classification
|
86 | 93 | model_input:
|
87 | 94 | 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} |
97 | 100 | maximum_rows_for_test_dataset: 5000
|
98 | 101 | classes: '[]'
|
99 | 102 | enable_explanation: True
|
100 | 103 | enable_error_analysis: True
|
101 |
| - |
102 | 104 | ```
|
103 | 105 |
|
104 | 106 | # [Python SDK](#tab/python)
|
105 | 107 |
|
| 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 | +
|
106 | 112 | ```python
|
107 |
| -#First load the RAI component: |
108 | 113 | rai_text_insights_component = ml_client_registry.components.get(
|
109 | 114 | name="rai_text_insights", version=version_string
|
110 |
| - |
111 | 115 | )
|
| 116 | +``` |
| 117 | + |
| 118 | +Inside the pipeline, initiate the RAI text insights as in the following example: |
112 | 119 |
|
113 |
| -#Then inside the pipeline: |
114 |
| - # Initiate the RAI Text Insights |
| 120 | +```python |
115 | 121 | rai_text_job = rai_text_insights_component(
|
116 | 122 | title="From Python",
|
117 | 123 | task_type="text_classification",
|
118 | 124 | 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), |
120 | 126 | train_dataset=train_data,
|
121 | 127 | test_dataset=test_data,
|
122 | 128 | target_column_name=target_column_name,
|
123 | 129 | classes=classes,
|
124 | 130 | )
|
| 131 | +``` |
| 132 | + |
| 133 | +And assemble the output: |
125 | 134 |
|
126 |
| - #Assemble the output |
| 135 | +```python |
127 | 136 | rai_text_job.outputs.dashboard.mode = "upload"
|
128 | 137 | rai_text_job.outputs.ux_json.mode = "upload"
|
129 | 138 | ```
|
130 | 139 | ---
|
131 | 140 |
|
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 |
137 | 142 |
|
| 143 | +- Learn [how to use the Responsible AI text dashboard](how-to-responsible-ai-text-dashboard.md). |
138 | 144 | - 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