Azure AI 文本分析 SDK
azure-ai-textanalytics-py
用于情感分析、实体识别、关键短语提取、语言检测、PII(个人身份信息)以及医疗健康 NLP 的 Azure AI 文本分析 SDK。用于对文本执行自然语言处理。 触发词:“text analytics”、“sentiment analysis”、“entity recognition”、“key phrase”、“PII detection”、“TextAnalyticsClient”。
- License 许可
- MIT
- 所属仓库
- microsoft/skills
- 最近更新
- 2026-11-14
- Stars
- ★ 3.2k
- Forks
- 368
01 前言 Front Matter
- name
- azure-ai-textanalytics-py
- license
- MIT
- metadata
- { "author": "Microsoft", "package": "azure-ai-textanalytics", "version": "1.0.0" }
- description
- Azure AI Text Analytics SDK for sentiment analysis, entity recognition, key phrases, language detection, PII, and healthcare NLP. Use for natural language processing on text. Triggers: "text analytics", "sentiment analysis", "entity recognition", "key phrase", "PII detection", "TextAnalyticsClient".
02 资源文件 146
- 参考文档copilot-studio/agent.sync.yaml174 B
- 参考文档copilot-studio/behaviors/aibast_campaign-projection.mcs.yml1.2 KB
- 参考文档copilot-studio/behaviors/aibast_care-gap-closure-cohort-review.mcs.yml1.6 KB
- 参考文档copilot-studio/behaviors/aibast_care-gap-closure-gap-analysis.mcs.yml1.6 KB
- 参考文档copilot-studio/behaviors/aibast_care-gap-closure-outreach-draft.mcs.yml1.6 KB
- 参考文档copilot-studio/behaviors/aibast_care-gap-closure-quality-dashboard.mcs.yml1.6 KB
- 参考文档copilot-studio/behaviors/aibast_hedis-status.mcs.yml1.3 KB
- 参考文档copilot-studio/behaviors/aibast_monitoring-plan.mcs.yml1.2 KB
- 参考文档copilot-studio/behaviors/aibast_outreach-strategy.mcs.yml1.2 KB
- 参考文档copilot-studio/behaviors/aibast_risk-stratification.mcs.yml1.2 KB
- 参考文档copilot-studio/behaviors/aibast_top-gaps.mcs.yml1.1 KB
- 参考文档copilot-studio/capabilities/knowledge/files/aibast_care-gap-closure-review-rules.md9.8 KB
- 参考文档copilot-studio/capabilities/knowledge/files/aibast_care-gap-closure-review-rules.md.mcs.yml182 B
- 参考文档copilot-studio/capabilities/knowledge/files/aibast_care-gap-closure-synthetic-records.md7.3 KB
- 参考文档copilot-studio/capabilities/knowledge/files/aibast_care-gap-closure-synthetic-records.md.mcs.yml192 B
- 参考文档copilot-studio/settings.mcs.yml4.8 KB
- 参考文档deployment.json4.4 KB
- 参考文档EASY-MODE-COPILOT-CHAT.md223 B
- 参考文档EASY-MODE-PERSONLESS.md223 B
- 参考文档EASY-MODE.md2.6 KB
- 参考文档evals/copilot-studio-preview-evidence.json3.9 KB
- 参考文档evals/dataverse-draft-evidence.json1.6 KB
- 参考文档evals/history/2026-09-10-upstream/GLOBAL-INSTRUCTIONS.staging.md3.7 KB
- 参考文档evals/history/2026-09-10-upstream/GLOBAL-INSTRUCTIONS.upstream.md3.4 KB
- 参考文档evals/history/2026-09-10-upstream/index.json2.4 KB
- 参考文档evals/history/2026-09-14-staging-sync/GLOBAL-INSTRUCTIONS.md4.1 KB
- 参考文档evals/history/2026-09-14-staging-sync/index.json999 B
- 参考文档evals/manual-build-evidence.json6.1 KB
- 参考文档evals/onepager-map.json3.1 KB
- 参考文档evals/source-audit.json4.6 KB
- 参考文档evals/transcripts.json23.8 KB
- 参考文档evals/visual-checkpoints.json38.8 KB
- 参考文档evidence-report.html36.1 KB
- 参考文档export-manifest.json68.4 KB
- 资产文件exports/care-gap-closure-copilot-studio-solution.zip25.7 KB
- 参考文档exports/care-gap-closure-deployment-settings.json203 B
- 参考文档exports/care-gap-closure-solution-export.json1.0 KB
- 参考文档exports/README.md1.5 KB
- 参考文档field-guide.html38.7 KB
- 参考文档FIELD-GUIDE.md14.2 KB
- 参考文档FLOW.md1.0 KB
- 参考文档manual-tutorial.html110.9 KB
- 参考文档manual/GLOBAL-INSTRUCTIONS.md3.9 KB
- 参考文档manual/knowledge/aibast_care-gap-closure-review-rules.md9.8 KB
- 参考文档manual/knowledge/aibast_care-gap-closure-synthetic-records.md7.3 KB
- 参考文档quest.html174.3 KB
- 参考文档README.md7.3 KB
- 参考文档references/capabilities.md1.9 KB
- 参考文档references/non-hero-scenarios.md3.1 KB
- 资产文件screenshots/assisted/01-review-build.jpg125.1 KB
- 资产文件screenshots/assisted/02-cg-01.jpg119.5 KB
- 资产文件screenshots/assisted/03-cg-02.jpg192.1 KB
- 资产文件screenshots/assisted/04-cg-03.jpg136.9 KB
- 资产文件screenshots/assisted/05-cg-04.jpg153.0 KB
- 资产文件screenshots/assisted/06-cg-05.jpg134.9 KB
- 资产文件screenshots/assisted/07-cg-06.jpg174.3 KB
- 资产文件screenshots/assisted/08-cg-07.jpg167.1 KB
- 资产文件screenshots/assisted/09-cg-08.jpg234.1 KB
- 资产文件screenshots/assisted/10-cg-09.jpg195.4 KB
- 资产文件screenshots/assisted/11-cg-10.jpg164.4 KB
- 资产文件screenshots/assisted/12-confirm-draft.jpg29.9 KB
- 资产文件screenshots/assisted/annotated/01-review-build.png115.5 KB
- 资产文件screenshots/assisted/annotated/02-cg-01.png106.3 KB
- 资产文件screenshots/assisted/annotated/03-cg-02.png163.4 KB
- 资产文件screenshots/assisted/annotated/04-cg-03.png117.2 KB
- 资产文件screenshots/assisted/annotated/05-cg-04.png127.1 KB
- 资产文件screenshots/assisted/annotated/06-cg-05.png120.8 KB
- 资产文件screenshots/assisted/annotated/07-cg-06.png147.7 KB
- 资产文件screenshots/assisted/annotated/08-cg-07.png140.1 KB
- 资产文件screenshots/assisted/annotated/09-cg-08.png196.8 KB
- 资产文件screenshots/assisted/annotated/10-cg-09.png168.2 KB
- 资产文件screenshots/assisted/annotated/11-cg-10.png142.5 KB
- 资产文件screenshots/assisted/annotated/12-confirm-draft.png28.1 KB
- 参考文档screenshots/assisted/browserfilm.json2.2 KB
- 资产文件screenshots/assisted/copilot-assisted-contact-sheet.jpg323.9 KB
- 资产文件screenshots/assisted/copilot-assisted-walkthrough.gif1.8 MB
- 参考文档screenshots/assisted/README.md468 B
- 资产文件screenshots/manual/01-create-blank-agent.jpg57.7 KB
- 资产文件screenshots/manual/02-name-agent.jpg58.9 KB
- 资产文件screenshots/manual/03-enter-instructions.jpg117.7 KB
- 资产文件screenshots/manual/04-save-instructions.jpg118.6 KB
- 资产文件screenshots/manual/05-remove-web-search.jpg117.7 KB
- 资产文件screenshots/manual/06-add-aibast-care-gap-closure-review-rules.jpg119.0 KB
- 资产文件screenshots/manual/07-add-aibast-care-gap-closure-synthetic-records.jpg121.9 KB
- 资产文件screenshots/manual/08-add-aibast-campaign-projection-09.jpg125.3 KB
- 资产文件screenshots/manual/09-add-aibast-cohort-review-02.jpg127.7 KB
- 资产文件screenshots/manual/10-add-aibast-gap-analysis-01.jpg129.9 KB
- 资产文件screenshots/manual/11-add-aibast-hedis-status-05.jpg131.2 KB
- 资产文件screenshots/manual/12-add-aibast-monitoring-plan-10.jpg132.5 KB
- 资产文件screenshots/manual/13-add-aibast-outreach-draft-03.jpg133.5 KB
- 资产文件screenshots/manual/14-add-aibast-outreach-strategy-08.jpg132.8 KB
- 资产文件screenshots/manual/15-add-aibast-quality-dashboard-04.jpg133.0 KB
- 资产文件screenshots/manual/16-add-aibast-risk-stratification-07.jpg133.4 KB
- 资产文件screenshots/manual/17-add-aibast-top-gaps-06.jpg133.0 KB
- 资产文件screenshots/manual/18-review-inventory.jpg133.0 KB
- 资产文件screenshots/manual/19-review-skills.jpg123.4 KB
- 资产文件screenshots/manual/20-review-skills-more.jpg126.0 KB
- 资产文件screenshots/manual/21-open-preview.jpg31.8 KB
- 资产文件screenshots/manual/22-cg-01.jpg117.8 KB
- 资产文件screenshots/manual/23-cg-02.jpg130.8 KB
- 资产文件screenshots/manual/24-cg-03.jpg114.8 KB
- 资产文件screenshots/manual/25-cg-04.jpg164.5 KB
- 资产文件screenshots/manual/26-cg-05.jpg107.2 KB
- 资产文件screenshots/manual/27-cg-06.jpg103.1 KB
- 资产文件screenshots/manual/28-cg-07.jpg106.2 KB
- 资产文件screenshots/manual/29-cg-08.jpg113.0 KB
- 资产文件screenshots/manual/30-cg-09.jpg114.1 KB
- 资产文件screenshots/manual/31-cg-10.jpg114.8 KB
- 资产文件screenshots/manual/32-confirm-draft.jpg28.4 KB
- 资产文件screenshots/manual/annotated/01-create-blank-agent.png62.7 KB
- 资产文件screenshots/manual/annotated/02-name-agent.png62.9 KB
- 资产文件screenshots/manual/annotated/03-enter-instructions.png117.1 KB
- 资产文件screenshots/manual/annotated/04-save-instructions.png119.3 KB
- 资产文件screenshots/manual/annotated/05-remove-web-search.png118.8 KB
- 资产文件screenshots/manual/annotated/06-add-aibast-care-gap-closure-review-rules.png120.2 KB
- 资产文件screenshots/manual/annotated/07-add-aibast-care-gap-closure-synthetic-records.png122.9 KB
- 资产文件screenshots/manual/annotated/08-add-aibast-campaign-projection-09.png124.7 KB
- 资产文件screenshots/manual/annotated/09-add-aibast-cohort-review-02.png126.5 KB
- 资产文件screenshots/manual/annotated/10-add-aibast-gap-analysis-01.png128.4 KB
- 资产文件screenshots/manual/annotated/11-add-aibast-hedis-status-05.png128.8 KB
- 资产文件screenshots/manual/annotated/12-add-aibast-monitoring-plan-10.png130.3 KB
- 资产文件screenshots/manual/annotated/13-add-aibast-outreach-draft-03.png131.3 KB
- 资产文件screenshots/manual/annotated/14-add-aibast-outreach-strategy-08.png130.8 KB
- 资产文件screenshots/manual/annotated/15-add-aibast-quality-dashboard-04.png131.2 KB
- 资产文件screenshots/manual/annotated/16-add-aibast-risk-stratification-07.png131.4 KB
- 资产文件screenshots/manual/annotated/17-add-aibast-top-gaps-06.png130.4 KB
- 资产文件screenshots/manual/annotated/18-review-inventory.png138.0 KB
- 资产文件screenshots/manual/annotated/19-review-skills.png136.2 KB
- 资产文件screenshots/manual/annotated/20-review-skills-more.png141.2 KB
- 资产文件screenshots/manual/annotated/21-open-preview.png31.3 KB
- 资产文件screenshots/manual/annotated/22-cg-01.png117.4 KB
- 资产文件screenshots/manual/annotated/23-cg-02.png131.7 KB
- 资产文件screenshots/manual/annotated/24-cg-03.png119.0 KB
- 资产文件screenshots/manual/annotated/25-cg-04.png165.0 KB
- 资产文件screenshots/manual/annotated/26-cg-05.png110.6 KB
- 资产文件screenshots/manual/annotated/27-cg-06.png103.6 KB
- 资产文件screenshots/manual/annotated/28-cg-07.png108.8 KB
- 资产文件screenshots/manual/annotated/29-cg-08.png118.9 KB
- 资产文件screenshots/manual/annotated/30-cg-09.png115.9 KB
- 资产文件screenshots/manual/annotated/31-cg-10.png121.0 KB
- 资产文件screenshots/manual/annotated/32-confirm-draft.png29.0 KB
- 参考文档screenshots/manual/browserfilm.json5.4 KB
- 资产文件screenshots/manual/manual-build-contact-sheet.jpg1.1 MB
- 资产文件screenshots/manual/manual-build-walkthrough.gif7.0 MB
- 参考文档screenshots/manual/README.md461 B
- 参考文档screenshots/README.md522 B
03 SKILL.md 正文
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-textanalytics
Environment Variables
AZURE_LANGUAGE_ENDPOINT=https://<resource>.cognitiveservices.azure.com # Required for all auth methods
AZURE_TOKEN_CREDENTIALS=prod # Required only if DefaultAzureCredential is used in production
AZURE_LANGUAGE_KEY=<your-api-key> # Only required for the legacy API-key auth path below
Authentication & Lifecycle
? Two rules apply to every code sample below:
- Prefer
DefaultAzureCredential. It works locally (Azure CLI / VS Code / Developer CLI) and in Azure (managed identity, workload identity) with no code change. Avoid connection strings, account/API keys — they bypass Entra audit and rotation.
- Local dev:
DefaultAzureCredentialworks as-is.- Production: set
AZURE_TOKEN_CREDENTIALS=prod(orAZURE_TOKEN_CREDENTIALS=<specific_credential>) to constrain the credential chain to production-safe credentials.- Wrap every client in a context manager so HTTP transports, sockets, and token caches are released deterministically:
- Sync:
with <Client>(...) as client:- Async:
async with <Client>(...) as client:andasync with DefaultAzureCredential() as credential:(fromazure.identity.aio)Snippets may abbreviate this setup, but production code should always follow both rules.
import os
from azure.identity import DefaultAzureCredential, ManagedIdentityCredential
from azure.ai.textanalytics import TextAnalyticsClient
# Local dev: DefaultAzureCredential. Production: set AZURE_TOKEN_CREDENTIALS=prod or AZURE_TOKEN_CREDENTIALS=<specific_credential>
credential = DefaultAzureCredential(require_envvar=True)
# Or use a specific credential directly in production:
# See https://learn.microsoft.com/python/api/overview/azure/identity-readme?view=azure-python#credential-classes
# credential = ManagedIdentityCredential()
with TextAnalyticsClient(
endpoint=os.environ["AZURE_LANGUAGE_ENDPOINT"],
credential=credential,
) as client:
languages = client.detect_language(["Hello, world!"])
Legacy: API Key (existing keyed deployments)
New code should use DefaultAzureCredential above. Use AzureKeyCredential only if you have an existing keyed deployment that hasn't been migrated to Entra ID yet — for example, regulated environments still completing their Entra rollout.
import os
from azure.core.credentials import AzureKeyCredential
from azure.ai.textanalytics import TextAnalyticsClient
with TextAnalyticsClient(
endpoint=os.environ["AZURE_LANGUAGE_ENDPOINT"],
credential=AzureKeyCredential(os.environ["AZURE_LANGUAGE_KEY"]),
) as client:
languages = client.detect_language(["Hello, world!"])
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 john@example.com"]
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: {entity.text} ({entity.category})")
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 DefaultAzureCredential() as credential:
async with TextAnalyticsClient(
endpoint=endpoint,
credential=credential
) 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
- Pick sync OR async and stay consistent. Do not mix
azure.ai.textanalyticssync clients withazure.ai.textanalytics.aioasync clients in the same call path. Choose one mode per module. - Always use context managers for clients and async credentials. Wrap every client in
with TextAnalyticsClient(...) as client:(sync) orasync with TextAnalyticsClient(...) as client:(async). For asyncDefaultAzureCredentialfromazure.identity.aio, also useasync with credential:so tokens and transports are cleaned up. - Use batch operations for multiple documents (up to 10 per request)
- Enable opinion mining for detailed aspect-based sentiment
- Use async client for high-throughput scenarios
- Handle document errors — results list may contain errors for some docs
- Specify language when known to improve accuracy
Reference Files
| File | Contents |
|---|---|
| references/capabilities.md | Additional non-hero capabilities, operation-group coverage, and production checklists. |
| references/non-hero-scenarios.md | Dedicated non-hero examples for secondary/advanced scenarios. |
04 同仓库更多 Skills
azure-advisor-cost-optimization
Analyze Azure Advisor Cost/IdleResources findings and prevalidate deletion safety, including Service Groups. WHEN: "find unused Azure resources", "what resources am I paying for but no longer using", "idle-resource savings", "historical idle-resource savings", "are these idle resources safe to delete". Generic Cost, other subcategories, and cross-category requests use azure-advisor.
Azure 技能创建与更新指南
skill-creator
面向使用 Azure SDK 和 Microsoft Foundry 服务的 AI 编码智能体,指导其创建高效技能的指南。在创建新技能或更新现有技能时使用。
AI 播客音频生成
podcast-generation
通过 WebSocket 使用 Azure OpenAI 的 GPT Realtime Mini 模型生成 AI 驱动的播客式音频叙述。当构建文本转语音功能、音频叙述生成、根据内容制作播客,或集成 Azure OpenAI Realtime API 以获得真实音频输出时使用。涵盖从 React 前端到 Python FastAPI 后端及 WebSocket 流式传输的全栈实现。
Microsoft 技术文档查询
microsoft-docs
通过查询官方文档来理解 Microsoft 技术。当用户询问某项技术的工作原理、想要教程、需要任何 Microsoft 技术(Azure、.NET、M365、Windows、Power Platform 等)的配置选项、限制、配额或最佳实践时使用——即使他们没有提到"文档"。如果问题是为了理解概念而非编写代码,那么这就是合适的技能。
MCP 服务器构建
mcp-builder
用于创建高质量 MCP(Model Context Protocol)服务器的指南,使大语言模型能够通过设计完善的工具与外部服务交互。当构建用于集成外部 API 或服务的 MCP 服务器时使用,无论采用 Python(FastMCP)、Node/TypeScript(MCP SDK),还是 C#/.NET(Microsoft MCP SDK)。
KQL 查询编写与调试
kql
KQL 语言专业能力,用于编写正确且高效的 Kusto Query Language 查询。涵盖语法陷阱、join 模式、dynamic 类型、datetime 陷阱、regex 模式、序列化、内存管理、结果集规模控制,以及高级函数(geo、vector、graph)。在编写、调试或审查 KQL 查询时均使用本技能——即使是简单查询——因为陷阱章节可防止最常见的错误,避免浪费工具调用并引发代价高昂的连锁重试。触发条件:KQL、Kusto、ADX、Azure Data Explorer、Fabric Real-Time Intelligence、EventHouse、Log Analytics、日志分析、数据探索、时间序列、异常检测、summarize、where 子句、join、extend、project、let 语句、parse 运算符、extract 函数,以及任何提及管道式查询语法的情形。