AI-900Chapter 16 of 100Objective 4.3

Sentiment Analysis and Key Phrase Extraction

This chapter covers sentiment analysis and key phrase extraction, two fundamental capabilities of Azure AI Language within the Natural Language Processing (NLP) domain. For the AI-900 exam, these topics appear in roughly 10-15% of questions related to NLP workloads (Objective 4.3). You will learn how these features work under the hood, how to call them via the Azure AI Language API, and how to interpret their outputs. Mastering these concepts is essential for demonstrating how Azure AI can derive insights from unstructured text.

25 min read
Intermediate
Updated May 31, 2026

The Customer Feedback Analyst

Imagine a company that receives thousands of customer feedback forms daily. Each form contains free-text comments. The company hires a team of analysts to process these forms. Each analyst reads a comment, identifies the overall sentiment (positive, negative, or neutral), and underlines key phrases that capture the main topics. For example, for the comment "The new update is great, but the battery life is terrible," an analyst would mark sentiment as mixed and underline "new update," "great," "battery life," and "terrible." Now, this team uses a standardized guidebook: a list of positive words (e.g., "excellent," "fast") and negative words (e.g., "slow," "buggy"), plus rules for handling negation (e.g., "not good" flips sentiment). For key phrases, they look for noun phrases that are frequently mentioned. The team's accuracy depends on the guidebook's quality and their training. In Azure AI Language, the pre-built models act as these trained analysts. The service uses machine learning models trained on millions of labeled examples. When you submit text, it processes it through multiple layers: first, it tokenizes the text into words and punctuation; then, it assigns sentiment scores to each sentence using a deep neural network that considers word order and context; finally, it extracts key phrases by identifying noun phrases using a part-of-speech tagger and statistical significance. The result is a structured JSON output with sentiment labels and confidence scores, and a list of key phrases. Just as the analyst's work helps the company understand customer satisfaction trends, Azure's sentiment analysis and key phrase extraction enable businesses to automatically gauge public opinion and identify recurring topics in large volumes of text.

How It Actually Works

What is Sentiment Analysis and Key Phrase Extraction?

Sentiment analysis and key phrase extraction are two of the pre-built features offered by Azure AI Language (formerly Text Analytics). They are part of the Language service, which provides REST APIs and SDKs for text analysis. Sentiment analysis determines the emotional tone of a piece of text—whether it is positive, negative, mixed, or neutral—at both the document and sentence levels. Key phrase extraction identifies the main talking points or topics within the text, returning a list of phrases that capture the essence of the content.

These features are widely used in business scenarios such as social media monitoring, customer feedback analysis, and survey processing. They allow organizations to automatically process large volumes of unstructured text and gain actionable insights without manual effort.

How Sentiment Analysis Works Internally

Azure's sentiment analysis uses a deep learning model based on a transformer architecture, similar to BERT (Bidirectional Encoder Representations from Transformers). The model is trained on a large corpus of text with human-labeled sentiment scores at the sentence and document levels. Here is the step-by-step mechanism:

1.

Text Preprocessing: The input text is tokenized into words, subwords, and punctuation. The service uses a tokenizer that splits text into tokens suitable for the model. For example, the sentence "I love Azure!" becomes tokens ["I", "love", "Azure", "!"].

2.

Encoding: Each token is converted into a numerical vector (embedding) that captures its meaning and context. The transformer model uses self-attention to weigh the importance of each token relative to others, enabling it to understand context like negation (e.g., "not good" is different from "good").

3.

Sentiment Scoring: The model outputs a sentiment score for each sentence and for the entire document. Scores range from 0 (negative) to 1 (positive). The service also provides labels: "positive" (score > 0.5), "negative" (score < 0.5), "neutral" (score = 0.5), or "mixed" (if both positive and negative scores are significant). The document-level sentiment is not simply an average of sentence scores; it is computed separately by the model, considering the overall context.

4.

Confidence Scores: For each sentiment label, the model outputs a confidence score between 0 and 1 indicating how sure it is. These scores are useful for filtering low-confidence results.

How Key Phrase Extraction Works Internally

