Skip to content
XUtilHub

AI-901 courseLesson 10 of 14 · 13 min

Text Analysis With Azure Language in Foundry: Sentiment, Entities, Key Phrases (AI-901)

XUtilHub Team ·

Exam skills covered

  • Build a lightweight application that includes text analysis

Text analysis turns unstructured text, such as reviews, emails, tickets and articles, into insight. For AI-901 you need to know the techniques and how to "build a lightweight application that includes text analysis" in Foundry.

There are two ways to do text analysis in Foundry:

  1. Azure Language in Foundry Tools (formerly Azure AI Language): purpose-built, pre-trained features with consistent, structured output and confidence scores.
  2. A generative model with a good prompt: flexible, handles unusual tasks, but output needs careful formatting and validation.

The exam can test both. Know when each fits.

Azure Language features

FeatureWhat it returns
Language detectionThe language of the text and a confidence score
Sentiment analysisPositive, negative, neutral or mixed, per document and per sentence
Opinion miningSentiment about specific aspects ("battery: positive")
Key phrase extractionThe main talking points
Named entity recognition (NER)People, locations, organizations, dates, quantities and more
Entity linkingEntities matched to a knowledge base, such as Wikipedia
PII detectionPersonal information like phone numbers and emails, plus a redacted version of the text
SummarizationExtractive (key sentences) or abstractive (newly written) summaries of documents and conversations
Custom featuresCustom text classification, custom NER, conversational language understanding, question answering

Build a text analysis app in Python

Install the client library:

pip install azure-ai-textanalytics

You need your Foundry (or Language) resource endpoint and a credential. A key is shown here for simplicity; in production use Entra ID or store the key in Azure Key Vault.

import os
from azure.ai.textanalytics import TextAnalyticsClient
from azure.core.credentials import AzureKeyCredential

client = TextAnalyticsClient(
    endpoint=os.environ["LANGUAGE_ENDPOINT"],
    credential=AzureKeyCredential(os.environ["LANGUAGE_KEY"]),
)

reviews = [
    "The hotel in Lahore was spotless and the staff were wonderful.",
    "Check-in took an hour and the Wi-Fi never worked. Call me on 0300-1234567.",
]

# Language
for doc in client.detect_language(reviews):
    print("Language:", doc.primary_language.name)

# Sentiment
for doc in client.analyze_sentiment(reviews):
    print("Sentiment:", doc.sentiment, doc.confidence_scores)

# Key phrases
for doc in client.extract_key_phrases(reviews):
    print("Key phrases:", doc.key_phrases)

# Entities
for doc in client.recognize_entities(reviews):
    for e in doc.entities:
        print("Entity:", e.text, "|", e.category, "|", round(e.confidence_score, 2))

# PII, with redacted text
for doc in client.recognize_pii_entities(reviews):
    print("Redacted:", doc.redacted_text)

Notice the pattern: create a client with endpoint + credential → call a method with a list of documents → loop over the results. Each result has an is_error flag you should check in real code.

Expected kinds of output:

  • Review 1: sentiment positive; key phrases such as hotel, staff; entity Lahore (Location).
  • Review 2: sentiment negative; key phrases such as check-in, Wi-Fi; PII detection finds the phone number and returns the text with it masked.

Summarization

Summaries run as long-running operations:

poller = client.begin_abstract_summary([long_article])
for result in poller.result():
    for summary in result.summaries:
        print(summary.text)

begin_extract_summary does extractive summarization the same way.

Doing it with a generative model instead

response = openai.responses.create(
    model="gpt-5-mini",
    instructions="Analyse customer reviews. Return JSON with: sentiment "
                 "(positive/negative/mixed), key_phrases (array) and summary (one sentence).",
    input=review_text,
)
Choose Azure Language when…Choose a generative model when…
You need consistent, structured output with confidence scoresThe task is unusual or needs reasoning
You process large volumes cheaplyYou want flexible output (explanations, rewrites)
You need PII redaction or entity linkingYou need several analyses in one call

Techniques behind the features

Fundamentals questions sometimes ask about classic NLP ideas:

  • Tokenization: splitting text into words or sub-words.
  • Stop-word removal: dropping common words such as "the" and "is".
  • Stemming / lemmatization: reducing words to a base form (running → run).
  • TF-IDF: scoring words that are common in one document but rare across all documents, a simple form of keyword extraction.
  • Embeddings: vectors that capture meaning, used by modern models for sentiment, similarity and search.

Key takeaways

  • Know each Language feature and its output: language, sentiment and opinions, key phrases, entities, PII, summaries.
  • SDK pattern: TextAnalyticsClient(endpoint, credential) → analyze_sentiment, extract_key_phrases, recognize_entities, recognize_pii_entities, detect_language.
  • Extractive summaries reuse sentences; abstractive summaries write new ones.
  • Use Language for consistent, scalable analysis; use a generative model for flexible or unusual tasks.

Next lesson: speech AI on Azure.

Check your understanding

Exam-style questions on this lesson. Get them all right to mark the lesson complete.

Question 1

1.Which feature finds names of people, places, organizations and dates in text?

Question 2

2.You must remove phone numbers and email addresses from support tickets before storing them. Which feature helps?

Question 3

3.Which feature returns the main talking points of a document as short phrases?

Question 4

4.What is the difference between extractive and abstractive summarization?

Question 5

5.Which two values do you typically need to create a Text Analytics client with a key?

Finished reading?

Tools mentioned in this article

← AI-901 course outline