From ee9ff1b7cd1ca76ba14d8217ee910d1579460c6f Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Mon, 13 Mar 2023 10:43:48 -0700 Subject: [PATCH] remove dynamic classification tests and samples (#29311) --- .../azure-ai-textanalytics/README.md | 5 -- .../textanalytics/_text_analytics_client.py | 9 --- .../aio/_text_analytics_client_async.py | 9 --- .../azure-ai-textanalytics/samples/README.md | 3 - .../sample_dynamic_classification_async.py | 69 ------------------- .../samples/sample_dynamic_classification.py | 65 ----------------- .../tests/test_dynamic_classification.py | 63 ----------------- .../test_dynamic_classification_async.py | 65 ----------------- 8 files changed, 288 deletions(-) delete mode 100644 sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_dynamic_classification_async.py delete mode 100644 sdk/textanalytics/azure-ai-textanalytics/samples/sample_dynamic_classification.py delete mode 100644 sdk/textanalytics/azure-ai-textanalytics/tests/test_dynamic_classification.py delete mode 100644 sdk/textanalytics/azure-ai-textanalytics/tests/test_dynamic_classification_async.py diff --git a/sdk/textanalytics/azure-ai-textanalytics/README.md b/sdk/textanalytics/azure-ai-textanalytics/README.md index 18287cdad55a..be40186f18ee 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/README.md +++ b/sdk/textanalytics/azure-ai-textanalytics/README.md @@ -14,7 +14,6 @@ The Azure Cognitive Service for Language is a cloud-based service that provides - Custom Text Classification - Extractive Text Summarization - Abstractive Text Summarization -- Dynamic Classification [Source code][source_code] | [Package (PyPI)][ta_pypi] | [API reference documentation][ta_ref_docs] | [Product documentation][language_product_documentation] | [Samples][ta_samples] @@ -259,7 +258,6 @@ The following section provides several code snippets covering some of the most c - [Custom Multi Label Classification][multi_label_classify_sample] - [Extractive Summarization][extract_summary_sample] - [Abstractive Summarization][abstractive_summary_sample] -- [Dynamic Classification][dynamic_classification_sample] ### Analyze Sentiment @@ -817,7 +815,6 @@ Common scenarios - Custom Multi Label Classification: [sample_multi_label_classify.py][multi_label_classify_sample] ([async_version][multi_label_classify_sample_async]) - Extractive text summarization: [sample_extract_summary.py][extract_summary_sample] ([async version][extract_summary_sample_async]) - Abstractive text summarization: [sample_abstractive_summary.py][abstractive_summary_sample] ([async version][abstractive_summary_sample_async]) -- Dynamic Classification: [sample_dynamic_classification.py][dynamic_classification_sample] ([async_version][dynamic_classification_sample_async]) Advanced scenarios @@ -926,8 +923,6 @@ This project has adopted the [Microsoft Open Source Code of Conduct][code_of_con [extract_summary_sample_async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_extract_summary_async.py [abstractive_summary_sample]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/textanalytics/azure-ai-textanalytics/samples/sample_abstractive_summary.py [abstractive_summary_sample_async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_abstractive_summary_async.py -[dynamic_classification_sample]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/textanalytics/azure-ai-textanalytics/samples/sample_dynamic_classification.py -[dynamic_classification_sample_async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_dynamic_classification_async.py [recognize_entity_resolutions_sample]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/textanalytics/azure-ai-textanalytics/samples/sample_recognize_entity_resolutions.py [recognize_entity_resolutions_sample_async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_recognize_entity_resolutions_async.py [cla]: https://cla.microsoft.com diff --git a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_text_analytics_client.py b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_text_analytics_client.py index e458fcb08dcd..461fddbef9eb 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_text_analytics_client.py +++ b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_text_analytics_client.py @@ -1788,15 +1788,6 @@ def dynamic_classification( .. versionadded:: 2022-10-01-preview The *dynamic_classification* client method. - - .. admonition:: Example: - - .. literalinclude:: ../samples/sample_dynamic_classification.py - :start-after: [START dynamic_classification] - :end-before: [END dynamic_classification] - :language: python - :dedent: 4 - :caption: Perform dynamic classification on a batch of documents. """ language_arg = language if language is not None else self._default_language diff --git a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/_text_analytics_client_async.py b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/_text_analytics_client_async.py index 57ea07e93ea8..50deefdfcbb0 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/_text_analytics_client_async.py +++ b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/_text_analytics_client_async.py @@ -1784,15 +1784,6 @@ async def dynamic_classification( .. versionadded:: 2022-10-01-preview The *dynamic_classification* client method. - - .. admonition:: Example: - - .. literalinclude:: ../samples/async_samples/sample_dynamic_classification_async.py - :start-after: [START dynamic_classification_async] - :end-before: [END dynamic_classification_async] - :language: python - :dedent: 4 - :caption: Perform dynamic classification on a batch of documents. """ language_arg = language if language is not None else self._default_language diff --git a/sdk/textanalytics/azure-ai-textanalytics/samples/README.md b/sdk/textanalytics/azure-ai-textanalytics/samples/README.md index 65b7e604010b..339b66f28d16 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/samples/README.md +++ b/sdk/textanalytics/azure-ai-textanalytics/samples/README.md @@ -36,7 +36,6 @@ These sample programs show common scenarios for the Text Analytics client's offe |[sample_analyze_healthcare_action.py][sample_analyze_healthcare_action] and [sample_analyze_healthcare_action_async.py][sample_analyze_healthcare_action_async]|Run a healthcare and PII analysis together| |[sample_extract_summary.py][extract_summary_sample] and [sample_extract_summary_async.py][extract_summary_sample_async]|As part of the analyze API, run extractive text summarization on documents| |[sample_abstractive_summary.py][abstractive_summary_sample] and [sample_abstractive_summary_async.py][abstractive_summary_sample_async]|As part of the analyze API, run abstractive text summarization on documents| -|[sample_dynamic_classification.py][dynamic_classification_sample] and [sample_dynamic_classification_async.py][dynamic_classification_sample_async]|Dynamically classify documents without needing to train a model.| ## Prerequisites * Python 3.7 or later is required to use this package @@ -121,8 +120,6 @@ what you can do with the Azure Text Analytics client library. [extract_summary_sample_async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_extract_summary_async.py [abstractive_summary_sample]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/textanalytics/azure-ai-textanalytics/samples/sample_abstractive_summary.py [abstractive_summary_sample_async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_abstractive_summary_async.py -[dynamic_classification_sample]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/textanalytics/azure-ai-textanalytics/samples/sample_dynamic_classification.py -[dynamic_classification_sample_async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_dynamic_classification_async.py [recognize_entity_resolutions_sample]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/textanalytics/azure-ai-textanalytics/samples/sample_recognize_entity_resolutions.py [recognize_entity_resolutions_sample_async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_recognize_entity_resolutions_async.py [pip]: https://pypi.org/project/pip/ diff --git a/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_dynamic_classification_async.py b/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_dynamic_classification_async.py deleted file mode 100644 index 87f7fa5a91f0..000000000000 --- a/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_dynamic_classification_async.py +++ /dev/null @@ -1,69 +0,0 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- - -""" -FILE: sample_dynamic_classification_async.py - -DESCRIPTION: - This sample demonstrates how to dynamically classify documents into one or multiple categories. - No model training is required to use dynamic classification. - - The dynamic classification feature is part of a gated preview. Request access here: - https://aka.ms/applyforgatedlanguagefeature - -USAGE: - python sample_dynamic_classification_async.py - - Set the environment variables with your own values before running the sample: - 1) AZURE_LANGUAGE_ENDPOINT - the endpoint to your Language resource. - 2) AZURE_LANGUAGE_KEY - your Language subscription key -""" - -import asyncio - - -async def sample_dynamic_classification_async() -> None: - # [START dynamic_classification_async] - import os - from azure.core.credentials import AzureKeyCredential - from azure.ai.textanalytics.aio import TextAnalyticsClient - - endpoint = os.environ["AZURE_LANGUAGE_ENDPOINT"] - key = os.environ["AZURE_LANGUAGE_KEY"] - - text_analytics_client = TextAnalyticsClient( - endpoint=endpoint, - credential=AzureKeyCredential(key), - ) - documents = [ - "The WHO is issuing a warning about Monkey Pox.", - "Mo Salah plays in Liverpool FC in England.", - ] - - async with text_analytics_client: - results = await text_analytics_client.dynamic_classification( - documents, - categories=["Health", "Politics", "Music", "Sports"], - classification_type="Multi" - ) - - for doc, classification_result in zip(documents, results): - if classification_result.kind == "DynamicClassification": - classifications = classification_result.classifications - print(f"\n'{doc}' classifications:\n") - for classification in classifications: - print("Category '{}' with confidence score {}.".format( - classification.category, classification.confidence_score - )) - elif classification_result.is_error is True: - print("Document '{}' has an error with code '{}' and message '{}'".format( - doc, classification_result.error.code, classification_result.error.message - )) - # [END dynamic_classification_async] - - -if __name__ == "__main__": - asyncio.run(sample_dynamic_classification_async()) diff --git a/sdk/textanalytics/azure-ai-textanalytics/samples/sample_dynamic_classification.py b/sdk/textanalytics/azure-ai-textanalytics/samples/sample_dynamic_classification.py deleted file mode 100644 index 427b32fdaf7a..000000000000 --- a/sdk/textanalytics/azure-ai-textanalytics/samples/sample_dynamic_classification.py +++ /dev/null @@ -1,65 +0,0 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- - -""" -FILE: sample_dynamic_classification.py - -DESCRIPTION: - This sample demonstrates how to dynamically classify documents into one or multiple categories. - No model training is required to use dynamic classification. - - The dynamic classification feature is part of a gated preview. Request access here: - https://aka.ms/applyforgatedlanguagefeature - -USAGE: - python sample_dynamic_classification.py - - Set the environment variables with your own values before running the sample: - 1) AZURE_LANGUAGE_ENDPOINT - the endpoint to your Language resource. - 2) AZURE_LANGUAGE_KEY - your Language subscription key -""" - - -def sample_dynamic_classification() -> None: - # [START dynamic_classification] - import os - from azure.core.credentials import AzureKeyCredential - from azure.ai.textanalytics import TextAnalyticsClient - - endpoint = os.environ["AZURE_LANGUAGE_ENDPOINT"] - key = os.environ["AZURE_LANGUAGE_KEY"] - - text_analytics_client = TextAnalyticsClient( - endpoint=endpoint, - credential=AzureKeyCredential(key), - ) - documents = [ - "The WHO is issuing a warning about Monkey Pox.", - "Mo Salah plays in Liverpool FC in England.", - ] - result = text_analytics_client.dynamic_classification( - documents, - categories=["Health", "Politics", "Music", "Sports"], - classification_type="Multi" - ) - - for doc, classification_result in zip(documents, result): - if classification_result.kind == "DynamicClassification": - classifications = classification_result.classifications - print(f"\n'{doc}' classifications:\n") - for classification in classifications: - print("Category '{}' with confidence score {}.".format( - classification.category, classification.confidence_score - )) - elif classification_result.is_error is True: - print("Document '{}' has an error with code '{}' and message '{}'".format( - doc, classification_result.error.code, classification_result.error.message - )) - # [END dynamic_classification] - - -if __name__ == "__main__": - sample_dynamic_classification() diff --git a/sdk/textanalytics/azure-ai-textanalytics/tests/test_dynamic_classification.py b/sdk/textanalytics/azure-ai-textanalytics/tests/test_dynamic_classification.py deleted file mode 100644 index 7393dfc93108..000000000000 --- a/sdk/textanalytics/azure-ai-textanalytics/tests/test_dynamic_classification.py +++ /dev/null @@ -1,63 +0,0 @@ -# ------------------------------------ -# Copyright (c) Microsoft Corporation. -# Licensed under the MIT License. -# ------------------------------------ - -import pytest -import platform -import functools -from testcase import TextAnalyticsTest, TextAnalyticsPreparer, is_public_cloud -from testcase import TextAnalyticsClientPreparer as _TextAnalyticsClientPreparer -from devtools_testutils import recorded_by_proxy -from azure.ai.textanalytics import ( - DynamicClassificationResult, - TextAnalyticsClient, - ClassificationType, -) - -# pre-apply the client_cls positional argument so it needn't be explicitly passed below -TextAnalyticsClientPreparer = functools.partial(_TextAnalyticsClientPreparer, TextAnalyticsClient) - - -class TestDynamicClassification(TextAnalyticsTest): - - @pytest.mark.skipif(not is_public_cloud(), reason='Usgov and China Cloud are not supported') - @TextAnalyticsPreparer() - @TextAnalyticsClientPreparer() - @recorded_by_proxy - def test_dynamic_classification(self, client): - documents = [ - "The WHO is issuing a warning about Monkey Pox.", - "Mo Salah plays in Liverpool FC in England.", - ] - result = client.dynamic_classification( - documents, - categories=["Health", "Politics", "Music", "Sports"], - show_stats=True - ) - for res in result: - assert res.id - assert res.statistics - for classification in res.classifications: - assert classification.category - assert classification.confidence_score is not None - - @pytest.mark.skipif(not is_public_cloud(), reason='Usgov and China Cloud are not supported') - @TextAnalyticsPreparer() - @TextAnalyticsClientPreparer() - @recorded_by_proxy - def test_dynamic_classification_single(self, client): - documents = [ - "The WHO is issuing a warning about Monkey Pox.", - "Mo Salah plays in Liverpool FC in England.", - ] - result = client.dynamic_classification( - documents, - categories=["Health", "Politics", "Music", "Sports"], - classification_type="single" - ) - for res in result: - assert res.id - assert len(res.classifications) == 1 - assert res.classifications[0].category - assert res.classifications[0].confidence_score is not None diff --git a/sdk/textanalytics/azure-ai-textanalytics/tests/test_dynamic_classification_async.py b/sdk/textanalytics/azure-ai-textanalytics/tests/test_dynamic_classification_async.py deleted file mode 100644 index ae7d27eddfc8..000000000000 --- a/sdk/textanalytics/azure-ai-textanalytics/tests/test_dynamic_classification_async.py +++ /dev/null @@ -1,65 +0,0 @@ -# ------------------------------------ -# Copyright (c) Microsoft Corporation. -# Licensed under the MIT License. -# ------------------------------------ - -import pytest -import platform -import functools -from testcase import TextAnalyticsTest, TextAnalyticsPreparer, is_public_cloud -from testcase import TextAnalyticsClientPreparer as _TextAnalyticsClientPreparer -from devtools_testutils.aio import recorded_by_proxy_async -from azure.ai.textanalytics.aio import TextAnalyticsClient -from azure.ai.textanalytics import ( - DynamicClassificationResult, - ClassificationType, -) - -# pre-apply the client_cls positional argument so it needn't be explicitly passed below -TextAnalyticsClientPreparer = functools.partial(_TextAnalyticsClientPreparer, TextAnalyticsClient) - - -class TestDynamicClassification(TextAnalyticsTest): - - @pytest.mark.skipif(not is_public_cloud(), reason='Usgov and China Cloud are not supported') - @TextAnalyticsPreparer() - @TextAnalyticsClientPreparer() - @recorded_by_proxy_async - async def test_dynamic_classification(self, client): - documents = [ - "The WHO is issuing a warning about Monkey Pox.", - "Mo Salah plays in Liverpool FC in England.", - ] - async with client: - result = await client.dynamic_classification( - documents, - categories=["Health", "Politics", "Music", "Sports"], - show_stats=True - ) - for res in result: - assert res.id - assert res.statistics - for classification in res.classifications: - assert classification.category - assert classification.confidence_score is not None - - @pytest.mark.skipif(not is_public_cloud(), reason='Usgov and China Cloud are not supported') - @TextAnalyticsPreparer() - @TextAnalyticsClientPreparer() - @recorded_by_proxy_async - async def test_dynamic_classification_single(self, client): - documents = [ - "The WHO is issuing a warning about Monkey Pox.", - "Mo Salah plays in Liverpool FC in England.", - ] - async with client: - result = await client.dynamic_classification( - documents, - categories=["Health", "Politics", "Music", "Sports"], - classification_type="single" - ) - for res in result: - assert res.id - assert len(res.classifications) == 1 - assert res.classifications[0].category - assert res.classifications[0].confidence_score is not None