Key phrase extraction uses a different model that focuses on identifying noun phrases and other significant terms. The process involves:

1.

Part-of-Speech Tagging: The text is parsed to identify parts of speech (nouns, verbs, adjectives, etc.). This helps isolate candidate noun phrases.

2.

Phrase Chunking: The service groups words into chunks that form meaningful phrases. For example, in "machine learning model," the phrase "machine learning model" is identified as a key phrase.

3.

Ranking: The extracted phrases are ranked by importance based on frequency, relevance, and other statistical measures. The top phrases are returned in order of significance.

4.

Output: The API returns a list of key phrases as strings. There is no confidence score for individual key phrases; the list is simply the extracted phrases.

API Usage and Configuration

To use sentiment analysis or key phrase extraction, you call the Azure AI Language REST API. The endpoint is typically:

https://<your-resource-name>.cognitiveservices.azure.com/text/analytics/v3.1/sentiment

For key phrase extraction:

https://<your-resource-name>.cognitiveservices.azure.com/text/analytics/v3.1/keyPhrases

You need a valid API key and a JSON payload containing the documents to analyze. Each document is an object with an "id", "text", and optionally "language". Here is an example request for sentiment analysis:

{
  "documents": [
    {
      "id": "1",
      "language": "en",
      "text": "The product is excellent. I am very satisfied."
    },
    {
      "id": "2",
      "language": "en",
      "text": "The service was terrible and slow."
    }
  ]
}

The response includes sentiment labels and scores for each document and each sentence. For key phrase extraction, the response contains a list of key phrases for each document.

Supported Languages and Limits

Sentiment Analysis: Supports over 100 languages, with varying accuracy. English, French, German, Spanish, and Chinese have the highest accuracy. The maximum document size is 5,120 characters. You can send up to 10 documents per request.

Key Phrase Extraction: Supports a subset of languages (around 40). The same size and count limits apply.

Interaction with Other Azure AI Services

Sentiment analysis and key phrase extraction are often used together. For example, you might first extract key phrases to identify topics, then analyze sentiment to understand how people feel about those topics. They can also be combined with other Language features like entity recognition and language detection. For instance, you could detect the language first, then apply sentiment analysis in that language.

Pricing and Throughput

Azure AI Language is billed per 1,000 text records. Each document counts as one record regardless of length (up to the character limit). The free tier (F0) offers 5,000 records per month. The standard tier (S) has no fixed limit but is pay-as-you-go. Throughput is limited by your resource's pricing tier; the S tier can handle up to 20 requests per second by default, but you can request a higher limit.

Error Handling

Common errors include: - InvalidLanguageCode: The specified language is not supported. - InvalidDocument: The document exceeds the size limit or is empty. - Forbidden: The API key is invalid or expired. - TooManyRequests: You have exceeded the rate limit.

Always check the HTTP status code and the error message in the response.

Walk-Through

1

Create Azure AI Language Resource

In the Azure portal, create a Language service resource. Choose the free tier (F0) for testing or standard (S) for production. Note the endpoint and key. This resource will be used for all API calls.

2

Prepare Text Documents

Assemble your text data into JSON format. Each document must have a unique ID, the text content (max 5,120 characters), and optional language code. For best accuracy, specify the language explicitly. If omitted, the service auto-detects.

3

Call Sentiment Analysis API

Send a POST request to the sentiment endpoint with your JSON payload. The service returns sentiment labels (positive, negative, neutral, mixed) and confidence scores for each document and each sentence. Examine the response to understand the overall tone.

4

Call Key Phrase Extraction API

Send a POST request to the keyPhrases endpoint with the same or different documents. The response contains a list of key phrases for each document. These phrases represent the main topics discussed.

5

Interpret and Use Results

Analyze the output. For sentiment, use the document-level score to gauge overall sentiment. For key phrases, look for frequently occurring terms to identify common themes. Integrate these insights into dashboards, alerts, or downstream applications.

What This Looks Like on the Job

Enterprise Scenario 1: Social Media Monitoring for Brand Reputation

