azure-ai-textanalytics-py – skill DevOps & Hạ tầng cho agent AI
SDK Azure AI Text Analytics để phân tích cảm xúc, nhận diện thực thể, cụm từ khóa, nhận diện ngôn ngữ, PII và NLP y tế. Dùng để xử lý ngôn ngữ tự nhiên trên văn bản.
Cài skill azure-ai-textanalytics-py bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-ai-textanalytics-py-28e4d.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /azure-ai-textanalytics-py – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-ai-textanalytics-py-28e4d.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $azure-ai-textanalytics-py – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-ai-textanalytics-py-28e4d.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /azure-ai-textanalytics-py – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-ai-textanalytics-py-28e4d.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /azure-ai-textanalytics-py – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
Azure AI Text Analytics SDK for Python
Client library for Azure AI Language service NLP capabilities including sentiment, entities, key phrases, and more.
Installation
pip install azure-ai-textanalyticsEnvironment Variables
AZURE_LANGUAGE_ENDPOINT=https://<resource>.cognitiveservices.azure.com
AZURE_LANGUAGE_KEY=<your-api-key> # If using API keyAuthentication
API Key
import os
from azure.core.credentials import AzureKeyCredential
from azure.ai.textanalytics import TextAnalyticsClient
endpoint = os.environ["AZURE_LANGUAGE_ENDPOINT"]
key = os.environ["AZURE_LANGUAGE_KEY"]
client = TextAnalyticsClient(endpoint, AzureKeyCredential(key))Entra ID (Recommended)
from azure.ai.textanalytics import TextAnalyticsClient
from azure.identity import DefaultAzureCredential
client = TextAnalyticsClient(
endpoint=os.environ["AZURE_LANGUAGE_ENDPOINT"],
credential=DefaultAzureCredential()
)Data handling
Calls send document text to Azure. Obtain authorization for private, PII or health data and verify region, retention and permitted use; redaction is probabilistic and does not guarantee de-identification. Healthcare extraction is not diagnosis. Examples are independent fragments; check each per-document error before consuming result fields.
Sentiment Analysis
documents = [
"I had a wonderful trip to Seattle last week!",
"The food was terrible and the service was slow."
]
result = client.analyze_sentiment(documents, show_opinion_mining=True)
for doc in result:
if not doc.is_error:
print(f"Sentiment: {doc.sentiment}")
print(f"Scores: pos={doc.confidence_scores.positive:.2f}, "
f"neg={doc.confidence_scores.negative:.2f}, "
f"neu={doc.confidence_scores.neutral:.2f}")
# Opinion mining (aspect-based sentiment)
for sentence in doc.sentences:
for opinion in sentence.mined_opinions:
target = opinion.target
print(f" Target: '{target.text}' - {target.sentiment}")
for assessment in opinion.assessments:
print(f" Assessment: '{assessment.text}' - {assessment.sentiment}")Entity Recognition
documents = ["Microsoft was founded by Bill Gates and Paul Allen in Albuquerque."]
result = client.recognize_entities(documents)
for doc in result:
if not doc.is_error:
for entity in doc.entities:
print(f"Entity: {entity.text}")
print(f" Category: {entity.category}")
print(f" Subcategory: {entity.subcategory}")
print(f" Confidence: {entity.confidence_score:.2f}")PII Detection
documents = ["My SSN is 123-45-6789 and my email is [email protected]"]
result = client.recognize_pii_entities(documents)
for doc in result:
if not doc.is_error:
print(f"Redacted: {doc.redacted_text}")
for entity in doc.entities:
print(f"PII category: {entity.category}") # Do not log detected sensitive values.Key Phrase Extraction
documents = ["Azure AI provides powerful machine learning capabilities for developers."]
result = client.extract_key_phrases(documents)
for doc in result:
if not doc.is_error:
print(f"Key phrases: {doc.key_phrases}")Language Detection
documents = ["Ce document est en francais.", "This is written in English."]
result = client.detect_language(documents)
for doc in result:
if not doc.is_error:
print(f"Language: {doc.primary_language.name} ({doc.primary_language.iso6391_name})")
print(f"Confidence: {doc.primary_language.confidence_score:.2f}")Healthcare Text Analytics
documents = ["Patient has diabetes and was prescribed metformin 500mg twice daily."]
poller = client.begin_analyze_healthcare_entities(documents)
result = poller.result()
for doc in result:
if not doc.is_error:
for entity in doc.entities:
print(f"Entity: {entity.text}")
print(f" Category: {entity.category}")
print(f" Normalized: {entity.normalized_text}")
# Entity links (UMLS, etc.)
for link in entity.data_sources:
print(f" Link: {link.name} - {link.entity_id}")Multiple Analysis (Batch)
from azure.ai.textanalytics import (
RecognizeEntitiesAction,
ExtractKeyPhrasesAction,
AnalyzeSentimentAction
)
documents = ["Microsoft announced new Azure AI features at Build conference."]
poller = client.begin_analyze_actions(
documents,
actions=[
RecognizeEntitiesAction(),
ExtractKeyPhrasesAction(),
AnalyzeSentimentAction()
]
)
results = poller.result()
for doc_results in results:
for result in doc_results:
if result.kind == "EntityRecognition":
print(f"Entities: {[e.text for e in result.entities]}")
elif result.kind == "KeyPhraseExtraction":
print(f"Key phrases: {result.key_phrases}")
elif result.kind == "SentimentAnalysis":
print(f"Sentiment: {result.sentiment}")Async Client
from azure.ai.textanalytics.aio import TextAnalyticsClient
from azure.identity.aio import DefaultAzureCredential
async def analyze():
async with TextAnalyticsClient(
endpoint=endpoint,
credential=DefaultAzureCredential()
) as client:
result = await client.analyze_sentiment(documents)
# Process results...Client Types
| Client | Purpose |
|--------|---------|
| TextAnalyticsClient | All text analytics operations |
| TextAnalyticsClient (aio) | Async version |
Available Operations
| Method | Description |
|--------|-------------|
| analyze_sentiment | Sentiment analysis with opinion mining |
| recognize_entities | Named entity recognition |
| recognize_pii_entities | PII detection and redaction |
| recognize_linked_entities | Entity linking to Wikipedia |
| extract_key_phrases | Key phrase extraction |
| detect_language | Language detection |
| begin_analyze_healthcare_entities | Healthcare NLP (long-running) |
| begin_analyze_actions | Multiple analyses in batch |
Best Practices
1. Use batch operations for multiple documents (up to 10 per request)
2. Enable opinion mining for detailed aspect-based sentiment
3. Use async client for high-throughput scenarios
4. Handle document errors — results list may contain errors for some docs
5. Specify language when known to improve accuracy
6. Use context manager or close client explicitly
When to Use
This skill is applicable to execute the workflow or actions described in the overview.
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
Skill liên quan
- azure-ai-transcription-py – SDK Azure AI Transcription cho Python. Dùng để chuyển file âm thanh thành văn bản kèm…
- k8s-manifest-generator – Tạo manifest Kubernetes sẵn sàng cho production cho Deployments, Services, ConfigMaps và…
- azure-ai-vision-imageanalysis-py – SDK Azure AI Vision Image Analysis cho chú thích, thẻ, đối tượng, OCR, nhận diện người…
- azure-ai-voicelive-dotnet – SDK Azure AI Voice Live cho .NET. Xây dựng ứng dụng AI giọng nói thời gian thực với giao…
- azure-ai-voicelive-py – Xây dựng ứng dụng AI giọng nói thời gian thực với giao tiếp WebSocket hai chiều.
- azure-ai-voicelive-ts – SDK Azure AI Voice Live cho JavaScript/TypeScript. Xây dựng ứng dụng AI giọng nói thời…
- azure-aks – Triển khai và quản lý cụm Azure Kubernetes Service. Cấu hình node pool, mạng và tích…
- azure-appconfiguration-py – SDK Azure App Configuration cho Python. Dùng để quản lý cấu hình tập trung, feature flag…