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:
- Azure Language in Foundry Tools (formerly Azure AI Language): purpose-built, pre-trained features with consistent, structured output and confidence scores.
- 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
| Feature | What it returns |
|---|---|
| Language detection | The language of the text and a confidence score |
| Sentiment analysis | Positive, negative, neutral or mixed, per document and per sentence |
| Opinion mining | Sentiment about specific aspects ("battery: positive") |
| Key phrase extraction | The main talking points |
| Named entity recognition (NER) | People, locations, organizations, dates, quantities and more |
| Entity linking | Entities matched to a knowledge base, such as Wikipedia |
| PII detection | Personal information like phone numbers and emails, plus a redacted version of the text |
| Summarization | Extractive (key sentences) or abstractive (newly written) summaries of documents and conversations |
| Custom features | Custom 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 scores | The task is unusual or needs reasoning |
| You process large volumes cheaply | You want flexible output (explanations, rewrites) |
| You need PII redaction or entity linking | You 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.
Finished reading?