A large retail company monitors Twitter mentions to gauge public sentiment about its brand. They use Azure AI Language's sentiment analysis to automatically classify tweets as positive, negative, or neutral. Key phrase extraction identifies trending topics like "shipping delays" or "product quality." The system processes over 100,000 tweets daily. The API is called from an Azure Function triggered by a Twitter stream. Results are stored in Azure Cosmos DB and visualized in Power BI dashboards. When negative sentiment spikes, an alert triggers a manual review. A common misconfiguration is not specifying the language code, causing misclassification of tweets in mixed languages. Also, the free tier's 5,000 records per month limit is quickly exceeded; they needed the S tier. Performance considerations include API rate limits—at 20 requests per second, they batch tweets into groups of 10 to maximize throughput.

Enterprise Scenario 2: Customer Feedback Analysis in Call Centers

A telecom company analyzes post-call survey responses. Customers leave voice feedback transcribed by Azure Speech to Text. The transcribed text is then analyzed using sentiment analysis and key phrase extraction. This identifies common complaints (e.g., "billing issues") and overall satisfaction trends. The system processes 500,000 transcripts per month. They use the Language service's asynchronous operation for large batches. A common pitfall is not handling mixed sentiment correctly—a survey that says "The service was great, but the price is too high" is labeled "mixed" by the API, but their initial logic treated it as neutral, missing the negative aspect. They learned to use sentence-level scores to drill down into specifics.

Enterprise Scenario 3: Automated Content Moderation

A social media platform uses sentiment analysis to flag potentially harmful content. They combine sentiment analysis with other AI services like Content Moderator. For example, a post with very negative sentiment and aggressive key phrases like "hate" or "attack" is escalated for review. They process millions of posts daily, requiring high throughput. They implemented a caching layer to avoid redundant API calls for identical text. A scaling challenge was the API's 10 documents per request limit; they built a queue system to batch requests efficiently. Misconfiguration of the region (e.g., using a resource in a different geography) increased latency, so they deployed resources in multiple regions.

How AI-900 Actually Tests This

What AI-900 Tests on Sentiment Analysis and Key Phrase Extraction

AI-900 Objective 4.3: Identify features of NLP workloads on Azure. Specifically, you need to know:

The purpose of sentiment analysis: determine positive, negative, neutral, or mixed sentiment.

The purpose of key phrase extraction: identify main talking points.

That both are part of the Azure AI Language service (formerly Text Analytics).

How to call the APIs: REST endpoints, JSON payload, API key.

Output formats: sentiment returns labels and scores; key phrases return a list of strings.

Supported languages and limits: 5,120 characters per document, 10 documents per request.

Pricing: free tier (5,000 records/month) and standard tier (pay-as-you-go).

Common Wrong Answers and Why Candidates Choose Them

1.

Wrong: Sentiment analysis returns a single score for the entire document. Many candidates think it only gives a document-level score. In reality, it returns both document-level and sentence-level scores. The exam may ask about sentence-level analysis.

2.

Wrong: Key phrase extraction returns phrases with confidence scores. Candidates confuse it with entity recognition. Key phrases are returned as a list without scores.

3.

Wrong: You need to train a custom model. The exam emphasizes that these are pre-built capabilities. No training is required; you just call the API.

4.

Wrong: Sentiment analysis works only for English. Actually, it supports over 100 languages, though accuracy varies.

Specific Numbers and Terms to Memorize

Maximum document size: 5,120 characters.

Maximum documents per request: 10.

Sentiment labels: positive, negative, neutral, mixed.

Free tier: 5,000 text records per month.

API version: v3.1 (current at time of writing).

Edge Cases and Exam Traps

Empty text: The API returns an error. Always check for non-empty input.

Mixed sentiment: When both positive and negative sentiments are strong, the document is labeled "mixed." The exam may test that this is different from neutral.

Language auto-detection: If you omit the language, the service auto-detects, but it may be inaccurate for short texts. The exam may ask about best practices: always specify the language if known.

How to Eliminate Wrong Answers

