Skip to main content

Challenge 15: Sentiment Analysis and Language Detection

Estimated Time

20-30 min | Cost: Free | Domain: Natural Language Processing (15-20%)

Exam skills covered

  • Identify features and uses for sentiment analysis
  • Identify features and uses for language modeling
  • Identify Azure AI Language service capabilities

Overview

Sentiment analysis determines whether text expresses positive, negative, neutral, or mixed feelings. It works at both the document level (overall sentiment) and the sentence level (individual statement sentiment). For example, a product review saying "The camera quality is amazing but the battery life is terrible" would be classified as "mixed" overall, with the first clause positive and the second negative.

Azure AI Language returns confidence scores for each sentiment (positive, negative, neutral) that add up to 1.0. A sentence like "The hotel was okay" might score 0.1 positive, 0.1 negative, 0.8 neutral — indicating the model is most confident it's neutral. This granularity helps businesses understand not just whether customers are happy, but how strongly they feel.

Language detection identifies which language a piece of text is written in and returns a confidence score. It supports 120+ languages and can detect even very short text samples. This capability is essential as a first step in multilingual processing pipelines — you need to know the language before you can analyze sentiment, extract entities, or translate content.

Explore

Task 1: Understand sentiment analysis scoring

Sentiment analysis returns scores for three categories. Review these examples:

TextPositiveNegativeNeutralOverall
"I absolutely love this product!"0.980.010.01Positive
"The service was terrible and rude."0.010.970.02Negative
"The meeting is scheduled for Tuesday."0.050.020.93Neutral
"Great food but awful service."0.500.480.02Mixed

Key insight: "Mixed" sentiment occurs when a document contains both positive and negative sentiments at the sentence level.

Task 2: Try sentiment analysis in Language Studio

Navigate to: language.cognitive.azure.com

  1. Select Classify textAnalyze sentiment and mine opinions
  2. Try these sample texts one at a time:

Sample 1 (Positive):

"The new Azure AI services are incredibly powerful and easy to use. The documentation is clear and the support team is very responsive."

Sample 2 (Mixed):

"The hotel room was spacious and clean with a beautiful view. However, the restaurant food was cold and overpriced, and checkout took forever."

Sample 3 (Neutral):

"The Azure AI Language service supports over 120 languages for text analysis. It is available in multiple Azure regions."

  1. Observe how the service provides:
    • Document-level sentiment (overall)
    • Sentence-level sentiment (each sentence)
    • Confidence scores for each category

Task 3: Explore opinion mining

Opinion mining is an advanced feature of sentiment analysis that identifies:

  • Targets — what the opinion is about (e.g., "food," "staff," "battery")
  • Assessments — the opinion expressed (e.g., "delicious," "friendly," "short")

Example:

"The pizza was delicious but the delivery was slow."

TargetAssessmentSentiment
pizzadeliciousPositive
deliveryslowNegative

This is valuable for understanding what specifically customers like or dislike.

Task 4: Understand language detection

Language detection identifies the language of input text. Try these examples mentally:

InputDetected LanguageConfidenceISO Code
"Hello, how are you?"English1.0en
"Bonjour, comment allez-vous?"French1.0fr
"こんにちは"Japanese1.0ja
"asdf"Unknown0.0(unknown)

Important behaviors:

  • Returns the language with highest confidence
  • Returns "unknown" with NaN confidence for ambiguous or nonsensical input
  • Works best with at least one sentence of text
  • Can detect mixed-language documents (returns predominant language)
Azure CLI Alternative
# Call the sentiment analysis endpoint
az cognitiveservices account show \
--name my-language-resource \
--resource-group myResourceGroup \
--query "properties.endpoint"

Key Concepts

ConceptDefinition
Sentiment analysisDetermines whether text is positive, negative, neutral, or mixed
Document-level sentimentThe overall sentiment of an entire text document
Sentence-level sentimentIndividual sentiment classification for each sentence in a document
Opinion miningIdentifies specific targets (aspects) and the sentiments expressed about them
Confidence scoreA value between 0 and 1 indicating how confident the model is in its prediction
Language detectionIdentifies which human language text is written in

Common Misconceptions

MisconceptionReality
Sentiment analysis understands sarcasm perfectlyAI often struggles with sarcasm, irony, and cultural nuances — these may be misclassified
Mixed sentiment means the model is uncertainMixed means the document contains BOTH positive and negative sentiments; uncertainty shows as similar scores across categories
Language detection needs long textIt can work with even a single word, though accuracy improves with more text
Sentiment scores are always accurate for all domainsPre-built models work best on general text; domain-specific language (medical, legal) may need custom models
Neutral means the model couldn't determine sentimentNeutral is a legitimate classification — it means the text doesn't express positive or negative emotion (e.g., factual statements)

Knowledge Check

1. A customer review states: "The camera is excellent but the battery drains too quickly." How would sentiment analysis classify this document?

2. What does language detection return when it cannot identify the language of the input text?

3. A company processes customer feedback from 50 countries. Which capability should be applied FIRST in their NLP pipeline?

4. In sentiment analysis, what do confidence scores represent?

5. What does opinion mining add beyond basic sentiment analysis?

Learn More