Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

page_type languages products urlFragment
sample
python
azure
azure-cognitive-services
language-service
textanalytics-samples

Samples for Azure Text Analytics client library for Python

These code samples show common scenario operations with the Azure Text Analytics client library.

You can authenticate your client with a Language API key or through Azure Active Directory with a token credential from azure-identity:

These sample programs show common scenarios for the Text Analytics client's offerings.

File Name Description
sample_detect_language.py and sample_detect_language_async.py Detect language in documents
sample_recognize_entities.py and sample_recognize_entities_async.py Recognize named entities in documents
sample_recognize_linked_entities.py and sample_recognize_linked_entities_async.py Recognize linked entities in documents
sample_recognize_pii_entities.py and sample_recognize_pii_entities_async.py Recognize personally identifiable information in documents
sample_extract_key_phrases.py and sample_extract_key_phrases_async.py Extract key phrases from documents
sample_analyze_sentiment.py and sample_analyze_sentiment_async.py Analyze the sentiment of documents
sample_alternative_document_input.py and sample_alternative_document_input_async.py Pass documents to an endpoint using dicts
sample_analyze_healthcare_entities.py and sample_analyze_healthcare_entities_async.py Analyze healthcare entities
sample_analyze_actions.py and sample_analyze_actions_async.py Run multiple analyses together in a single request
sample_recognize_custom_entities.py and sample_recognize_custom_entities_async.py Use a custom model to recognize custom entities in documents
sample_single_label_classify.py and sample_single_label_classify_async.py Use a custom model to classify documents into a single category
sample_multi_label_classify.py and sample_multi_label_classify_async.py Use a custom model to classify documents into multiple categories
sample_model_version.py and sample_model_version_async.py Set the model version for pre-built Text Analytics models
sample_analyze_healthcare_action.py and sample_analyze_healthcare_action_async.py Run a healthcare and PII analysis together
sample_extract_summary.py and sample_extract_summary_async.py Run extractive text summarization on documents
sample_abstract_summary.py and sample_abstract_summary_async.py Run abstractive text summarization on documents

Prerequisites

Setup

  1. Install the Azure Text Analytics client library for Python with pip:
pip install azure-ai-textanalytics

For more information about how the versioning story of the SDK corresponds to the versioning story of the service's API, see here.

  • If authenticating with Azure Active Directory, make sure you have azure-identity installed:
    pip install azure-identity
  1. Clone the repo or download the sample file
  2. Open the sample file in Visual Studio Code or your IDE of choice.

Running the samples

  1. Open a terminal window and cd to the directory that the samples are saved in.
  2. Set the environment variables specified in the sample file you wish to run.
  3. Follow the usage described in the file, e.g. python sample_detect_language.py

Next steps

Check out the API reference documentation to learn more about what you can do with the Azure Text Analytics client library.

Advanced Sample File Name Description
sample_analyze_sentiment_with_opinion_mining.py and sample_analyze_sentiment_with_opinion_mining_async.py Analyze sentiment in documents with granular analysis into individual opinions present in a sentence. Only available with API version v3.1 and up.
sample_get_detailed_diagnostics_information.py and sample_get_detailed_diagnostics_information_async.py Get the request batch statistics, model version, and raw response in JSON format through a callback
sample_analyze_healthcare_entities_with_cancellation.py and sample_analyze_healthcare_entities_with_cancellation_async.py Cancel an analyze healthcare entities operation after it's started.