Read the question carefully. If it asks about "identifying the overall feeling" of text, it's sentiment analysis. If it asks about "extracting main topics," it's key phrase extraction. If the answer mentions training or custom models, it's likely wrong because these are pre-built. Look for keywords like "confidence score" only for sentiment; key phrases have none. Also, remember that both are part of Azure AI Language, not separate services.

Key Takeaways

Sentiment analysis and key phrase extraction are pre-built features of Azure AI Language.

Sentiment analysis returns document-level and sentence-level scores with labels: positive, negative, neutral, mixed.

Key phrase extraction returns a list of significant phrases without confidence scores.

Maximum document size is 5,120 characters; maximum 10 documents per API request.

Free tier (F0) allows 5,000 text records per month; standard (S) is pay-as-you-go.

Always specify the language code for best accuracy; auto-detection may be unreliable for short texts.

Both features are accessed via REST API with a JSON payload and API key.

No custom training is required—use the pre-built models directly.

Easy to Mix Up

These come up on the exam all the time. Here's how to tell them apart.

Sentiment Analysis

Determines emotional tone (positive, negative, neutral, mixed)

Returns confidence scores for each label

Works at document and sentence levels

Supports 100+ languages

Output includes structured JSON with scores

Key Phrase Extraction

Extracts main talking points or topics

Returns list of phrases without confidence scores

Works at document level only

Supports ~40 languages

Output is a simple list of strings

Watch Out for These

Mistake

Sentiment analysis only gives a positive or negative label.

Correct

It also returns 'neutral' and 'mixed' labels, plus confidence scores for each label.

Mistake

Key phrase extraction returns the most frequent words in the text.

Correct

It returns meaningful phrases (noun phrases) that capture key topics, not just frequent words.

Mistake

You must train a custom model for sentiment analysis.

Correct

Azure provides pre-built models that work out of the box. No training is needed.

Mistake

The free tier allows unlimited API calls.

Correct

The free tier (F0) allows 5,000 text records per month. Exceeding this results in errors.

Mistake

Sentiment analysis works only on English text.

Correct

It supports over 100 languages, including French, German, Spanish, Chinese, etc.

Do You Actually Know This?

Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.

Frequently Asked Questions

What is the difference between sentiment analysis and key phrase extraction?

Sentiment analysis determines the emotional tone of text (positive, negative, neutral, mixed) and returns confidence scores. Key phrase extraction identifies the main topics or talking points in the text, returning a list of phrases without scores. Both are part of Azure AI Language.

How do I call the sentiment analysis API in Azure?

Send a POST request to `https://<your-resource-name>.cognitiveservices.azure.com/text/analytics/v3.1/sentiment` with a JSON payload containing documents. Each document has an id, text, and optional language. Include the Ocp-Apim-Subscription-Key header with your API key.

What does the sentiment analysis response look like?

The response includes a `sentiment` field per document (positive, negative, neutral, mixed) and `confidenceScores` for each label. It also includes `sentences` array with per-sentence sentiment and scores. Example: `{"documents": [{"id": "1", "sentiment": "positive", "confidenceScores": {"positive": 0.99, "neutral": 0.01, "negative": 0.0}, "sentences": [...]}]}`

Can I use sentiment analysis for multiple languages?

Yes, sentiment analysis supports over 100 languages. Specify the language code in each document for best accuracy. If omitted, the service auto-detects, but this is less reliable for short texts.

What are the limits of the free tier for Azure AI Language?

The free tier (F0) allows 5,000 text records per month. Each document counts as one record regardless of length (up to 5,120 characters). You can send up to 10 documents per request.

How does key phrase extraction determine which phrases to return?

The model uses part-of-speech tagging to identify noun phrases, then ranks them by importance based on frequency and relevance. It returns the top phrases as a list. There is no confidence score.

Is it possible to get mixed sentiment in a single document?

Yes. If a document contains both positive and negative statements, the API may label it 'mixed' at the document level. For example, 'The product is great but the delivery was late.' The sentence-level scores will show the individual sentiments.

Terms Worth Knowing

Ready to put this to the test?

You've just covered Sentiment Analysis and Key Phrase Extraction — now see how well it sticks with free AI-900 practice questions. Full explanations included, no account needed.

Done with this chapter?