Lesson 1 of 2 Text Analysis Applications in Foundry

Analyzing Text with Azure Language in Foundry Tools

This lesson explains how Azure Language provides prebuilt natural language processing features through the Foundry resource: the features, the request and response format, and how an application calls them.

Learning outcomes

After completing this lesson, you will be able to:

  • Identify the prebuilt features of Azure Language.
  • Describe the structure of an analyze-text request and response.
  • Describe the client library and authentication options.
  • Choose the analysis kinds for a requirement.

Features

Azure Language in Foundry Tools offers prebuilt features that need no training: language detection, key phrase extraction, named entity recognition, PII detection and redaction, entity linking, sentiment analysis with opinion mining, summarization of documents and conversations, and text analytics for health. Customizable features, such as custom text classification and custom named entity recognition, are trained with labelled examples. In the Foundry portal, the Language playground lets you try each feature on sample or pasted text.

Sort into groups

Prebuilt or custom?

Exam skills 2.2.1

Decide whether each task uses a prebuilt Azure Language feature or a customizable one trained with labelled examples.

Log in to try this activity Interactive activities are free with an account.

Requests and responses

Most features use one analyze-text operation on the Foundry resource's endpoint. The request names the kind of analysis and contains analysisInput with a list of documents, each with an id, language and text, so one request can analyze many texts. The response lists results by document ID: a sentiment label with confidence scores and per-sentence results, a list of key phrases, or entities with category, text, offset, length and confidence score. Long-running features such as summarization use an asynchronous job that the client polls.

body = {
    "kind": "SentimentAnalysis",
    "parameters": {"opinionMining": True},
    "analysisInput": {"documents": [
        {"id": "1", "language": "en", "text": "The tent was easy to pitch but the zip broke."},
    ]},
}
r = requests.post(f"{endpoint}/language/:analyze-text?api-version=2024-11-01", json=body, headers=auth_header)
doc = r.json()["results"]["documents"][0]
print(doc["sentiment"], doc["confidenceScores"])
True or false

Inside an analyze-text request

Exam skills 2.2.1

Check four statements about Azure Language requests and responses.

Log in to try this activity Interactive activities are free with an account.

Client libraries and authentication

Python applications can call the REST API directly or use the azure-ai-textanalytics client library, whose TextAnalyticsClient has methods such as analyze_sentiment(), extract_key_phrases(), recognize_entities() and recognize_pii_entities(). Either way, the application authenticates with a Microsoft Entra ID token from DefaultAzureCredential (or a key), and the identity needs a role that allows calling Foundry Tools on the resource.

Match the pairs

TextAnalyticsClient methods

Exam skills 2.2.1

Match each method of the azure-ai-textanalytics client with what it returns.

Log in to try this activity Interactive activities are free with an account.
Worked example

Choosing the kind

A developer must (1) tag support emails with their main topics, (2) remove customers' phone numbers before storage and (3) flag emails written in languages other than English. Which analysis kinds should the application request?

(1) is KeyPhraseExtraction, (2) is PiiEntityRecognition, which returns redacted text, and (3) is LanguageDetection. EntityRecognition would find named entities rather than topics and would not redact the phone numbers.

Check yourself

How does an Azure Language request choose which analysis to run?

Show answer

With the kind value in the analyze-text operation, such as sentiment analysis or PII detection.

Exam Tips

Remember for the exam

  • One analyze-text operation; the kind selects the feature; documents are sent as a list.
  • Results include labels, confidence scores, categories and offsets per document.
  • Summarization runs as an asynchronous job.