Natural Language Processing (NLP) enables computers to understand, interpret, and generate human language. Azure AI provides various NLP capabilities through Azure AI Language Services, allowing developers to build intelligent applications that analyze and process text.
Azure AI Language Services is a cloud-based NLP service that provides pre-trained models and tools to analyze and process natural language data.
Azure AI Language Services provides AI-powered NLP functionalities for analyzing text, detecting language, recognizing entities, and even translating between languages.
For Python users, install the required package:
pip install azure-ai-textanalytics
Below is a simple Python script that analyzes text for key phrases, entities, and sentiment.
from azure.ai.textanalytics import TextAnalyticsClient
from azure.core.credentials import AzureKeyCredential
#Azure AI Language Credentials
API_KEY = "your_api_key"
ENDPOINT = "https://your-language-endpoint.com"
#Create a Text Analytics Client
client = TextAnalyticsClient(ENDPOINT, AzureKeyCredential(API_KEY))
#Define text for analysis
documents = ["Azure AI Language Services are powerful for NLP tasks."]
#Analyze text
response = client.analyze_sentiment(documents)
#Print sentiment analysis results
for doc in response:
print(f"Overall Sentiment: {doc.sentiment}, Confidence Scores: {doc.confidence_scores}")
The API returns structured NLP analysis results in JSON format:
{
"sentiment": "positive",
"confidence_scores": {
"positive": 0.95,
"neutral": 0.03,
"negative": 0.02
}
}
Text Analytics enables applications to extract important information from text, such as key phrases, named entities, and personal data (PII detection).
Azure Text Analytics can:
Below is a Python example to extract key phrases and detect entities.
from azure.ai.textanalytics import TextAnalyticsClient
from azure.core.credentials import AzureKeyCredential
#Azure AI Credentials
API_KEY = "your_api_key"
ENDPOINT = "https://your-language-endpoint.com"
#Create a Text Analytics Client
client = TextAnalyticsClient(ENDPOINT, AzureKeyCredential(API_KEY))
#Define text for analysis
documents = ["Microsoft Azure AI provides cloud-based NLP services for developers."]
#Extract key phrases
key_phrases_result = client.extract_key_phrases(documents)
print("Key Phrases:", key_phrases_result)
#Extract named entities
entities_result = client.recognize_entities(documents)
print("Entities:", entities_result)
{
"keyPhrases": ["Microsoft Azure", "AI", "NLP services", "developers"]
}
{
"entities": [
{"text": "Microsoft Azure", "category": "Organization"},
{"text": "AI", "category": "Technology"},
{"text": "developers", "category": "Profession"}
]
}
Named Entity Recognition (NER) identifies important entities in text, such as:
#Define text containing entities
documents = ["Elon Musk is the CEO of Tesla, based in California."]
#Perform Named Entity Recognition (NER)
ner_results = client.recognize_entities(documents)
#Print detected entities
for entity in ner_results[0].entities:
print(f"Entity: {entity.text}, Category: {entity.category}, Confidence: {entity.confidence_score:.2f}")
{
"entities": [
{"text": "Elon Musk", "category": "Person"},
{"text": "Tesla", "category": "Organization"},
{"text": "California", "category": "Location"}
]
}
Sentiment analysis is a natural language processing (NLP) technique used to determine the emotional tone behind a piece of text. It is widely used in customer feedback analysis, chatbot responses, social media monitoring, and content moderation.
Sentiment analysis enables applications to analyze user opinions and classify text as:
Azure's Text Analytics Sentiment Analysis API provides:
from azure.ai.textanalytics import TextAnalyticsClient
from azure.core.credentials import AzureKeyCredential
#Azure AI Credentials
API_KEY = "your_api_key"
ENDPOINT = "https://your-language-endpoint.com"
#Create a Text Analytics Client
client = TextAnalyticsClient(ENDPOINT, AzureKeyCredential(API_KEY))
#Define sample customer reviews
documents = [
"I absolutely love this product! It works great and exceeded my expectations.",
"The delivery was delayed, but the product quality was okay.",
"This is the worst experience I have ever had. I am very disappointed."
]
#Perform sentiment analysis
sentiment_results = client.analyze_sentiment(documents)
#Print results
for doc in sentiment_results:
print(f"Text: {doc.sentences[0].text}")
print(f"Overall Sentiment: {doc.sentiment}")
print(f"Confidence Scores: Positive: {doc.confidence_scores.positive:.2f}, Neutral: {doc.confidence_scores.neutral:.2f}, Negative: {doc.confidence_scores.negative:.2f}")
print("-" * 50)
The API returns sentiment scores for each document:
[
{
"sentiment": "positive",
"confidence_scores": {
"positive": 0.95,
"neutral": 0.03,
"negative": 0.02
}
},
{
"sentiment": "neutral",
"confidence_scores": {
"positive": 0.40,
"neutral": 0.50,
"negative": 0.10
}
},
{
"sentiment": "negative",
"confidence_scores": {
"positive": 0.05,
"neutral": 0.10,
"negative": 0.85
}
}
]
Standard sentiment analysis determines overall sentiment, but Aspect-Based Sentiment Analysis (ABSA) can analyze opinions on specific topics.
Consider this customer review:
"The battery life of this phone is amazing, but the camera quality is poor."
Standard sentiment analysis might classify the whole review as neutral, but aspect-based sentiment analysis can determine:
#Define a review with multiple aspects
documents = ["The battery life of this phone is amazing, but the camera quality is poor."]
#Perform aspect-based sentiment analysis
aspect_results = client.analyze_sentiment(documents, show_opinion_mining=True)
#Print aspect-based sentiment analysis results
for sentence in aspect_results[0].sentences:
for opinion in sentence.mined_opinions:
print(f"Aspect: {opinion.aspect.text}, Sentiment: {opinion.sentiment}")
for opinion_detail in opinion.opinions:
print(f" - Related Opinion: {opinion_detail.text}, Sentiment: {opinion_detail.sentiment}")
Aspect: battery life, Sentiment: positive
- Related Opinion: amazing, Sentiment: positive
Aspect: camera quality, Sentiment: negative
- Related Opinion: poor, Sentiment: negative
| Industry | Use Case |
|---|---|
| E-Commerce | Analyze product reviews to improve listings. |
| Customer Support | Detect negative sentiment in emails and route them to urgent support. |
| Social Media | Monitor brand reputation by analyzing public sentiment. |
| Finance | Analyze news articles and customer feedback about stock trends. |
Text summarization is an NLP technique that enables AI to generate concise summaries of long-form content. It helps businesses extract key insights from lengthy documents, news articles, reports, and legal texts.
Text summarization allows AI to shorten long text while preserving key information. Azure AI provides two types of summarization:
| Summarization Type | How It Works | Example |
|---|---|---|
| Extractive Summarization | Selects the most important sentences from the original text. | “The company announced record profits. Revenue increased by 20%.” |
| Abstractive Summarization | Generates new sentences that capture the meaning of the original text. | “The company reported significant financial growth.” |
Azure AI provides prebuilt models for text summarization, accessible via REST APIs and SDKs.
pip install azure-ai-textanalytics
Extractive summarization selects key sentences from the input text.
from azure.ai.textanalytics import TextAnalyticsClient
from azure.core.credentials import AzureKeyCredential
#Azure AI Credentials
API_KEY = "your_api_key"
ENDPOINT = "https://your-language-endpoint.com"
#Create a Text Analytics Client
client = TextAnalyticsClient(ENDPOINT, AzureKeyCredential(API_KEY))
#Define a long document for summarization
document = ["The company announced its quarterly earnings report. Revenue increased by 20% compared to the previous year. The CEO stated that the company plans to expand into new markets. Despite global economic challenges, the company remains optimistic about future growth."]
#Perform extractive summarization
summary_result = client.extract_summary(document)
#Print summarized text
for sentence in summary_result[0].sentences:
print(sentence.text)
The company announced its quarterly earnings report.
Revenue increased by 20% compared to the previous year.
Abstractive summarization rewrites text in a more concise way.
#Perform abstractive summarization
summary_result = client.abstractive_summarization(document)
#Print summary
print("Summary:", summary_result.summary)
The company reported strong financial growth, with revenue up 20%.
| Industry | Use Case |
|---|---|
| Legal | Summarizing long contracts for quick review. |
| Healthcare | Extracting critical insights from medical reports. |
| News & Media | Generating short news briefs from lengthy articles. |
| Customer Support | Summarizing chatbot conversations for analytics. |
Language translation is a key NLP capability that enables real-time text translation between multiple languages. Azure Translator API provides fast, accurate, and customizable translation services for global applications.
Language translation allows AI to convert text from one language to another while preserving meaning and context. Azure Translator API supports:
| Translation Type | Description | Example |
|---|---|---|
| Standard Translation | Converts text from one language to another. | "Hello" → "Hola" (Spanish) |
| Custom Translation | Trains AI to handle domain-specific vocabulary. | "Cloud computing" (tech) vs. "Cloud" (weather) |
| Document Translation | Translates entire documents while keeping formatting intact. | PDF, Word, Excel |
pip install azure-ai-translation-text
import requests
#Azure Translator API credentials
API_KEY = "your_api_key"
ENDPOINT = "https://api.cognitive.microsofttranslator.com"
LOCATION = "your_region"
#Define text and target language
text = "Hello, how are you?"
target_language = "fr"
#Define headers and request payload
headers = {
"Ocp-Apim-Subscription-Key": API_KEY,
"Ocp-Apim-Subscription-Region": LOCATION,
"Content-Type": "application/json"
}
body = [{"text": text}]
#Make the API request
response = requests.post(f"{ENDPOINT}/translate?api-version=3.0&to={target_language}", headers=headers, json=body)
#Print the translated text
print(response.json()[0]["translations"][0]["text"])
Bonjour, comment ça va?
response = requests.post(f"{ENDPOINT}/translate?api-version=3.0&to={target_language}&from=", headers=headers, json=body)
print("Detected Language:", response.json()[0]["detectedLanguage"]["language"])
print("Translation:", response.json()[0]["translations"][0]["text"])
Detected Language: en
Translation: Bonjour, comment ça va?
Azure Translator API can translate entire documents (PDFs, Word, Excel) while preserving formatting.
import json
#Define document translation request
document_translation_request = {
"source": {"sourceUrl": "https://storageaccount.blob.core.windows.net/source-container"},
"targets": [
{"targetUrl": "https://storageaccount.blob.core.windows.net/target-container", "language": "es"}
]
}
#Submit the translation request
response = requests.post(f"{ENDPOINT}/translator/text/batch/v1.0", headers=headers, json=document_translation_request)
print(response.json())
| Deployment Method | Best For | Example Use Case |
|---|---|---|
| Cloud API | Real-time text translation | Chatbots, customer support |
| Batch Processing | Translating large datasets | Enterprise document translation |
| Edge AI | Offline translation on devices | Mobile apps for travelers |
Speech technologies allow AI to convert spoken language into written text (Speech-to-Text) and generate human-like speech from text (Text-to-Speech). These capabilities are widely used in voice assistants, call center automation, and accessibility applications.
| Technology | Function | Example Use Case |
|---|---|---|
| Speech-to-Text (STT) | Converts spoken language into written text. | Transcribing customer service calls. |
| Text-to-Speech (TTS) | Generates lifelike speech from text. | AI-powered voice assistants. |
Azure Speech-to-Text allows applications to convert spoken language into written text in real-time or from recorded audio files.
pip install azure-cognitiveservices-speech
import azure.cognitiveservices.speech as speechsdk
#Azure Speech API Credentials
SPEECH_KEY = "your_api_key"
SPEECH_REGION = "your_region"
#Create a speech recognition client
speech_config = speechsdk.SpeechConfig(subscription=SPEECH_KEY, region=SPEECH_REGION)
speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config)
print("Speak into your microphone...")
speech_result = speech_recognizer.recognize_once()
#Print transcribed text
if speech_result.reason == speechsdk.ResultReason.RecognizedSpeech:
print(f"Recognized: {speech_result.text}")
else:
print("No speech recognized.")
Speak into your microphone...
Recognized: "Hello, how can I help you today?"
You can also process pre-recorded audio files and extract spoken content.
#Define audio input file
audio_config = speechsdk.AudioConfig(filename="sample_audio.wav")
#Recognize speech from audio file
speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config)
speech_result = speech_recognizer.recognize_once()
print(f"Transcribed Text: {speech_result.text}")
Transcribed Text: "Welcome to Azure AI Speech Services."
Azure Text-to-Speech (TTS) allows applications to convert text into natural-sounding speech.
import azure.cognitiveservices.speech as speechsdk
#Create a speech synthesis client
speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config)
#Define text to convert into speech
text = "Hello! Welcome to Azure AI Speech Services."
#Synthesize speech
speech_synthesizer.speak_text_async(text)
Azure provides prebuilt voices but also supports custom neural voices for a more personalized experience.
#Select a different voice
speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config)
speech_synthesizer.speak_text_async(text)
| Deployment Method | Best For | Example Use Case |
|---|---|---|
| Cloud API | Real-time speech services | Virtual assistants |
| Edge AI | Offline voice processing | Smart home devices |
| Batch Processing | Large-scale speech transcription | Automated podcast transcriptions |
Once an NLP model is trained and tested, the next step is deployment, ensuring that AI-powered text processing, translation, or speech capabilities can be accessed by applications at scale.
Azure provides multiple ways to deploy NLP models, depending on factors like scalability, latency, and cost efficiency.
| Deployment Method | Best For | Example Use Case |
|---|---|---|
| Azure AI Language Services (Cloud API) | Scalable NLP services | Real-time chatbot sentiment analysis |
| Azure Kubernetes Service (AKS) | Large-scale NLP model deployment | AI-powered customer support system |
| Azure IoT Edge | Low-latency, offline NLP inference | Smart devices for voice recognition |
| Azure App Services | Deploying AI-powered web applications | E-commerce search enhancement |
The easiest way to deploy an NLP model is as an Azure Cloud API, allowing applications to send text data and receive NLP processing results in real-time.
The following Flask-based Python API allows users to submit text and get NLP analysis results.
from flask import Flask, request, jsonify
from azure.ai.textanalytics import TextAnalyticsClient
from azure.core.credentials import AzureKeyCredential
#Azure AI Credentials
API_KEY = "your_api_key"
ENDPOINT = "https://your-language-endpoint.com"
#Create an Azure AI Language Client
client = TextAnalyticsClient(ENDPOINT, AzureKeyCredential(API_KEY))
#Create Flask app
app = Flask(__name__)
#Define sentiment analysis API
@app.route('/analyze_sentiment', methods=['POST'])
def analyze_sentiment():
text = request.json.get("text")
response = client.analyze_sentiment([text])
sentiment_result = response[0].sentiment
return jsonify({"text": text, "sentiment": sentiment_result})
#Run the Flask app
if __name__ == '__main__':
app.run(debug=True)
For enterprise-level applications, AI models can be containerized and deployed using Azure Kubernetes Service (AKS).
#Use Python as base image
FROM python:3.9
#Install dependencies
RUN pip install flask azure-ai-textanalytics
#Copy the application
COPY app.py /app/app.py
#Run the Flask API server
CMD ["python", "/app/app.py"]
For real-time NLP inference on edge devices, deploying AI models to IoT Edge is ideal.
import torch
import torch.onnx
#Load trained PyTorch NLP model
model = torch.load("nlp_model.pth")
#Convert model to ONNX format
onnx_model_path = "nlp_model.onnx"
torch.onnx.export(model, torch.randn(1, 300), onnx_model_path)
print("Model converted to ONNX for IoT Edge deployment.")
Once an NLP model is deployed, it must be monitored for performance, accuracy, and drift.
from azureml.core import Workspace, Model
#Connect to Azure ML workspace
ws = Workspace.from_config()
#Register a new NLP model version
model = Model.register(
workspace=ws,
model_name="updated_nlp_model",
model_path="./new_model.onnx"
)
| Deployment Option | Best For | Example Use Case |
|---|---|---|
| Azure AI Language API (Cloud API) | Real-time NLP processing | AI chatbots, content moderation |
| Azure Kubernetes Service (AKS) | Large-scale NLP applications | AI-powered customer support |
| Azure IoT Edge | Offline NLP inference | AI voice assistants in smart homes |
| Azure Batch Processing | NLP on large datasets | Financial document processing |
Language Detection is the process of identifying the language of a given text input. This is often a prerequisite task in NLP pipelines, especially in multilingual applications, to route content to the correct models (e.g., translation, sentiment analysis).
| Service | Supports Language Detection? | How to Use |
|---|---|---|
| Azure Text Analytics API | Yes | DetectLanguage endpoint or feature |
| Azure Translator Service | Auto-detects source language | Specify "from": "auto" in API requests |
| Azure OpenAI | Not built-in; can infer with prompts | Requires creative prompting or tool integration |
POST https://<region>.api.cognitive.microsoft.com/text/analytics/v3.1/languages
Request Body:
{
"documents": [
{
"id": "1",
"text": "Bonjour tout le monde"
}
]
}
Response:
{
"documents": [
{
"id": "1",
"detectedLanguage": {
"name": "French",
"iso6391Name": "fr",
"confidenceScore": 0.99
}
}
]
}
Use Case: Automatically detect user input language before translation or sentiment scoring.
When processing human language (text, transcribed speech), you may encounter Personally Identifiable Information (PII) such as:
Names, emails, phone numbers
National IDs, addresses
Credit card numbers, IP addresses
Under GDPR and other regulations, this data must be protected or redacted before use.
| Feature | Description |
|---|---|
| Text Analytics PII | Detects and redacts PII from unstructured text. Returns masked text and entity categories. |
| Speech-to-Text PII | Azure Speech Service can automatically redact PII in transcriptions via profanityOption: "masked" or piiCategory filters. |
| Data Retention | When storing transcripts, enforce retention policies and encryption. |
POST /text/analytics/v3.1/entities/recognition/pii
{
"documents": [
{
"id": "1",
"text": "My name is Alice and my SSN is 123-45-6789."
}
]
}
Response:
{
"entities": [
{
"text": "123-45-6789",
"category": "U.S. Social Security Number (SSN)",
"confidenceScore": 0.99,
"offset": 27,
"length": 11
}
],
"redactedText": "My name is Alice and my SSN is ***********."
}
| Task | Traditional NLP Services (Text Analytics, Translator, LUIS) | Azure OpenAI (GPT-3.5/4) |
|---|---|---|
| Sentiment Analysis | Built-in models | Possible with prompts, less precise |
| Key Phrase Extraction | Text Analytics | Not native, must prompt manually |
| Named Entity Recognition | Built-in | Can infer with engineered prompts |
| Text Generation (email, FAQ) | Not supported | Native with GPT |
| Multi-turn Chat (Contextual) | Requires Bot Framework + Logic | Built into Chat Completion API |
| Language Detection | Available in APIs | Not built-in, must infer |
| Scenario | Recommended Service |
|---|---|
| Structured insights from customer reviews | Azure Text Analytics (faster, cheaper) |
| Auto-generating FAQs from documents | Azure OpenAI (creative generation) |
| Translating comments into English before mining | Azure Translator + Text Analytics |
| Creating a legal chatbot | Azure OpenAI (flexible, generative) |
Best Practice: Use traditional NLP services for lightweight, structured tasks (e.g., entity extraction, language detection). Use Azure OpenAI for freeform generation, summarization, and conversation.
A sentiment analysis request to Azure Language Service returns “neutral” sentiment for text that appears positive. What is the most likely explanation?
The sentiment model determined that positive and negative signals were balanced or ambiguous.
Azure Language Service sentiment analysis models classify sentiment based on statistical signals across the entire text. If a statement includes mixed cues—for example praise combined with complaints—the model may classify it as neutral. Another factor is that the model evaluates linguistic indicators rather than human interpretation of tone. Developers often assume strongly positive wording will always yield a positive classification, but contextual elements can reduce confidence in that classification. The API also returns confidence scores for positive, neutral, and negative sentiment categories. Reviewing these scores can help determine whether the result is borderline between categories. Understanding that sentiment classification evaluates overall linguistic patterns rather than isolated words helps explain why neutral outcomes sometimes occur.
Demand Score: 70
Exam Relevance Score: 79
A developer notices that Azure Language Service entity recognition does not detect certain expected entities in text. What is a common cause?
The entities may not match the predefined entity categories supported by the model.
Azure Language Service named entity recognition models are trained to identify a specific set of entity categories such as Person, Organization, Location, and Date. If a developer expects the service to recognize domain-specific entities—for example specialized product names or technical identifiers—the model may not detect them because they fall outside the supported taxonomy. Additionally, entity recognition relies on contextual cues, so ambiguous wording may prevent detection. In such cases developers may need to use custom entity extraction models or augment detection logic in their application. Understanding the predefined entity schema is essential when designing NLP pipelines that rely on entity extraction.
Demand Score: 75
Exam Relevance Score: 82
When should Azure OpenAI be used instead of Azure Language Service for NLP tasks?
Azure OpenAI should be used when tasks require generative or flexible language understanding beyond predefined NLP models.
Azure Language Service provides specialized NLP capabilities such as sentiment analysis, entity recognition, summarization, and classification using predefined models optimized for specific tasks. However, these models operate within fixed capabilities and categories. Azure OpenAI models support broader generative and reasoning capabilities, enabling applications such as conversational agents, dynamic summarization, and context-aware text generation. Developers often compare both services when designing NLP solutions. The correct choice depends on whether the task requires structured NLP outputs from predefined models or flexible generative responses. Many AI-102 solution architectures combine both services, using Language Service for structured extraction and Azure OpenAI for generative interaction.
Demand Score: 72
Exam Relevance Score: 84
Why might key phrase extraction return fewer phrases than expected for a document?
The algorithm filters phrases that lack statistical significance or contextual relevance.
Azure Language Service key phrase extraction uses machine learning to identify the most representative terms within a document. The algorithm evaluates phrase frequency, contextual importance, and semantic relevance. If phrases appear frequently but provide limited semantic value, they may be excluded from the results. Developers sometimes expect every noun phrase to be returned, but the service intentionally prioritizes phrases that best represent document meaning. This filtering helps reduce noise and produce concise summaries of document topics. Understanding this ranking behavior explains why the output may contain fewer phrases than expected even when many candidate phrases exist.
Demand Score: 68
Exam Relevance Score: 77
Why might language detection return incorrect language results for short text inputs?
Short text does not provide enough linguistic context for accurate detection.
Language detection models rely on patterns such as character sequences, vocabulary usage, and grammatical structures. When input text is very short—such as a few words or a single phrase—the model may not have sufficient signals to determine the language reliably. Similar words across multiple languages can further increase ambiguity. Azure Language Service may therefore return lower confidence scores or incorrect predictions for short inputs. Providing longer text segments or aggregating multiple inputs improves detection accuracy because the model has more linguistic evidence to analyze. Developers should review confidence scores when interpreting language detection results to assess reliability.
Demand Score: 67
Exam Relevance Score: 78