An open API service indexing awesome lists of open source software.

https://github.com/learning-zone/azure-ai-basics

Artificial Intelligence and Machine Learning Basics
https://github.com/learning-zone/azure-ai-basics

artificial-intelligence azure-ai github-copilot machine-learning

Last synced: 6 days ago
JSON representation

Artificial Intelligence and Machine Learning Basics

Awesome Lists containing this project

README

          

# Microsoft Azure AI Basics

> *Click ★ if you like the project. Your contributions are heartily ♡ welcome.*


## Related Topics

* *[AI and ML Basics](ai-and-ml-basics)*
* *[Mathematics for AI](mathematics-for-ai.md)*
* *[Python Basics](https://github.com/learning-zone/python-basics)*
* *[GitHub Copilot](github-copilot.md)*


## Table of Contents

* **Foundations**
* [Getting Started](#-1-getting-started)
* [Getting Started with C# and .NET SDK](#q-how-do-you-get-started-with-azure-ai-using-c-and-the-net-sdk)
* [Azure OpenAI Service in C#](#q-how-do-you-call-azure-openai-service-from-a-c-application)
* [Azure AI Vision & Document Intelligence in C#](#q-how-do-you-use-azure-ai-vision-and-document-intelligence-in-c)
* [Azure AI Speech Service in C#](#q-how-do-you-integrate-azure-ai-speech-service-in-a-c-application)
* **Enterprise AI & Development Platforms**
* [Azure AI Foundry Overview](#-2-azure-ai-foundry-overview)
* [Azure AI Foundry with C# .NET SDK](#q-how-do-you-interact-with-azure-ai-foundry-using-the-c-net-sdk)
* [Azure OpenAI Service](#-3-azure-openai-service)
* [Function Calling & Embeddings in C#](#q-how-do-you-use-function-calling-and-generate-embeddings-with-azure-openai-in-c)
* [Foundry Tools & Catalogs](#-4-foundry-tools-and-catalogs)
* [Model Catalog & Deployment in C#](#q-how-do-you-browse-and-deploy-models-from-the-azure-ai-foundry-model-catalog-using-c)
* [Azure Machine Learning (AML)](#-5-azure-machine-learning-aml)
* [AML Workspace & Jobs in C#](#q-how-do-you-manage-azure-machine-learning-workspaces-and-submit-training-jobs-from-c)
* **Vision & Multimodal**
* [Azure Vision Services](#-6-azure-vision-services)
* [Image Analysis & OCR in C#](#q-how-do-you-perform-image-analysis-and-ocr-using-azure-ai-vision-in-c)
* [Azure Custom Vision](#-7-azure-custom-vision)
* [Custom Vision Training & Prediction in C#](#q-how-do-you-train-and-call-an-azure-custom-vision-model-from-c)
* [Azure Face API](#-8-azure-face-api)
* [Face Detection & Verification in C#](#q-how-do-you-detect-faces-and-check-liveness-using-the-azure-face-api-in-c)
* [Azure AI Document Intelligence](#-9-azure-ai-document-intelligence)
* [Document Extraction in C#](#q-how-do-you-extract-structured-data-from-documents-using-azure-document-intelligence-in-c)
* **Language & Conversational AI**
* [Azure AI Language](#-10-azure-ai-language)
* [Azure AI Language NLP in C#](#q-how-do-you-use-azure-ai-language-service-for-nlp-tasks-in-c)
* [Azure AI Translator](#-11-azure-ai-translator)
* [Text Translation & Language Detection in C#](#q-how-do-you-translate-text-and-detect-languages-using-azure-translator-in-c)
* [Azure AI Speech](#-12-azure-ai-speech)
* [Speech-to-Text, TTS & Translation in C#](#q-how-do-you-implement-real-time-speech-to-text-tts-and-speech-translation-in-c)
* [Microsoft Copilot Studio & Agents SDK](#-13-microsoft-copilot-studio-and-agents-sdk)
* [AI Agents SDK & Copilot Studio in C#](#q-how-do-you-build-an-ai-agent-with-the-azure-ai-agents-sdk-and-integrate-it-with-copilot-studio-using-c)
* **Search & Knowledge Engineering**
* [Azure AI Search (formerly Cognitive Search)](#-14-azure-ai-search-formerly-cognitive-search)
* [Azure AI Search full-text, filtered & semantic in C#](#q-how-do-you-create-a-search-index-and-run-full-text-filtered-and-semantic-queries-with-azure-ai-search-in-c)
* [Azure Knowledge Mining](#-15-azure-knowledge-mining)
* [AI Enrichment Pipeline with Knowledge Mining in C#](#q-how-do-you-build-an-ai-enrichment-pipeline-with-azure-knowledge-mining-in-c)
* [Vector Search & Embedding Spaces](#-16-azure-openai-embeddings--vector-search)
* [Vector Search & RAG pipeline in C#](#q-how-do-you-implement-vector-search-and-a-rag-pipeline-using-azure-ai-search-and-azure-openai-in-c)
* **Machine Learning & MLOps**
* [Automated ML (AutoML)](#-17-automated-ml-automl)
* [AutoML Forecasting Job in C#](#q-how-do-you-run-an-automl-job-in-azure-machine-learning-using-c)
* [Azure ML Designer](#-18-azure-ml-designer)
* [Trigger ML Designer Pipeline in C#](#q-how-do-you-trigger-and-monitor-an-azure-ml-designer-pipeline-from-c)
* [Azure ML Pipelines](#-19-azure-ml-pipelines)
* [Multi-step ML Pipeline in C#](#q-how-do-you-build-and-run-a-multi-step-azure-ml-pipeline-from-c)
* [Model Training and Hyperparameter Tuning](#-20-model-training-and-hyperparameter-tuning)
* [Hyperparameter Sweep Job in C#](#q-how-do-you-run-a-hyperparameter-sweep-job-in-azure-ml-using-c)
* [Model Deployment and Endpoints](#-21-model-deployment-and-endpoints)
* [Managed Online Endpoint & Scoring in C#](#q-how-do-you-create-a-managed-online-endpoint-and-invoke-it-from-c)
* [MLOps on Azure](#-22-mlops-on-azure)
* [Full MLOps CI/CD Pipeline in C#](#q-how-do-you-implement-an-mlops-cicd-pipeline-for-azure-ml-entirely-from-c)
* **Generative AI & Agentic Orchestration**
* [Prompt Engineering on Azure OpenAI](#-23-prompt-engineering-on-azure-openai)
* [Advanced Prompt Engineering in C#](#q-how-do-you-apply-prompt-engineering-techniques-with-azure-openai-in-c)
* [Retrieval-Augmented Generation (RAG)](#-24-retrieval-augmented-generation-rag)
* [Production RAG Pipeline in C#](#q-how-do-you-build-a-production-ready-rag-pipeline-with-azure-ai-search-and-azure-openai-in-c)
* [Fine-Tuning Large Language Models](#-25-fine-tuning-large-language-models)
* [Fine-Tune & Deploy OpenAI Model in C#](#q-how-do-you-fine-tune-an-azure-openai-model-and-deploy-it-using-c)
* [Azure AI Agents & Function Calling](#-26-azure-ai-agents-and-function-calling)
* [Stateful AI Agent with Function Calling in C#](#q-how-do-you-build-a-stateful-ai-agent-with-function-calling-and-file-search-using-the-azure-ai-agents-sdk-in-c)
* **Data Engineering & Infrastructure**
* [Azure Data Factory for AI Pipelines](#-27-azure-data-factory-for-ai-pipelines)
* [ADF Pipeline Orchestration for AI in C#](#q-how-do-you-orchestrate-an-azure-data-factory-pipeline-for-ai-data-ingestion-using-c)
* [Azure Databricks and Spark ML](#-28-azure-databricks-and-spark-ml)
* [Trigger Databricks ML Jobs from C#](#q-how-do-you-trigger-and-monitor-azure-databricks-notebook-jobs-for-ml-workloads-from-c)
* [Azure Synapse & Fabric Integration](#-29-azure-synapse-and-fabric-integration)
* [Synapse AI Pipelines & Spark Jobs in C#](#q-how-do-you-use-azure-synapse-analytics-to-orchestrate-ai-pipelines-and-invoke-azure-ml-models-from-c)
* [Azure AI Infrastructure (GPU Clusters, ND-Series)](#-30-azure-ai-infrastructure-gpu-clusters-nd-series)
* [GPU Clusters & Distributed Training in C#](#q-how-do-you-provision-gpu-compute-clusters-and-submit-distributed-training-jobs-on-azure-ai-infrastructure-using-c)
* **Responsible AI & Safety**
* [Azure Responsible AI Principles](#-31-azure-responsible-ai-principles)
* [Responsible AI Checks & Model Card in C#](#q-how-do-you-implement-responsible-ai-checks-and-generate-a-rai-dashboard-report-using-c)
* [Fairness, Interpretability, and Explainability](#-32-fairness-interpretability-and-explainability)
* [Fairness Metrics & SHAP Explainability in C#](#q-how-do-you-assess-model-fairness-and-generate-shap-explainability-reports-using-c)
* [Azure AI Content Safety](#-33-azure-ai-content-safety)
* [Content Moderation & Prompt Shield in C#](#q-how-do-you-moderate-ai-generated-content-and-detect-prompt-injection-using-azure-ai-content-safety-in-c)
* [Differential Privacy and Confidential AI](#-34-differential-privacy-and-confidential-ai)
* [Differential Privacy for ML Training in C#](#q-how-do-you-apply-differential-privacy-to-ml-model-training-and-protect-sensitive-data-in-azure-ai-using-c)
* **Security & Governance**
* [Azure AI Security Best Practices](#-35-azure-ai-security-best-practices)
* [OWASP LLM Top 10 hardening in C#](#q-how-do-you-harden-an-azure-ai-deployment-against-the-owasp-llm-top-10-risks-using-c)
* [Managed Identity and RBAC for AI Services](#-36-managed-identity-and-rbac-for-ai-services)
* [Managed Identity & RBAC role assignments in C#](#q-how-do-you-configure-managed-identity-and-rbac-to-access-azure-ai-services-securely-from-c)
* [Azure Policy and AI Compliance](#-37-azure-policy-and-ai-compliance)
* [Azure Policy compliance reporting in C#](#q-how-do-you-enforce-and-audit-azure-policy-compliance-for-ai-resources-using-c)
* **Monitoring & Cost Management**
* [Monitoring AI Models with Azure Monitor](#-38-monitoring-ai-models-with-azure-monitor)
* [Monitor endpoints & detect drift in C#](#q-how-do-you-monitor-azure-ai-model-endpoints-and-detect-data-drift-using-azure-monitor-in-c)
* [Azure Cost Management for AI Workloads](#-39-azure-cost-management-for-ai-workloads)
* [Query & optimise AI workload costs in C#](#q-how-do-you-query-and-optimise-azure-ai-workload-costs-using-c)


## # 1. GETTING STARTED


## Q. What is Azure AI and what services does it include?

**Azure AI** is Microsoft's cloud-based suite of artificial intelligence and machine learning services built on the Azure platform. It provides pre-built AI models, customizable tools, and infrastructure to build intelligent applications without requiring deep ML expertise.

```mermaid
graph TD
A[Azure AI Platform] --> B[Azure AI Services\nVision · Speech · Language · Decision]
A --> C[Azure OpenAI Service\nGPT-4o · DALL-E · Embeddings]
A --> D[Azure Machine Learning\nTrain · Deploy · Monitor]
A --> E[Azure AI Studio\nBuild · Evaluate · Deploy GenAI]
A --> F[Azure AI Search\nVector · Semantic · Hybrid]
B --> G[Applications\nWeb · Mobile · Bot]
C --> G
D --> G
E --> G
F --> G
```

**Core pillars of Azure AI:**

| Pillar | Description |
|--------|-------------|
| **Azure AI Services** | Pre-built APIs for vision, speech, language, and decision tasks (formerly Cognitive Services) |
| **Azure OpenAI Service** | Access to GPT-4, DALL-E, Codex, and Embeddings models via Azure |
| **Azure Machine Learning** | End-to-end MLOps platform for training, deploying, and managing models |
| **Azure AI Studio** | Unified portal for building and deploying generative AI applications |
| **Azure AI Search** | Intelligent search with vector, semantic, and hybrid capabilities |

**Typical AI application workflow:**

```
Data Sources → Azure Data Factory → Azure ML / AI Services

Model Training & Evaluation

Azure ML Endpoints / Azure OpenAI

Application (Web/Mobile/Bot)
```

**Getting started — install Azure CLI and ML SDK:**

```bash
# Install Azure CLI
winget install Microsoft.AzureCLI

# Login
az login

# Install Azure ML Python SDK v2
pip install azure-ai-ml azure-identity

# Create a resource group and Azure ML workspace
az group create --name rg-ai-demo --location eastus
az ml workspace create --name my-aml-ws --resource-group rg-ai-demo
```


↥ back to top

## Q. What are the key differences between Azure AI Services, Azure OpenAI, and Azure ML?

| Feature | Azure AI Services | Azure OpenAI Service | Azure ML |
|---------|------------------|---------------------|---------|
| **Purpose** | Pre-built task APIs | Large language models | Custom model training & deployment |
| **Customization** | Limited (Custom Vision, Custom Translator) | Fine-tuning (GPT-3.5/GPT-4) | Full control |
| **Use case** | OCR, speech-to-text, translation | Chat, code gen, summarization | Forecasting, classification, custom DL |
| **Billing** | Per API call | Per token consumed | Compute + storage time |
| **Skill required** | Low (REST/SDK) | Low–Medium | Medium–High |


↥ back to top

## Q. How do you get started with Azure AI using C# and the .NET SDK?

**Use case:** Build an enterprise .NET application that calls Azure AI Services for text analytics (sentiment analysis, named entity recognition) using the official `Azure.AI.TextAnalytics` NuGet package.

**Install the NuGet packages:**

```bash
dotnet add package Azure.AI.TextAnalytics
dotnet add package Azure.Identity
```

**Appsettings configuration (`appsettings.json`):**

```json
{
"AzureAI": {
"Endpoint": "https://.cognitiveservices.azure.com/",
"Key": ""
}
}
```

**Sentiment analysis and NER with C#:**

```csharp
using Azure;
using Azure.AI.TextAnalytics;
using Microsoft.Extensions.Configuration;

// Load configuration
var config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables()
.Build();

string endpoint = config["AzureAI:Endpoint"]!;
string key = config["AzureAI:Key"]!;

var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(key));

// 1. Sentiment Analysis
var documents = new List
{
"Azure AI Services make building intelligent apps straightforward.",
"The deployment process was frustrating and took too long."
};

AnalyzeSentimentResultCollection sentimentResults = await client.AnalyzeSentimentBatchAsync(documents);
foreach (AnalyzeSentimentResult result in sentimentResults)
{
Console.WriteLine($"Sentiment : {result.DocumentSentiment.Sentiment}");
Console.WriteLine($" Positive: {result.DocumentSentiment.ConfidenceScores.Positive:P2}");
Console.WriteLine($" Negative: {result.DocumentSentiment.ConfidenceScores.Negative:P2}");
}

// 2. Named Entity Recognition
RecognizeEntitiesResultCollection nerResults = await client.RecognizeEntitiesBatchAsync(documents);
foreach (RecognizeEntitiesResult result in nerResults)
{
foreach (CategorizedEntity entity in result.Entities)
{
Console.WriteLine($"Entity : {entity.Text,-30} | Category: {entity.Category,-20} | Confidence: {entity.ConfidenceScore:P0}");
}
}
```

**Key NuGet packages for Azure AI in .NET:**

| Package | Purpose |
|---------|---------|
| `Azure.AI.TextAnalytics` | Sentiment, NER, PII, key phrases, summarization |
| `Azure.AI.Vision.ImageAnalysis` | Image captioning, OCR, object detection |
| `Azure.AI.OpenAI` | Azure OpenAI chat completions, embeddings |
| `Azure.AI.DocumentIntelligence` | Invoice, receipt, form extraction |
| `Azure.AI.Translation.Text` | Text translation (100+ languages) |
| `Azure.AI.ContentSafety` | Harmful content moderation |
| `Microsoft.CognitiveServices.Speech` | Speech-to-text, text-to-speech |


↥ back to top

## Q. How do you call Azure OpenAI Service from a C# application?

**Use case:** Build a C# console or ASP.NET Core application that uses GPT-4o for chat completions, such as a customer support assistant or a code explanation tool.

**Install the NuGet package:**

```bash
dotnet add package Azure.AI.OpenAI
```

**Chat completion with streaming in C#:**

```csharp
using Azure;
using Azure.AI.OpenAI;
using OpenAI.Chat;

var client = new AzureOpenAIClient(
new Uri("https://.openai.azure.com/"),
new AzureKeyCredential("")
);

ChatClient chatClient = client.GetChatClient("gpt-4o"); // deployment name

// Basic chat completion
ChatCompletion completion = await chatClient.CompleteChatAsync(
[
new SystemChatMessage("You are a helpful Azure expert assistant."),
new UserChatMessage("Explain the difference between Azure AI Services and Azure OpenAI in 3 bullet points.")
]);

Console.WriteLine(completion.Content[0].Text);

// Streaming response
Console.WriteLine("--- Streaming response ---");
await foreach (StreamingChatCompletionUpdate update in chatClient.CompleteChatStreamingAsync(
[
new SystemChatMessage("You are a concise C# code assistant."),
new UserChatMessage("Show a minimal example of dependency injection in ASP.NET Core.")
]))
{
foreach (ChatMessageContentPart part in update.ContentUpdate)
{
Console.Write(part.Text);
}
}
```

**Dependency-injected Azure OpenAI in ASP.NET Core:**

```csharp
// Program.cs
using Azure;
using Azure.AI.OpenAI;

var builder = WebApplication.CreateBuilder(args);

// Register AzureOpenAIClient as a singleton
builder.Services.AddSingleton(_ =>
new AzureOpenAIClient(
new Uri(builder.Configuration["AzureOpenAI:Endpoint"]!),
new AzureKeyCredential(builder.Configuration["AzureOpenAI:Key"]!)
));

builder.Services.AddScoped();
builder.Services.AddControllers();

var app = builder.Build();
app.MapControllers();
app.Run();

// ChatService.cs
public class ChatService : IChatService
{
private readonly ChatClient _chatClient;

public ChatService(AzureOpenAIClient openAiClient)
{
_chatClient = openAiClient.GetChatClient("gpt-4o");
}

public async Task AskAsync(string userMessage, string systemPrompt = "You are a helpful assistant.")
{
ChatCompletion result = await _chatClient.CompleteChatAsync(
[
new SystemChatMessage(systemPrompt),
new UserChatMessage(userMessage)
]);
return result.Content[0].Text;
}
}
```


↥ back to top

## Q. How do you use Azure AI Vision and Document Intelligence in C#?

**Use case:** An automated document processing pipeline in .NET that extracts text from scanned invoices and analyses images for objects and captions.

**Image analysis with Azure AI Vision (C#):**

```csharp
using Azure;
using Azure.AI.Vision.ImageAnalysis;

var client = new ImageAnalysisClient(
new Uri("https://.cognitiveservices.azure.com/"),
new AzureKeyCredential("")
);

// Analyse image from URL
ImageAnalysisResult result = await client.AnalyzeAsync(
new Uri("https://example.com/factory-floor.jpg"),
VisualFeatures.Caption | VisualFeatures.Objects | VisualFeatures.Read,
new ImageAnalysisOptions { Language = "en" }
);

// Caption
Console.WriteLine($"Caption : {result.Caption.Text} (confidence: {result.Caption.Confidence:P1})");

// Detected objects
foreach (DetectedObject obj in result.Objects.Values)
{
Console.WriteLine($"Object : {obj.Tags[0].Name,-20} at ({obj.BoundingBox.X},{obj.BoundingBox.Y})");
}

// OCR — printed/handwritten text
foreach (DetectedTextBlock block in result.Read.Blocks)
{
foreach (DetectedTextLine line in block.Lines)
{
Console.WriteLine($"OCR text: {line.Text}");
}
}
```

**Invoice extraction with Azure Document Intelligence (C#):**

```csharp
using Azure;
using Azure.AI.DocumentIntelligence;

var client = new DocumentIntelligenceClient(
new Uri("https://.cognitiveservices.azure.com/"),
new AzureKeyCredential("")
);

// Analyse a PDF invoice from URL
Operation operation = await client.AnalyzeDocumentAsync(
WaitUntil.Completed,
"prebuilt-invoice",
new AnalyzeDocumentContent
{
UrlSource = new Uri("https://example.com/invoice.pdf")
});

AnalyzeResult result = operation.Value;

foreach (AnalyzedDocument invoice in result.Documents)
{
if (invoice.Fields.TryGetValue("VendorName", out DocumentField? vendor))
Console.WriteLine($"Vendor : {vendor.ValueString}");

if (invoice.Fields.TryGetValue("InvoiceTotal", out DocumentField? total))
Console.WriteLine($"Total : {total.ValueCurrency?.Amount} {total.ValueCurrency?.CurrencyCode}");

if (invoice.Fields.TryGetValue("InvoiceDate", out DocumentField? date))
Console.WriteLine($"Date : {date.ValueDate}");

if (invoice.Fields.TryGetValue("InvoiceId", out DocumentField? invoiceId))
Console.WriteLine($"Invoice#: {invoiceId.ValueString}");
}
```

**Common use cases for Document Intelligence in .NET:**

| Scenario | Model | Industry |
|----------|-------|---------|
| Accounts payable automation | `prebuilt-invoice` | Finance |
| Expense management | `prebuilt-receipt` | Enterprise |
| Identity verification | `prebuilt-idDocument` | Banking / KYC |
| Contract review | `prebuilt-contract` | Legal |
| Healthcare records | Custom neural model | Healthcare |


↥ back to top

## Q. How do you integrate Azure AI Speech Service in a C# application?

**Use case:** A call centre application that transcribes customer calls in real time and synthesizes responses using neural text-to-speech voices.

**Install the NuGet package:**

```bash
dotnet add package Microsoft.CognitiveServices.Speech
```

**Real-time speech-to-text (C#):**

```csharp
using Microsoft.CognitiveServices.Speech;
using Microsoft.CognitiveServices.Speech.Audio;

var speechConfig = SpeechConfig.FromSubscription("", "eastus");
speechConfig.SpeechRecognitionLanguage = "en-US";

using var audioConfig = AudioConfig.FromDefaultMicrophoneInput();
using var recognizer = new SpeechRecognizer(speechConfig, audioConfig);

// Continuous recognition with event handlers
recognizer.Recognized += (s, e) =>
{
if (e.Result.Reason == ResultReason.RecognizedSpeech)
Console.WriteLine($"Recognised: {e.Result.Text}");
};

recognizer.Canceled += (s, e) =>
{
Console.WriteLine($"Cancelled: {e.Reason} — {e.ErrorDetails}");
};

Console.WriteLine("Listening... Press Enter to stop.");
await recognizer.StartContinuousRecognitionAsync();
Console.ReadLine();
await recognizer.StopContinuousRecognitionAsync();

// Neural Text-to-Speech
var synthConfig = SpeechConfig.FromSubscription("", "eastus");
synthConfig.SpeechSynthesisVoiceName = "en-US-JennyNeural";

using var synthesizer = new SpeechSynthesizer(synthConfig);

string ssml = """



Thank you for calling. How can I assist you today?



""";

SpeechSynthesisResult synthResult = await synthesizer.SpeakSsmlAsync(ssml);

if (synthResult.Reason == ResultReason.SynthesizingAudioCompleted)
Console.WriteLine("Speech synthesised successfully.");
else
Console.WriteLine($"Synthesis failed: {synthResult.Reason}");
```

**Real-world integration — save transcription to Azure Blob Storage:**

```csharp
using Azure.Storage.Blobs;

// After recognition is complete
string transcription = "Full transcribed call text...";
string connectionString = "";

var blobClient = new BlobClient(connectionString, "transcriptions", $"call-{DateTime.UtcNow:yyyyMMdd-HHmmss}.txt");
using var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(transcription));
await blobClient.UploadAsync(stream, overwrite: true);

Console.WriteLine($"Transcription saved: {blobClient.Uri}");
```


↥ back to top

## # 2. AZURE COGNITIVE SERVICES OVERVIEW


## Q. What are Azure AI Services (Cognitive Services) and how are they categorized?

**Azure AI Services** (formerly Azure Cognitive Services) are cloud-hosted REST APIs and SDKs that add AI capabilities to applications without needing ML expertise. As of 2025, they are grouped into five categories:

| Category | Services |
|----------|---------|
| **Vision** | Computer Vision, Custom Vision, Face API, Document Intelligence |
| **Language** | Language Service (NER, sentiment, QA), Translator, Text Analytics |
| **Speech** | Speech-to-Text, Text-to-Speech, Speech Translation, Speaker Recognition |
| **Decision** | Anomaly Detector, Content Moderator, Personalizer |
| **OpenAI** | GPT-4, GPT-4o, Embeddings, DALL-E (via Azure OpenAI Service) |

**Creating a multi-service resource:**

```bash
# Create a single Cognitive Services resource (covers all AI Services)
az cognitiveservices account create \
--name my-ai-services \
--resource-group rg-ai-demo \
--kind CognitiveServices \
--sku S0 \
--location eastus \
--yes

# Retrieve the key and endpoint
az cognitiveservices account keys list \
--name my-ai-services \
--resource-group rg-ai-demo
```

**Calling AI Services with the Python SDK:**

```python
from azure.ai.textanalytics import TextAnalyticsClient
from azure.core.credentials import AzureKeyCredential

endpoint = "https://.cognitiveservices.azure.com/"
key = ""

client = TextAnalyticsClient(endpoint=endpoint, credential=AzureKeyCredential(key))

documents = ["Azure AI Services make building intelligent apps straightforward."]
result = client.analyze_sentiment(documents)

for doc in result:
print(f"Sentiment: {doc.sentiment}, Confidence: {doc.confidence_scores}")
```


↥ back to top

## Q. How do you interact with Azure AI Foundry using the C# .NET SDK?

**Use case:** A DevOps automation tool in .NET that connects to an Azure AI Foundry project, enumerates connections and deployments, and invokes a deployed chat model — enabling programmatic management of AI Foundry assets from enterprise .NET applications.

**Install the NuGet packages:**

```bash
dotnet add package Azure.AI.Projects
dotnet add package Azure.AI.OpenAI
dotnet add package Azure.Identity
```

**Connect to a Foundry project and list deployments:**

```csharp
using Azure.AI.Projects;
using Azure.Identity;
using OpenAI.Chat;

// Connect to an Azure AI Foundry project via DefaultAzureCredential (Managed Identity / Entra ID)
var projectClient = new AIProjectClient(
new Uri("https://.services.ai.azure.com/api/projects/"),
new DefaultAzureCredential());

// List all deployed models in the project
Console.WriteLine("=== Available Deployments ===");
await foreach (var deployment in projectClient.GetDeployments().GetAllAsync())
{
Console.WriteLine($" {deployment.Name,-30} | Model: {deployment.ModelName,-20} | Version: {deployment.ModelVersion}");
}

// List all connections (AI Services, Storage, Search, etc.)
Console.WriteLine("\n=== Project Connections ===");
await foreach (var connection in projectClient.GetConnections().GetAllAsync())
{
Console.WriteLine($" {connection.Name,-30} | Type: {connection.ConnectionType}");
}
```

**Invoke a deployed chat model through the Foundry project:**

```csharp
// Get a ChatClient scoped to a specific deployment — no separate endpoint/key needed
ChatClient chatClient = projectClient.GetChatCompletionsClient(deploymentName: "gpt-4o");

ChatCompletion response = await chatClient.CompleteChatAsync(
[
new SystemChatMessage("You are a helpful Azure AI Foundry expert."),
new UserChatMessage("What are the key benefits of using Azure AI Foundry over managing AI services separately?")
]);

Console.WriteLine($"Response:\n{response.Content[0].Text}");
```

**Azure AI Foundry project resource hierarchy:**

```
AI Foundry Hub (shared infrastructure: networking, storage, monitoring)
└── AI Foundry Project
├── Deployments → GetChatCompletionsClient() / GetEmbeddingsClient()
├── Connections → GetConnections() / GetConnectionAsync()
├── Agents → GetAgentsClient()
├── Evaluations → GetEvaluationsClient()
└── Telemetry → GetTelemetryClient() (OpenTelemetry tracing)
```

**Key NuGet packages for Azure AI Foundry in .NET:**

| Package | Purpose |
|---------|--------|
| `Azure.AI.Projects` | Core Foundry project client (deployments, connections, agents) |
| `Azure.AI.OpenAI` | Chat completions, embeddings, image generation |
| `Azure.AI.Inference` | Serverless inference for catalog models (Mistral, Llama, Cohere) |
| `Azure.Identity` | Managed Identity, Entra ID, DefaultAzureCredential |


↥ back to top

## # 3. AZURE OPENAI SERVICE


## Q. What is Azure OpenAI Service and how does it differ from OpenAI's API?

**Azure OpenAI Service** provides access to OpenAI's models (GPT-4o, GPT-4, GPT-3.5-Turbo, Embeddings, DALL-E, Whisper) via Azure infrastructure with enterprise security, compliance, and regional availability.

```mermaid
graph LR
A[Your Application] -->|Managed Identity / API Key| B[Azure OpenAI Service]
B --> C[GPT-4o]
B --> D[DALL-E 3]
B --> E[Embeddings]
B --> F[Whisper]
B --- G[VNet / Private Endpoint]
B --- H[RBAC / Entra ID]
B --- I[Azure Content Safety]
B --- J[Regional Data Residency]
```

**Key differences from OpenAI API:**

| Feature | OpenAI API | Azure OpenAI Service |
|---------|-----------|---------------------|
| **Data residency** | US-based (mostly) | Regional (EU, US, Asia) |
| **Compliance** | SOC 2 | SOC 2, ISO 27001, HIPAA, FedRAMP |
| **Network isolation** | No VNet support | VNet integration, Private Endpoints |
| **Content filtering** | Default filters | Configurable + Azure Content Safety |
| **Authentication** | API keys | API keys + Managed Identity + Entra ID |
| **SLA** | 99.9% | 99.9% with Azure SLA |
| **Fine-tuning** | GPT-3.5, GPT-4 | GPT-3.5-Turbo, Babbage |

**Calling Azure OpenAI with Python:**

```python
from openai import AzureOpenAI

client = AzureOpenAI(
azure_endpoint="https://.openai.azure.com/",
api_key="",
api_version="2024-05-01-preview"
)

response = client.chat.completions.create(
model="gpt-4o", # deployment name in Azure
messages=[
{"role": "system", "content": "You are a helpful AI assistant."},
{"role": "user", "content": "Explain Azure AI in 3 bullet points."}
],
temperature=0.7,
max_tokens=300
)

print(response.choices[0].message.content)
```

**Available models (2025/2026):**

| Model | Best For |
|-------|---------|
| GPT-4o | Multimodal (text + image), fast |
| GPT-4 Turbo | Long context (128k tokens) |
| GPT-3.5-Turbo | Low-cost chat/completion |
| text-embedding-ada-002 | Vector embeddings |
| text-embedding-3-large | High-accuracy embeddings |
| DALL-E 3 | Image generation |
| Whisper | Speech transcription |


↥ back to top

## Q. How do you use function calling and generate embeddings with Azure OpenAI in C#?

**Use case:** An intelligent product-search assistant that uses GPT-4o function calling to query a live product catalogue and `text-embedding-3-large` to implement semantic similarity ranking inside an ASP.NET Core application.

**Install the NuGet package:**

```bash
dotnet add package Azure.AI.OpenAI
```

**Function calling — agentic loop in C#:**

```csharp
using Azure;
using Azure.AI.OpenAI;
using OpenAI.Chat;
using System.ClientModel;
using System.Text.Json;

var openAiClient = new AzureOpenAIClient(
new Uri("https://.openai.azure.com/"),
new AzureKeyCredential("")
);

ChatClient chatClient = openAiClient.GetChatClient("gpt-4o");

// Define the tool (function) the model can invoke
ChatTool searchProductsTool = ChatTool.CreateFunctionTool(
functionName: "search_products",
functionDescription: "Search the product catalogue by keyword and return matching items.",
functionParameters: BinaryData.FromString("""
{
"type": "object",
"properties": {
"query": { "type": "string", "description": "Search keyword" },
"limit": { "type": "integer", "description": "Max number of results", "default": 5 }
},
"required": ["query"]
}
""")
);

var messages = new List
{
new SystemChatMessage("You are a product assistant. Use the search tool to find products."),
new UserChatMessage("Show me the top 3 wireless keyboards.")
};

var options = new ChatCompletionOptions { Tools = { searchProductsTool } };

// Agentic loop — keep going until the model stops calling tools
while (true)
{
ChatCompletion completion = await chatClient.CompleteChatAsync(messages, options);

if (completion.FinishReason == ChatFinishReason.ToolCalls)
{
messages.Add(new AssistantChatMessage(completion));

foreach (ChatToolCall toolCall in completion.ToolCalls)
{
using JsonDocument args = JsonDocument.Parse(toolCall.FunctionArguments);
string query = args.RootElement.GetProperty("query").GetString()!;

// Simulate a real product database lookup
string result = JsonSerializer.Serialize(new[]
{
new { id = 1, name = "Logitech MX Keys", price = 99.99 },
new { id = 2, name = "Microsoft Sculpt", price = 79.99 },
new { id = 3, name = "Keychron K2 Pro", price = 89.99 }
});

messages.Add(new ToolChatMessage(toolCall.Id, result));
}
}
else
{
Console.WriteLine(completion.Content[0].Text);
break;
}
}
```

**Generating and comparing embeddings in C#:**

```csharp
using OpenAI.Embeddings;

EmbeddingClient embeddingClient = openAiClient.GetEmbeddingClient("text-embedding-3-large");

string[] corpus =
[
"Azure Machine Learning is a cloud-based ML platform.",
"Python is a popular programming language.",
"Training neural networks requires GPU compute."
];

// Generate embeddings for the corpus
ClientResult corpusResult = await embeddingClient.GenerateEmbeddingsAsync(corpus);
float[][] corpusVectors = corpusResult.Value
.Select(e => e.ToFloats().ToArray())
.ToArray();

// Generate embedding for the query
string query = "How do I train a model on Azure?";
float[] queryVector = (await embeddingClient.GenerateEmbeddingAsync(query)).Value.ToFloats().ToArray();

// Cosine similarity helper
static float CosineSimilarity(float[] a, float[] b)
{
float dot = a.Zip(b, (x, y) => x * y).Sum();
float normA = MathF.Sqrt(a.Sum(x => x * x));
float normB = MathF.Sqrt(b.Sum(x => x * x));
return dot / (normA * normB);
}

var ranked = corpus
.Zip(corpusVectors, (doc, vec) => (doc, score: CosineSimilarity(queryVector, vec)))
.OrderByDescending(x => x.score);

Console.WriteLine($"Semantic search results for: \"{query}\"");
foreach (var (doc, score) in ranked)
Console.WriteLine($" [{score:F4}] {doc}");
```

**Azure OpenAI capabilities available in the .NET SDK:**

| Capability | Client | Method |
|------------|--------|--------|
| Chat completions | `ChatClient` | `CompleteChatAsync()` |
| Streaming chat | `ChatClient` | `CompleteChatStreamingAsync()` |
| Function calling | `ChatClient` | `ChatTool` + agentic loop |
| Text embeddings | `EmbeddingClient` | `GenerateEmbeddingsAsync()` |
| Image generation | `ImageClient` | `GenerateImageAsync()` |
| Audio transcription | `AudioClient` | `TranscribeAudioAsync()` |
| Structured output | `ChatCompletionOptions` | `ResponseFormat = ChatResponseFormat.JsonObject` |


↥ back to top

## # 4. AZURE AI STUDIO


## Q. What is Azure AI Studio and what can you build with it?

**Azure AI Studio** (ai.azure.com) is a unified development portal for building, evaluating, and deploying generative AI applications. It consolidates Azure OpenAI, Azure AI Services, Azure ML, and prompt tooling into a single interface.

```mermaid
graph TD
A[AI Foundry Hub\nShared Infrastructure] --> B[AI Foundry Project]
B --> C[Model Catalog\n1600+ Models]
B --> D[Deployments\nManaged · Serverless]
B --> E[Prompt Flows\nVisual Orchestration]
B --> F[Evaluations\nGroundedness · Relevance]
B --> G[Connections\nSearch · Storage · AI Services]
B --> H[Fine-tuning Jobs]
```

**Core capabilities:**

| Feature | Description |
|---------|-------------|
| **Model Catalog** | 1,600+ open-source and proprietary models (OpenAI, Meta, Mistral, Cohere) |
| **Playground** | Interactive testing of models with system prompts |
| **Prompt Flow** | Visual/code orchestration of LLM pipelines (inputs → LLM → outputs) |
| **Evaluations** | Measure groundedness, coherence, fluency, relevance of AI outputs |
| **Deployments** | One-click deploy to managed endpoints or serverless APIs |
| **AI Search integration** | Connect to Azure AI Search for RAG pipelines |

**AI Studio project structure:**

```
AI Studio Hub (shared resources)
└── AI Studio Project
├── Deployments (models)
├── Connections (storage, search, AI services)
├── Prompt flows
├── Evaluations
└── Fine-tuning jobs
```

**Creating a project with the Python SDK:**

```python
from azure.ai.projects import AIProjectClient
from azure.identity import DefaultAzureCredential

client = AIProjectClient(
subscription_id="",
resource_group_name="rg-ai-demo",
project_name="my-ai-project",
credential=DefaultAzureCredential()
)

# List available model deployments
for deployment in client.deployments.list():
print(f"{deployment.name}: {deployment.model_name}")
```


↥ back to top

## Q. How do you browse and deploy models from the Azure AI Foundry model catalog using C#?

**Use case:** A CI/CD automation script in C# that discovers available models in the Azure AI Foundry model catalog, deploys a selected open-source model to a serverless endpoint, and validates the deployment — enabling repeatable infrastructure-as-code for AI workloads.

**Install the NuGet packages:**

```bash
dotnet add package Azure.AI.Projects
dotnet add package Azure.AI.Inference
dotnet add package Azure.Identity
```

**Browse the model catalog and inspect a specific model:**

```csharp
using Azure.AI.Projects;
using Azure.AI.Projects.Models;
using Azure.Identity;

var projectClient = new AIProjectClient(
new Uri("https://.services.ai.azure.com/api/projects/"),
new DefaultAzureCredential());

// ─── 1. BROWSE CATALOG ────────────────────────────────────────────────────────
Console.WriteLine("=== Model Catalog ===");
await foreach (ModelInfo model in projectClient.GetModels().GetAllAsync())
{
Console.WriteLine($" {model.Id,-45} | Publisher: {model.Publisher,-15} | Task: {model.Task}");
}

// ─── 2. GET DETAILS FOR A SPECIFIC MODEL ─────────────────────────────────────
ModelInfo details = await projectClient.GetModelAsync("mistral-large-2407");
Console.WriteLine($"\nModel : {details.DisplayName}");
Console.WriteLine($"Publisher : {details.Publisher}");
Console.WriteLine($"License : {details.License}");
Console.WriteLine($"Description: {details.Description[..Math.Min(120, details.Description.Length)]}...");

// ─── 3. LIST EXISTING DEPLOYMENTS ────────────────────────────────────────────
Console.WriteLine("\n=== Active Deployments ===");
await foreach (ModelDeployment dep in projectClient.GetDeployments().GetAllAsync())
{
Console.WriteLine($" {dep.Name,-30} | Model: {dep.ModelName,-25} | State: {dep.ProvisioningState}");
}
```

**Invoke a catalog model via serverless inference endpoint:**

```csharp
using Azure.AI.Inference;

// Get a chat completions client for a deployed catalog model (no OpenAI required)
ChatCompletionsClient inferenceClient = projectClient.GetChatCompletionsClient("mistral-large-2407");

var inferenceOptions = new ChatCompletionsOptions
{
Messages =
{
new ChatRequestSystemMessage("You are a concise technical assistant."),
new ChatRequestUserMessage("List 3 reasons to use Mistral Large over GPT-3.5-Turbo.")
},
MaxTokens = 400,
Temperature = 0.6f
};

Response inferenceResponse = await inferenceClient.CompleteAsync(inferenceOptions);
Console.WriteLine($"\n{inferenceResponse.Value.Choices[0].Message.Content}");
```

**Run a Prompt Flow evaluation from C#:**

```csharp
// Trigger a named evaluation and check its status
var evalClient = projectClient.GetEvaluationsClient();

// Get an existing evaluation schedule
EvaluationSchedule evalSchedule = await evalClient.GetScheduleAsync("rag-groundedness-eval");
Console.WriteLine($"Evaluation : {evalSchedule.Name}");
Console.WriteLine($"Status : {evalSchedule.ProvisioningState}");
Console.WriteLine($"Description: {evalSchedule.Description}");
```

**Model catalog selection guide:**

| Model family | Publisher | Best for | Serverless deploy |
|-------------|-----------|----------|------------------|
| GPT-4o, GPT-4 Turbo | OpenAI | General purpose, multimodal | Yes |
| Mistral Large / Small | Mistral AI | Cost-efficient chat, function calling | Yes |
| Llama 3.1 / 3.2 | Meta | Open-weight, fine-tunable | Yes |
| Phi-3 / Phi-4 | Microsoft | Edge inference, small footprint | Yes |
| Cohere Command R+ | Cohere | RAG, long context | Yes |
| DALL-E 3 | OpenAI | Image generation | No (Azure OpenAI) |


↥ back to top

## # 5. AZURE MACHINE LEARNING (AML)


## Q. What is Azure Machine Learning and what are its core components?

**Azure Machine Learning (AML)** is a cloud platform for the complete ML lifecycle — data preparation, training, evaluation, deployment, and monitoring. It supports both code-first and low-code approaches.

```mermaid
flowchart LR
A[Data Sources] --> B[Data Assets\nVersioned Datasets]
B --> C[Training Jobs\nCommand · Sweep · Pipeline]
C --> D[Compute\nCPU / GPU Clusters]
C --> E[MLflow Tracking\nMetrics · Params · Artifacts]
E --> F[Model Registry]
F --> G[Online Endpoints\nReal-time Inference]
F --> H[Batch Endpoints\nBulk Scoring]
G --> I[Applications]
H --> I
```

**Core components:**

| Component | Purpose |
|-----------|---------|
| **Workspace** | Top-level resource grouping all AML assets |
| **Compute** | Compute clusters (training), compute instances (dev), inference clusters |
| **Data assets** | Versioned datasets registered in the workspace |
| **Environments** | Docker/conda environments for reproducible training |
| **Jobs** | Executed training scripts (Command, Sweep, Pipeline jobs) |
| **Models** | Registered artifacts from training runs |
| **Endpoints** | Online (real-time) or batch inference endpoints |
| **MLflow** | Integrated experiment tracking and model registry |

**Submitting a training job with SDK v2:**

```python
from azure.ai.ml import MLClient, command
from azure.ai.ml.entities import Environment
from azure.identity import DefaultAzureCredential

ml_client = MLClient(
DefaultAzureCredential(),
subscription_id="",
resource_group_name="rg-ai-demo",
workspace_name="my-aml-ws"
)

job = command(
code="./src",
command="python train.py --learning_rate ${{inputs.lr}} --epochs ${{inputs.epochs}}",
inputs={"lr": 0.001, "epochs": 10},
environment="AzureML-sklearn-1.5-ubuntu20.04-py38-cpu@latest",
compute="cpu-cluster",
display_name="sklearn-training-job"
)

returned_job = ml_client.jobs.create_or_update(job)
print(f"Job submitted: {returned_job.studio_url}")
```


↥ back to top

## Q. How do you manage Azure Machine Learning workspaces and submit training jobs from C#?

**Use case:** A GitHub Actions or Azure DevOps pipeline stage written in C# that submits a training job to AML, polls until completion, registers the best model, and creates an online endpoint — enabling full MLOps CI/CD without leaving the .NET ecosystem.

**Install the NuGet packages:**

```bash
dotnet add package Azure.ResourceManager.MachineLearning
dotnet add package Azure.Identity
```

**Connect to the workspace and list compute clusters:**

```csharp
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.MachineLearning;
using Azure.ResourceManager.MachineLearning.Models;

var credential = new DefaultAzureCredential();
var armClient = new ArmClient(credential);

// Reference the AML workspace via ARM resource ID
var workspaceId = MachineLearningWorkspaceResource.CreateResourceIdentifier(
subscriptionId: "",
resourceGroupName: "rg-ai-demo",
workspaceName: "my-aml-ws");

MachineLearningWorkspaceResource workspace =
armClient.GetMachineLearningWorkspaceResource(workspaceId);

// List available compute clusters
Console.WriteLine("=== Compute Clusters ===");
await foreach (MachineLearningComputeResource compute in
workspace.GetMachineLearningComputes().GetAllAsync())
{
Console.WriteLine(
$" {compute.Data.Name,-25} | Type: {compute.Data.Properties?.ComputeType}");
}
```

**Submit a command job and poll to completion:**

```csharp
// ─── SUBMIT JOB ───────────────────────────────────────────────────────────────
var jobCollection = workspace.GetMachineLearningJobs();

var jobData = new MachineLearningJobData(
new MachineLearningCommandJob(
command: "python train.py --learning-rate 0.001 --epochs 10",
environmentId: "azureml:AzureML-sklearn-1.5-ubuntu20.04-py38-cpu@latest",
computeId: "cpu-cluster")
{
DisplayName = "csharp-sklearn-training-job",
ExperimentName = "csharp-cicd-experiments",
Inputs =
{
["training_data"] = new MachineLearningLiteralJobInput("azureml:sales-data:1")
}
});

string jobName = $"job-{DateTime.UtcNow:yyyyMMddHHmmss}";
ArmOperation createOp =
await jobCollection.CreateOrUpdateAsync(Azure.WaitUntil.Started, jobName, jobData);

MachineLearningJobResource job = createOp.Value;
Console.WriteLine($"Job submitted : {job.Data.Name}");

// ─── POLL UNTIL COMPLETE ──────────────────────────────────────────────────────
MachineLearningJobStatus? status;
do
{
await Task.Delay(TimeSpan.FromSeconds(15));
job = await workspace.GetMachineLearningJobAsync(job.Data.Name);
status = (job.Data.Properties as MachineLearningCommandJob)?.Status;
Console.WriteLine($" [{DateTime.UtcNow:HH:mm:ss}] Status: {status}");
}
while (status is
MachineLearningJobStatus.Running or
MachineLearningJobStatus.Queued or
MachineLearningJobStatus.Preparing);

Console.WriteLine($"Job finished with status: {status}");
```

**Register the trained model and create an online endpoint:**

```csharp
if (status == MachineLearningJobStatus.Completed)
{
// ─── REGISTER MODEL ───────────────────────────────────────────────────────
var modelContainers = workspace.GetMachineLearningModelContainers();
await modelContainers.CreateOrUpdateAsync(
Azure.WaitUntil.Completed,
"sales-forecast-model",
new MachineLearningModelContainerData(
new MachineLearningModelContainerProperties
{
Description = "Sales forecast model — C# CI/CD pipeline"
}));

var modelVersions = (await modelContainers.GetAsync("sales-forecast-model"))
.Value.GetMachineLearningModelVersions();

await modelVersions.CreateOrUpdateAsync(
Azure.WaitUntil.Completed, "1",
new MachineLearningModelVersionData(
new MachineLearningModelVersionProperties
{
ModelUri = $"azureml://jobs/{job.Data.Name}/outputs/model",
Description = "v1 trained from C# job"
}));

Console.WriteLine("Model registered: sales-forecast-model:1");

// ─── CREATE MANAGED ONLINE ENDPOINT ──────────────────────────────────────
var endpoints = workspace.GetMachineLearningOnlineEndpoints();

await endpoints.CreateOrUpdateAsync(
Azure.WaitUntil.Completed,
"sales-forecast-endpoint",
new MachineLearningOnlineEndpointData(workspace.Data.Location)
{
Properties = new MachineLearningOnlineEndpointProperties
{
AuthMode = MachineLearningEndpointAuthMode.Key,
Description = "Real-time endpoint for sales forecast model"
}
});

Console.WriteLine("Online endpoint created: sales-forecast-endpoint");
}
```

**Key Azure ML ARM SDK types reference:**

| Type | Purpose |
|------|---------|
| `MachineLearningWorkspaceResource` | Workspace-level operations |
| `MachineLearningComputeResource` | Manage clusters and compute instances |
| `MachineLearningJobResource` | Submit, monitor, and cancel jobs |
| `MachineLearningModelContainerResource` | Model registry container |
| `MachineLearningModelVersionResource` | Versioned registered models |
| `MachineLearningOnlineEndpointResource` | Real-time inference endpoints |
| `MachineLearningBatchEndpointResource` | Batch inference endpoints |


↥ back to top

## # 6. AZURE COMPUTER VISION


## Q. What is Azure Computer Vision and what are its main capabilities?

**Azure Computer Vision** is an AI service that analyzes images and videos to extract information such as objects, text, faces, and scene context. The latest version (4.0) integrates vision models based on Florence and GPT-4 Vision.

```mermaid
flowchart LR
A[Image / Video] --> B[Azure AI Vision API]
B --> C[Auto Caption]
B --> D[Object Detection\nBounding Boxes]
B --> E[OCR — Read API\nPrinted · Handwritten]
B --> F[Tags & Confidence]
B --> G[Spatial Analysis\nPeople Counting · Zones]
B --> H[Background Removal\nPNG Matting]
```

**Key capabilities:**

| Feature | Description |
|---------|-------------|
| **Image Analysis** | Caption, dense captions, tags, object detection, smart crop |
| **OCR (Read API)** | Extract printed and handwritten text from images/PDFs |
| **Spatial Analysis** | Real-time video analysis (people counting, zone detection) |
| **Background Removal** | Segment foreground from background |
| **Product Recognition** | Identify products on retail shelves |
| **GPT-4 Vision** | Multimodal understanding (via Azure OpenAI) |

**Example — image analysis with Python SDK:**

```python
from azure.ai.vision.imageanalysis import ImageAnalysisClient
from azure.ai.vision.imageanalysis.models import VisualFeatures
from azure.core.credentials import AzureKeyCredential

client = ImageAnalysisClient(
endpoint="https://.cognitiveservices.azure.com/",
credential=AzureKeyCredential("")
)

result = client.analyze_from_url(
image_url="https://example.com/photo.jpg",
visual_features=[
VisualFeatures.CAPTION,
VisualFeatures.OBJECTS,
VisualFeatures.READ # OCR
],
language="en"
)

print(f"Caption: {result.caption.text} (confidence: {result.caption.confidence:.2f})")

for obj in result.objects.list:
print(f"Object: {obj.tags[0].name} at {obj.bounding_box}")

if result.read:
for block in result.read.blocks:
for line in block.lines:
print(f"Text: {line.text}")
```


↥ back to top

## Q. How do you perform image analysis and OCR using Azure AI Vision in C#?

**Use case:** A retail quality-control application that scans product images on a conveyor belt, reads printed labels via OCR, detects objects, and generates automated captions — all from a .NET worker service.

**Install the NuGet package:**

```bash
dotnet add package Azure.AI.Vision.ImageAnalysis
```

**Full image analysis — caption, objects, OCR, tags (C#):**

```csharp
using Azure;
using Azure.AI.Vision.ImageAnalysis;

var client = new ImageAnalysisClient(
new Uri("https://.cognitiveservices.azure.com/"),
new AzureKeyCredential("")
);

// Analyse an image from a public URL
ImageAnalysisResult result = await client.AnalyzeAsync(
new Uri("https://example.com/product-shelf.jpg"),
VisualFeatures.Caption
| VisualFeatures.DenseCaptions
| VisualFeatures.Objects
| VisualFeatures.Tags
| VisualFeatures.Read, // OCR
new ImageAnalysisOptions { Language = "en", GenderNeutralCaption = true }
);

// Caption
Console.WriteLine($"Caption : {result.Caption.Text} (confidence: {result.Caption.Confidence:P1})");

// Dense captions (region-level)
Console.WriteLine("\nDense Captions:");
foreach (DenseCaption dc in result.DenseCaptions.Values)
Console.WriteLine($" [{dc.Confidence:P0}] {dc.Text,-50} @ ({dc.BoundingBox.X},{dc.BoundingBox.Y})");

// Detected objects
Console.WriteLine("\nObjects:");
foreach (DetectedObject obj in result.Objects.Values)
Console.WriteLine($" {obj.Tags[0].Name,-20} confidence: {obj.Tags[0].Confidence:P1}");

// Tags
Console.WriteLine("\nTags: " + string.Join(", ",
result.Tags.Values.Select(t => $"{t.Name}({t.Confidence:P0})")));

// OCR — all text in the image
Console.WriteLine("\nOCR Text:");
if (result.Read is not null)
foreach (DetectedTextBlock block in result.Read.Blocks)
foreach (DetectedTextLine line in block.Lines)
Console.WriteLine($" {line.Text}");
```

**Analyse a local file using a stream:**

```csharp
using var imageStream = File.OpenRead("./images/label.jpg");
ImageAnalysisResult streamResult = await client.AnalyzeAsync(
BinaryData.FromStream(imageStream),
VisualFeatures.Read,
new ImageAnalysisOptions { Language = "en" }
);

Console.WriteLine("Extracted text from local file:");
foreach (DetectedTextBlock block in streamResult.Read.Blocks)
foreach (DetectedTextLine line in block.Lines)
Console.WriteLine($" {line.Text}");
```

**Background removal (foreground matting):**

```csharp
// Background removal returns a PNG with transparent background
Response bgResult = await client.RemoveBackgroundAsync(
new Uri("https://example.com/person.jpg")
);

await File.WriteAllBytesAsync("output-no-bg.png", bgResult.Value.ToArray());
Console.WriteLine($"Background removed — saved to output-no-bg.png");
```

**Azure AI Vision capabilities in .NET:**

| Feature | `VisualFeatures` enum | Notes |
|---------|----------------------|-------|
| Auto-caption | `Caption` | Single sentence |
| Region captions | `DenseCaptions` | Up to 10 regions |
| Object detection | `Objects` | Bounding boxes |
| Semantic tags | `Tags` | Confidence scored |
| OCR | `Read` | Printed & handwritten |
| People detection | `People` | Bounding boxes only |
| Smart crop | `SmartCrops` | Aspect-ratio aware |
| Background removal | `RemoveBackgroundAsync()` | Returns PNG |


↥ back to top

## # 7. AZURE CUSTOM VISION


## Q. What is Azure Custom Vision and when should you use it?

**Azure Custom Vision** is a service for building and deploying custom image classification and object detection models with minimal ML expertise. It uses transfer learning on top of pre-trained models, requiring as few as 15 images per class.

```mermaid
flowchart TD
A[Label Training Images] --> B[Upload & Tag via SDK / Portal]
B --> C[Train Model\nTransfer Learning]
C --> D[Evaluate\nPrecision · Recall · mAP]
D --> E{Acceptable\nAccuracy?}
E -- No --> A
E -- Yes --> F[Publish Iteration]
F --> G[REST Prediction Endpoint]
F --> H[Export for Edge\nONNX · TFLite · CoreML · Docker]
```

**Two main tasks:**

| Task | Description | Min Images |
|------|-------------|-----------|
| **Image Classification** | Assign one or more labels to an image (multi-class or multi-label) | 5–15 per tag |
| **Object Detection** | Locate and label objects within an image with bounding boxes | 15 per tag |

**Workflow:**

```
1. Create Custom Vision project (portal or SDK)
2. Upload & tag training images
3. Train model (Quick or Advanced training)
4. Evaluate — Precision, Recall, mAP
5. Test with new images
6. Publish → REST endpoint or export (ONNX, TensorFlow, CoreML, Docker)
```

**Python training example:**

```python
from azure.cognitiveservices.vision.customvision.training import CustomVisionTrainingClient
from azure.cognitiveservices.vision.customvision.training.models import ImageFileCreateBatch, ImageFileCreateEntry
from msrest.authentication import ApiKeyCredentials
import os

credentials = ApiKeyCredentials(in_headers={"Training-key": ""})
trainer = CustomVisionTrainingClient("", credentials)

# Create project
project = trainer.create_project("Defect Classifier")

# Create tags
good_tag = trainer.create_tag(project.id, "good")
defect_tag = trainer.create_tag(project.id, "defect")

# Upload images
image_list = []
for fname in os.listdir("./images/good"):
with open(f"./images/good/{fname}", "rb") as f:
image_list.append(ImageFileCreateEntry(name=fname, contents=f.read(), tag_ids=[good_tag.id]))

trainer.create_images_from_files(project.id, ImageFileCreateBatch(images=image_list))

# Train
import time
iteration = trainer.train_project(project.id)
while iteration.status != "Completed":
time.sleep(5)
iteration = trainer.get_iteration(project.id, iteration.id)

# Publish
trainer.publish_iteration(project.id, iteration.id, "classifyModel", "")
print("Model published!")
```


↥ back to top

## Q. How do you train and call an Azure Custom Vision model from C#?

**Use case:** A manufacturing defect-detection system that trains a Custom Vision classifier on labelled product images and integrates real-time prediction into a .NET production-line monitoring service.

**Install the NuGet packages:**

```bash
dotnet add package Microsoft.Azure.CognitiveServices.Vision.CustomVision.Training
dotnet add package Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction
```

**Create a project, upload tagged images, and train (C#):**

```csharp
using Microsoft.Azure.CognitiveServices.Vision.CustomVision.Training;
using Microsoft.Azure.CognitiveServices.Vision.CustomVision.Training.Models;

string trainingKey = "";
string trainingEndpoint = "https://.cognitiveservices.azure.com/";

var trainingClient = new CustomVisionTrainingClient(
new Microsoft.Azure.CognitiveServices.Vision.CustomVision.Training.ApiKeyServiceClientCredentials(trainingKey))
{
Endpoint = trainingEndpoint
};

// ─── 1. CREATE PROJECT ────────────────────────────────────────────────────────
Project project = await trainingClient.CreateProjectAsync(
"DefectClassifier",
description: "Binary classifier — good vs defect parts",
classificationType: Classifier.Multiclass);

Console.WriteLine($"Project created: {project.Id}");

// ─── 2. CREATE TAGS ───────────────────────────────────────────────────────────
Tag goodTag = await trainingClient.CreateTagAsync(project.Id, "good");
Tag defectTag = await trainingClient.CreateTagAsync(project.Id, "defect");

// ─── 3. UPLOAD TAGGED IMAGES ─────────────────────────────────────────────────
var imageEntries = new List();

foreach (string file in Directory.GetFiles("./images/good"))
{
byte[] bytes = await File.ReadAllBytesAsync(file);
imageEntries.Add(new ImageFileCreateEntry(Path.GetFileName(file), bytes,
tagIds: new List { goodTag.Id }));
}

foreach (string file in Directory.GetFiles("./images/defect"))
{
byte[] bytes = await File.ReadAllBytesAsync(file);
imageEntries.Add(new ImageFileCreateEntry(Path.GetFileName(file), bytes,
tagIds: new List { defectTag.Id }));
}

ImageCreateSummary uploadSummary = await trainingClient.CreateImagesFromFilesAsync(
project.Id, new ImageFileCreateBatch(imageEntries));

Console.WriteLine($"Uploaded: {uploadSummary.Images.Count} images");

// ─── 4. TRAIN ─────────────────────────────────────────────────────────────────
Iteration iteration = await trainingClient.TrainProjectAsync(project.Id);

while (iteration.Status == "Training")
{
await Task.Delay(TimeSpan.FromSeconds(5));
iteration = await trainingClient.GetIterationAsync(project.Id, iteration.Id);
Console.WriteLine($"Training status: {iteration.Status}");
}

Console.WriteLine($"Training complete — Precision: {iteration.Precision:P1} Recall: {iteration.Recall:P1}");

// ─── 5. PUBLISH ITERATION ─────────────────────────────────────────────────────
await trainingClient.PublishIterationAsync(
project.Id, iteration.Id,
publishName: "DefectClassifierV1",
predictionId: "");

Console.WriteLine("Model published as 'DefectClassifierV1'.");
```

**Run real-time prediction from C#:**

```csharp
using Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction;
using Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction.Models;

string predictionKey = "";
string predictionEndpoint = "https://.cognitiveservices.azure.com/";

var predictionClient = new CustomVisionPredictionClient(
new Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction.ApiKeyServiceClientCredentials(predictionKey))
{
Endpoint = predictionEndpoint
};

// Predict from a local file
using var imageStream = File.OpenRead("./test-images/part-001.jpg");
ImagePrediction prediction = await predictionClient.ClassifyImageAsync(
project.Id,
publishedModelName: "DefectClassifierV1",
imageData: imageStream
);

foreach (PredictionModel pred in prediction.Predictions.OrderByDescending(p => p.Probability))
Console.WriteLine($" {pred.TagName,-10}: {pred.Probability:P1}");

// Predict from a URL
ImagePrediction urlPrediction = await predictionClient.ClassifyImageUrlAsync(
project.Id,
publishedModelName: "DefectClassifierV1",
url: new Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction.Models.ImageUrl(
"https://example.com/part-002.jpg")
);

string topTag = urlPrediction.Predictions.MaxBy(p => p.Probability)!.TagName;
Console.WriteLine($"Top prediction: {topTag}");
```

**Custom Vision model export formats for edge deployment:**

| Format | Target runtime | Use case |
|--------|---------------|----------|
| ONNX | Windows ML, ONNX Runtime | .NET on-device inference |
| TensorFlow / TFLite | Android, Raspberry Pi | Mobile / IoT |
| CoreML | iOS / macOS | Apple devices |
| OpenVINO | Intel hardware | Industrial edge |
| Dockerfile | Any container host | Offline REST endpoint |


↥ back to top

## # 8. AZURE FACE API


## Q. What is the Azure Face API and what are its use cases and limitations?

**Azure Face API** detects, analyzes, and identifies human faces in images. As of 2023, access to certain capabilities (identification, verification, facial attributes like emotion) requires approval through Microsoft's Responsible AI access program due to ethical concerns.

```mermaid
flowchart TD
A[Input Image] --> B[Azure Face API]
B --> C[Face Detection\nBounding Box]
C --> D[Open Access\nGlasses · Mask · Blur · Exposure]
C --> E[Liveness Detection\nAnti-spoofing]
C --> F[Face ID]
F -->|Restricted Access| G[1:1 Verification\nSame Person?]
F -->|Restricted Access| H[1:N Identification\nWho is this?]
F -->|Restricted Access| I[Emotion · Age Attributes]
```

**Available capabilities:**

| Feature | Access | Description |
|---------|--------|-------------|
| **Face Detection** | Open | Locate faces + bounding boxes in images |
| **Face Attributes** | Restricted | Age, glasses, blur, exposure, noise, mask detection |
| **Face Verification** | Restricted | Are two faces the same person? (1:1) |
| **Face Identification** | Restricted | Who is this person? (1:N against a group) |
| **Liveness Detection** | Open | Prevent spoofing with static photos |

**Basic face detection (Python):**

```python
from azure.cognitiveservices.vision.face import FaceClient
from msrest.authentication import CognitiveServicesCredentials

face_client = FaceClient(
"",
CognitiveServicesCredentials("")
)

# Detect faces in an image URL
detected_faces = face_client.face.detect_with_url(
url="https://example.com/group-photo.jpg",
return_face_attributes=["age", "gender", "headPose", "glasses", "blur"],
detection_model="detection_03",
recognition_model="recognition_04"
)

for face in detected_faces:
r = face.face_rectangle
print(f"Face at ({r.left},{r.top}) size {r.width}x{r.height}")
print(f" Glasses: {face.face_attributes.glasses}")
print(f" Blur: {face.face_attributes.blur.blur_level}")
```

**Responsible use note:** Facial recognition carries privacy risks. Microsoft requires a use-case justification and legal review before granting access to identification and verification capabilities.


↥ back to top

## Q. How do you detect faces and check liveness using the Azure Face API in C#?

**Use case:** A workplace access-control application in .NET that detects faces in camera frames, checks for presentation-attack liveness, and verifies whether the detected face matches an enrolled employee — using only the open-access capabilities of the Azure Face API.

**Install the NuGet package:**

```bash
dotnet add package Microsoft.Azure.CognitiveServices.Vision.Face
```

**Face detection with attributes (C#):**

```csharp
using Microsoft.Azure.CognitiveServices.Vision.Face;
using Microsoft.Azure.CognitiveServices.Vision.Face.Models;

string faceKey = "";
string faceEndpoint = "https://.cognitiveservices.azure.com/";

var faceClient = new FaceClient(
new ApiKeyServiceClientCredentials(faceKey))
{
Endpoint = faceEndpoint
};

// ─── DETECT FACES FROM URL ────────────────────────────────────────────────────
IList faces = await faceClient.Face.DetectWithUrlAsync(
url: "https://example.com/office-entrance.jpg",
returnFaceAttributes: new List
{
FaceAttributeType.Glasses,
FaceAttributeType.Blur,
FaceAttributeType.Exposure,
FaceAttributeType.Mask // open-access: mask detection
},
detectionModel : DetectionModel.Detection03,
recognitionModel: RecognitionModel.Recognition04,
returnFaceId: true
);

Console.WriteLine($"Detected {faces.Count} face(s):");
foreach (DetectedFace face in faces)
{
FaceRectangle r = face.FaceRectangle;
Console.WriteLine($" Face ID : {face.FaceId}");
Console.WriteLine($" Location : ({r.Left},{r.Top}) {r.Width}×{r.Height}");
Console.WriteLine($" Glasses : {face.FaceAttributes.Glasses}");
Console.WriteLine($" Blur : {face.FaceAttributes.Blur?.BlurLevel}");
Console.WriteLine($" Mask : {face.FaceAttributes.Mask?.Type}");
Console.WriteLine();
}

// ─── DETECT FACES FROM LOCAL FILE ────────────────────────────────────────────
using var imageStream = File.OpenRead("./images/entrance.jpg");
IList localFaces = await faceClient.Face.DetectWithStreamAsync(
image: imageStream,
detectionModel : DetectionModel.Detection03,
recognitionModel: RecognitionModel.Recognition04,
returnFaceId: true
);

Console.WriteLine($"Local image: detected {localFaces.Count} face(s).");
```

**Face verification — are two faces the same person? (restricted access required):**

```csharp
// Note: Face verification requires approved access via Microsoft RAI program.
// The code below demonstrates the pattern once access is granted.

// Detect face from enrolled employee photo
IList enrolledFaces = await faceClient.Face.DetectWithUrlAsync(
"https://example.com/employee-john.jpg",
returnFaceId: true,
recognitionModel: RecognitionModel.Recognition04,
detectionModel: DetectionModel.Detection03
);

// Detect face from live camera frame
IList liveFaces = await faceClient.Face.DetectWithUrlAsync(
"https://example.com/live-frame.jpg",
returnFaceId: true,
recognitionModel: RecognitionModel.Recognition04,
detectionModel: DetectionModel.Detection03
);

if (enrolledFaces.Count > 0 && liveFaces.Count > 0)
{
VerifyResult verifyResult = await faceClient.Face.VerifyFaceToFaceAsync(
faceId1: enrolledFaces[0].FaceId!.Value,
faceId2: liveFaces[0].FaceId!.Value
);

Console.WriteLine($"Same person : {verifyResult.IsIdentical}");
Console.WriteLine($"Confidence : {verifyResult.Confidence:P1}");

string decision = verifyResult.IsIdentical && verifyResult.Confidence > 0.8
? "ACCESS GRANTED" : "ACCESS DENIED";
Console.WriteLine($"Decision : {decision}");
}
```

**Face API capability access summary:**

| Capability | Access level | C# method |
|------------|-------------|----------|
| Face detection (bounding box) | Open | `DetectWithUrlAsync` / `DetectWithStreamAsync` |
| Mask & blur attributes | Open | `FaceAttributeType.Mask`, `.Blur` |
| Glasses, exposure attributes | Open | `FaceAttributeType.Glasses`, `.Exposure` |
| Liveness detection | Open (separate SDK) | `FaceSessionClient` (preview) |
| Face verification (1:1) | Restricted | `VerifyFaceToFaceAsync` |
| Face identification (1:N) | Restricted | `IdentifyAsync` with `PersonGroup` |
| Emotion, age attributes | Restricted | `FaceAttributeType.Emotion`, `.Age` |


↥ back to top

## # 9. AZURE DOCUMENT INTELLIGENCE


## Q. What is Azure Document Intelligence and how does it work?

**Azure Document Intelligence** (formerly Form Recognizer) is an AI service that extracts structured data — text, key-value pairs, tables, and fields — from documents such as invoices, receipts, contracts, IDs, and tax forms.

```mermaid
flowchart TD
A[Document\nPDF · Image · DOCX] --> B[Document Intelligence API]
B --> C{Model Selection}
C --> D[Prebuilt Models\ninvoice · receipt · idDocument\nbusinessCard · contract]
C --> E[Layout / Read\nGeneral OCR + Tables]
C --> F[Custom Model\nTemplate · Neural]
D --> G[Structured Fields\nKey-Value · Tables · Line Items]
E --> G
F --> G
G --> H[Downstream Systems\nERP · Database · App]
```

**Pre-built models available:**

| Model | Document Type |
|-------|--------------|
| `prebuilt-invoice` | Invoices (vendor, amounts, line items) |
| `prebuilt-receipt` | Receipts (merchant, total, items) |
| `prebuilt-idDocument` | Passports, driver's licenses |
| `prebuilt-businessCard` | Business cards (name, phone, email) |
| `prebuilt-contract` | Legal contracts (parties, clauses) |
| `prebuilt-layout` | General layout + tables + OCR |
| `prebuilt-read` | Plain text extraction |
| **Custom model** | Train on your own document types |

**Analyzing an invoice with Python:**

```python
from azure.ai.documentintelligence import DocumentIntelligenceClient
from azure.ai.documentintelligence.models import AnalyzeDocumentRequest
from azure.core.credentials import AzureKeyCredential

client = DocumentIntelligenceClient(
endpoint="https://.cognitiveservices.azure.com/",
credential=AzureKeyCredential("")
)

poller = client.begin_analyze_document(
"prebuilt-invoice",
AnalyzeDocumentRequest(url_source="https://example.com/invoice.pdf")
)
result = poller.result()

for invoice in result.documents:
fields = invoice.fields
print(f"Vendor: {fields.get('VendorName', {}).get('content')}")
print(f"Total: {fields.get('InvoiceTotal', {}).get('content')}")
print(f"Date: {fields.get('InvoiceDate', {}).get('content')}")
print(f"Invoice #: {fields.get('InvoiceId', {}).get('content')}")
```

**Training a custom model:**

```python
# 1. Label documents in Document Intelligence Studio (studio.cognitiveservices.azure.com)
# 2. Build the model
poller = client.begin_build_document_model(
build_mode="template", # or "neural"
blob_container_url="https://.blob.core.windows.net/?",
model_id="my-custom-invoice-model"
)
model = poller.result()
print(f"Model '{model.model_id}' built — accuracy: {model.doc_types}")
```


↥ back to top

## Q. How do you extract structured data from documents using Azure Document Intelligence in C#?

**Use case:** An accounts-payable automation system in .NET that processes incoming PDF invoices from Azure Blob Storage, extracts vendor details and line items using the `prebuilt-invoice` model, and writes results to a SQL database.

**Install the NuGet package:**

```bash
dotnet add package Azure.AI.DocumentIntelligence
```

**Extract invoice fields with the prebuilt model (C#):**

```csharp
using Azure;
using Azure.AI.DocumentIntelligence;

var client = new DocumentIntelligenceClient(
new Uri("https://.cognitiveservices.azure.com/"),
new AzureKeyCredential("")
);

// ─── ANALYSE INVOICE FROM URL ─────────────────────────────────────────────────
Operation operation = await client.AnalyzeDocumentAsync(
WaitUntil.Completed,
"prebuilt-invoice",
new AnalyzeDocumentContent
{
UrlSource = new Uri("https://example.com/invoice.pdf")
});

AnalyzeResult result = operation.Value;

foreach (AnalyzedDocument invoice in result.Documents)
{
Console.WriteLine("=== Invoice ===");

if (invoice.Fields.TryGetValue("VendorName", out DocumentField? vendor))
Console.WriteLine($" Vendor : {vendor.ValueString}");

if (invoice.Fields.TryGetValue("InvoiceId", out DocumentField? invoiceId))
Console.WriteLine($" Invoice # : {invoiceId.ValueString}");

if (invoice.Fields.TryGetValue("InvoiceDate", out DocumentField? date))
Console.WriteLine($" Date : {date.ValueDate}");

if (invoice.Fields.TryGetValue("DueDate", out DocumentField? due))
Console.WriteLine($" Due Date : {due.ValueDate}");

if (invoice.Fields.TryGetValue("InvoiceTotal", out DocumentField? total))
Console.WriteLine($" Total : {total.ValueCurrency?.Amount:C} {total.ValueCurrency?.CurrencyCode}");

if (invoice.Fields.TryGetValue("SubTotal", out DocumentField? sub))
Console.WriteLine($" Subtotal : {sub.ValueCurrency?.Amount:C}");

// ─── LINE ITEMS ────────────────────────────────────────────────────────────
if (invoice.Fields.TryGetValue("Items", out DocumentField? items)
&& items.ValueList is not null)
{
Console.WriteLine(" Line Items:");
foreach (DocumentField item in items.ValueList)
{
if (item.ValueDictionary is null) continue;

item.ValueDictionary.TryGetValue("Description", out DocumentField? desc);
item.ValueDictionary.TryGetValue("Quantity", out DocumentField? qty);
item.ValueDictionary.TryGetValue("UnitPrice", out DocumentField? price);
item.ValueDictionary.TryGetValue("Amount", out DocumentField? amount);

Console.WriteLine($" {desc?.ValueString,-35} qty: {qty?.ValueDouble,5} " +
$"@ {price?.ValueCurrency?.Amount,8:C} = {amount?.ValueCurrency?.Amount,10:C}");
}
}
}
```

**Analyse a local PDF file using a stream:**

```csharp
using var pdfStream = File.OpenRead("./invoices/march-invoice.pdf");
Operation streamOp = await client.AnalyzeDocumentAsync(
WaitUntil.Completed,
"prebuilt-invoice",
new AnalyzeDocumentContent { Base64Source = BinaryData.FromStream(pdfStream) }
);

AnalyzeResult streamResult = streamOp.Value;
Console.WriteLine($"Pages analysed: {streamResult.Pages.Count}");
```

**Build and use a custom document model (C#):**

```csharp
// ─── BUILD CUSTOM MODEL (run once) ────────────────────────────────────────────
// Label documents first in Document Intelligence Studio, then:
BuildDocumentModelOperation buildOp = await client.BuildDocumentModelAsync(
WaitUntil.Completed,
new BuildDocumentModelContent(
modelId : "purchase-order-model",
buildMode: DocumentBuildMode.Template)
{
AzureBlobSource = new AzureBlobContentSource(
new Uri("https://.blob.core.windows.net/?")
),
Description = "Custom PO extraction model"
}
);

DocumentModelDetails model = buildOp.Value;
Console.WriteLine($"Model '{model.ModelId}' built — doc types: {model.DocTypes.Count}");

// ─── USE CUSTOM MODEL ─────────────────────────────────────────────────────────
Operation customOp = await client.AnalyzeDocumentAsync(
WaitUntil.Completed,
"purchase-order-model",
new AnalyzeDocumentContent
{
UrlSource = new Uri("https://example.com/po-2026-001.pdf")
});

foreach (AnalyzedDocument doc in customOp.Value.Documents)
{
if (doc.Fields.TryGetValue("PONumber", out DocumentField? poNum))
Console.WriteLine($"PO Number : {poNum.ValueString}");
if (doc.Fields.TryGetValue("Requester", out DocumentField? req))
Console.WriteLine($"Requester : {req.ValueString}");
}
```

**Prebuilt models available in C#:**

| Model ID | Document type | Key extracted fields |
|----------|--------------|---------------------|
| `prebuilt-invoice` | Invoices | VendorName, InvoiceTotal, Items, DueDate |
| `prebuilt-receipt` | Receipts | MerchantName, Total, TransactionDate |
| `prebuilt-idDocument` | Passports, licences | FirstName, LastName, DateOfBirth, DocumentNumber |
| `prebuilt-businessCard` | Business cards | ContactNames, Emails, PhoneNumbers |
| `prebuilt-contract` | Legal contracts | Parties, Dates, RenewalDate |
| `prebuilt-layout` | Any document | Tables, paragraphs, selection marks |
| `prebuilt-read` | Any document | Full text, language, handwritten text |


↥ back to top

## # 10. AZURE LANGUAGE SERVICE


## Q. What features does Azure Language Service offer?

**Azure Language Service** is a unified NLP service that consolidates text analytics, language understanding, and question answering into a single resource.

```mermaid
flowchart LR
A[Input Text] --> B[Azure Language Service]
B --> C[Sentiment Analysis\nOpinion Mining]
B --> D[Named Entity Recognition\nPerson · Org · Location · Date]
B --> E[PII Detection & Redaction]
B --> F[Key Phrase Extraction]
B --> G[Language Detection]
B --> H[Question Answering QnA]
B --> I[Conversational CLU\nIntent · Entity]
B --> J[Text Summarization\nExtractive · Abstractive]
B --> K[Healthcare NLP]
```

**Available features:**

| Feature | Description |
|---------|-------------|
| **Sentiment Analysis** | Positive/negative/neutral + opinion mining |
| **Named Entity Recognition (NER)** | Identify persons, organizations, locations, dates |
| **PII Detection** | Detect and redact personally identifiable information |
| **Key Phrase Extraction** | Extract the most important phrases |
| **Language Detection** | Identify the language of text |
| **Entity Linking** | Link entities to Wikipedia |
| **Text Classification** | Custom single-label / multi-label classification |
| **Custom NER** | Train models to extract domain-specific entities |
| **Question Answering (QnA)** | Build FAQ bots from documents/URLs |
| **Conversational Language Understanding (CLU)** | Intent + entity recognition for chatbots |
| **Text Summarization** | Extractive and abstractive summarization |
| **Healthcare NLP** | Clinical entities from medical text |

**Example — multi-feature analysis:**

```python
from azure.ai.textanalytics import TextAnalyticsClient
from azure.core.credentials import AzureKeyCredential

client = TextAnalyticsClient(
endpoint="https://.cognitiveservices.azure.com/",
credential=AzureKeyCredential("")
)

docs = [
"Microsoft released Azure AI Studio in 2024 from its Redmond headquarters.",
"Patient John Doe, DOB 01/15/1980, was prescribed Metformin 500mg."
]

# Named Entity Recognition
ner_results = client.recognize_entities(docs)
for doc in ner_results:
for entity in doc.entities:
print(f"{entity.text:30} | Category: {entity.category:20} | Confidence: {entity.confidence_score:.2f}")

# PII Detection
pii_results = client.recognize_pii_entities([docs[1]])
for doc in pii_results:
print(f"Redacted: {doc.redacted_text}")

# Sentiment with opinion mining
sa_results = client.analyze_sentiment(docs, show_opinion_mining=True)
for doc in sa_results:
print(f"Sentiment: {doc.sentiment}")
```


↥ back to top

## Q. How do you use Azure AI Language Service for NLP tasks in C#?

**Use case:** A customer-feedback pipeline in .NET that runs sentiment analysis with opinion mining, extracts named entities, detects PII, and generates an abstractive summary — all in a single batched call from an ASP.NET Core background worker.

**Install the NuGet package:**

```bash
dotnet add package Azure.AI.TextAnalytics
```

**Sentiment analysis, NER, PII detection, and summarisation (C#):**

```csharp
using Azure;
using Azure.AI.TextAnalytics;

var client = new TextAnalyticsClient(
new Uri("https://.cognitiveservices.azure.com/"),
new AzureKeyCredential("")
);

var documents = new List
{
"Microsoft released Azure AI Studio from its Redmond HQ in 2024. The platform is excellent.",
"Patient John Doe, DOB 01/15/1980, was prescribed Metformin 500mg by Dr. Smith."
};

// ─── 1. SENTIMENT WITH OPINION MINING ────────────────────────────────────────
Console.WriteLine("=== Sentiment Analysis ===");
AnalyzeSentimentResultCollection sentimentResults =
await client.AnalyzeSentimentBatchAsync(documents, options: new AnalyzeSentimentOptions
{
IncludeOpinionMining = true
});

foreach (AnalyzeSentimentResult result in sentimentResults)
{
Console.WriteLine($" Overall : {result.DocumentSentiment.Sentiment}");
Console.WriteLine($" Positive : {result.DocumentSentiment.ConfidenceScores.Positive:P1}");
Console.WriteLine($" Negative : {result.DocumentSentiment.ConfidenceScores.Negative:P1}");

foreach (SentenceSentiment sentence in result.DocumentSentiment.Sentences)
{
Console.WriteLine($" Sentence : \"{sentence.Text}\" → {sentence.Sentiment}");
foreach (SentenceOpinion opinion in sentence.Opinions)
{
Console.WriteLine($" Target : {opinion.Target.Text} ({opinion.Target.Sentiment})");
foreach (AssessmentSentiment assessment in opinion.Assessments)
Console.WriteLine($" Opinion : {assessment.Text} ({assessment.Sentiment})");
}
}
}

// ─── 2. NAMED ENTITY RECOGNITION ─────────────────────────────────────────────
Console.WriteLine("\n=== Named Entity Recognition ===");
RecognizeEntitiesResultCollection nerResults =
await client.RecognizeEntitiesBatchAsync(documents);

foreach (RecognizeEntitiesResult result in nerResults)
foreach (CategorizedEntity entity in result.Entities)
Console.WriteLine(
$" {entity.Text,-30} | {entity.Category,-20} | Sub: {entity.SubCategory,-15} | Conf: {entity.ConfidenceScore:P0}");

// ─── 3. PII DETECTION & REDACTION ────────────────────────────────────────────
Console.WriteLine("\n=== PII Detection ===");
RecognizePiiEntitiesResultCollection piiResults =
await client.RecognizePiiEntitiesBatchAsync(new[] { documents[1] });

foreach (RecognizePiiEntitiesResult result in piiResults)
{
Console.WriteLine($" Redacted : {result.Entities.RedactedText}");
foreach (PiiEntity entity in result.Entities)
Console.WriteLine($" PII : {entity.Text,-25} | Category: {entity.Category}");
}

// ─── 4. ABSTRACTIVE SUMMARISATION ────────────────────────────────────────────
Console.WriteLine("\n=== Abstractive Summarisation ===");
AbstractSummaryOperation summaryOp = await client.AbstractSummaryAsync(
Azure.WaitUntil.Completed,
documents,
options: new AbstractSummaryOptions { SentenceCount = 2 }
);

await foreach (AbstractSummaryResultCollection page in summaryOp)
foreach (AbstractSummaryResult result in page)
foreach (AbstractiveSummary summary in result.Summaries)
Console.WriteLine($" Summary: {summary.Text}");
```

**Key Phrase Extraction and Language Detection:**

```csharp
// ─── KEY PHRASE EXTRACTION ────────────────────────────────────────────────────
ExtractKeyPhrasesResultCollection kpResults =
await client.ExtractKeyPhrasesBatchAsync(documents);

foreach (ExtractKeyPhrasesResult result in kpResults)
Console.WriteLine(" Key phrases: " + string.Join(", ", result.KeyPhrases));

// ─── LANGUAGE DETECTION ───────────────────────────────────────────────────────
var multiLangDocs = new List
{
"Azure AI is transforming enterprise applications.",
"Azure AI transformiert Unternehmensanwendungen.",
"Azure AI transforme les applications d'entreprise."
};

DetectLanguageResultCollection langResults =
await client.DetectLanguageBatchAsync(multiLangDocs);

foreach (DetectLanguageResult result in langResults)
Console.WriteLine(
$" Language: {result.PrimaryLanguage.Name,-15} | ISO: {result.PrimaryLanguage.Iso6391Name} | Conf: {result.PrimaryLanguage.ConfidenceScore:P0}");
```

**Azure AI Language features available in .NET:**

| Feature | SDK method | Use case |
|---------|-----------|----------|
| Sentiment + opinion mining | `AnalyzeSentimentBatchAsync` | Customer feedback, reviews |
| Named Entity Recognition | `RecognizeEntitiesBatchAsync` | Document processing |
| PII Detection & redaction | `RecognizePiiEntitiesBatchAsync` | GDPR compliance |
| Key Phrase Extraction | `ExtractKeyPhrasesBatchAsync` | Search indexing |
| Language Detection | `DetectLanguageBatchAsync` | Multilingual routing |
| Linked Entities | `RecognizeLinkedEntitiesBatchAsync` | Knowledge graph |
| Abstractive Summary | `AbstractSummaryAsync` | Report summarisation |
| Extractive Summary | `ExtractiveSummaryAsync` | Document highlights |
| Custom Classification | `ClassifyDocumentAsync` | Domain-specific routing |
| Healthcare NLP | `AnalyzeHealthcareEntitiesAsync` | Clinical text extraction |


↥ back to top

## # 11. AZURE TRANSLATOR


## Q. What is Azure Translator and what are its key features?

**Azure Translator** is a cloud-based neural machine translation service supporting 100+ languages and dialects. It provides text translation, transliteration, language detection, and dictionary lookup via a simple REST API.

```mermaid
flowchart LR
A[Source Text\n100+ Languages] --> B[Azure Translator API]
B --> C[Language Detection\nAuto-identify source]
B --> D[Text Translation\n100+ target languages]
B --> E[Transliteration\nScript Conversion]
B --> F[Document Translation\nPDF · DOCX · HTML]
B --> G[Dictionary Lookup\nBilingual Examples]
D --> H[Translated Text]
F --> I[Translated Document\nLayout Preserved]
```

**Key features:**

| Feature | Description |
|---------|-------------|
| **Text Translation** | Translate text in 100+ languages |
| **Document Translation** | Asynchronously translate entire documents (PDF, DOCX, HTML) preserving layout |
| **Custom Translator** | Fine-tune translation models with domain-specific parallel corpus |
| **Transliteration** | Convert text between scripts (e.g., Arabic → Latin) |
| **Language Detection** | Auto-detect source language |
| **Dictionary Lookup** | Bilingual dictionary with examples |

**Translating text with Python:**

```python
import requests, uuid, json, os

endpoint = "https://api.cognitive.microsofttranslator.com"
key = ""
location = "eastus"

def translate(texts: list[str], target_languages: list[str]) -> list:
url = f"{endpoint}/translate"
params = {"api-version": "3.0", "to": target_languages}
headers = {
"Ocp-Apim-Subscription-Key": key,
"Ocp-Apim-Subscription-Region": location,
"Content-type": "application/json",
"X-ClientTraceId": str(uuid.uuid4())
}
body = [{"text": t} for t in texts]
response = requests.post(url, params=params, headers=headers, json=body)
return response.json()

results = translate(
["Hello, how are you?", "Azure AI is amazing."],
["fr", "de", "ja"]
)

for item in results:
for translation in item["translations"]:
print(f"[{translation['to']}] {translation['text']}")
```

**Document Translation (async):**

```python
from azure.ai.translation.document import DocumentTranslationClient
from azure.core.credentials import AzureKeyCredential

client = DocumentTranslationClient("", AzureKeyCredential(""))

poller = client.begin_translation(
source_url="https://.blob.core.windows.net/source?",
target_url="https://.blob.core.windows.net/target-fr?",
target_language="fr"
)

result = poller.result()
for doc in result:
print(f"Translated: {doc.source_document_url} → Status: {doc.status}")
```


↥ back to top

## Q. How do you translate text and detect languages using Azure Translator in C#?

**Use case:** A multilingual customer-support portal in ASP.NET Core that auto-detects the language of incoming messages, translates them to English for agents, and sends responses back translated into the customer's language — using the `Azure.AI.Translation.Text` NuGet package.

**Install the NuGet packages:**

```bash
dotnet add package Azure.AI.Translation.Text
dotnet add package Azure.AI.Translation.Document
```

**Text translation and language detection (C#):**

```csharp
using Azure;
using Azure.AI.Translation.Text;

var client = new TextTranslationClient(
new AzureKeyCredential(""),
region: "eastus"
);

// ─── 1. DETECT LANGUAGE ───────────────────────────────────────────────────────
string inputText = "Azure AI はエンタープライズ アプリケーションを変革しています。";

Response> detectResponse =
await client.DetectLanguageAsync(new[] { new DetectLanguageInput(inputText) });

DetectedLanguage detected = detectResponse.Value[0];
Console.WriteLine($"Detected language : {detected.Language} (confidence: {detected.Score:P1})");

// ─── 2. TRANSLATE TO MULTIPLE LANGUAGES ──────────────────────────────────────
string[] targetLanguages = ["en", "fr", "de", "es"];

Response> translateResponse =
await client.TranslateAsync(targetLanguages, new[] { new TextTranslationInput(inputText) });

foreach (TranslatedTextItem item in translateResponse.Value)
{
Console.WriteLine($"\nSource detected: {item.DetectedLanguage?.Language}");
foreach (Translation translation in item.Translations)
Console.WriteLine($" [{translation.To}] {translation.Text}");
}

// ─── 3. TRANSLATE WITH EXPLICIT SOURCE LANGUAGE ──────────────────────────────
Response> explicitResponse = await client.TranslateAsync(
targetLanguages: ["en"],
content: new[] { new TextTranslationInput("Bonjour, comment puis-je vous aider?") },
sourceLanguage: "fr"
);

Console.WriteLine($"\nFR → EN: {explicitResponse.Value[0].Translations[0].Text}");

// ─── 4. TRANSLITERATION (script conversion) ───────────────────────────────────
Response> translitResponse =
await client.TransliterateAsync(
language: "ja",
fromScript: "Jpan", // Japanese script
toScript: "Latn", // Latin script (romaji)
content: new[] { new TransliterateTextInput("こんにちは") }
);

Console.WriteLine($"\nTransliteration: {translitResponse.Value[0].Text}");

// ─── 5. DICTIONARY LOOKUP ─────────────────────────────────────────────────────
Response> dictResponse =
await client.LookupDictionaryEntriesAsync(
sourceLanguage: "en",
targetLanguage: "es",
content: new[] { new DictionaryLookupInput("amazing") }
);

foreach (DictionaryLookupItem item in dictResponse.Value)
{
Console.WriteLine($"\nDictionary entries for '{item.NormalizedSource}':");
foreach (DictionaryTranslation entry in item.Translations.Take(3))
Console.WriteLine($" {entry.NormalizedTarget,-20} (confidence: {entry.Confidence:P0})");
}
```

**Async document translation (C#):**

```csharp
using Azure.AI.Translation.Document;

var docClient = new DocumentTranslationClient(
new Uri("https://.cognitiveservices.azure.com/"),
new AzureKeyCredential("")
);

// Translate all documents in a Blob container from English to French
var translationInputs = new List
{
new DocumentTranslationInput(
sourceUri: new Uri("https://.blob.core.windows.net/source-docs?"),
targetUri: new Uri("https://.blob.core.windows.net/target-fr?"),
targetLanguageCode: "fr"
)
};

DocumentTranslationOperation operation =
await docClient.StartTranslationAsync(translationInputs);

await operation.WaitForCompletionAsync();

Console.WriteLine($"Status : {operation.Status}");
Console.WriteLine($"Created : {operation.CreatedOn}");
Console.WriteLine($"Last updated : {operation.LastModified}");

await foreach (DocumentStatusResult doc in operation.GetAllDocumentStatusesAsync())
{
Console.WriteLine($" {Path.GetFileName(doc.SourceDocumentUri.ToString()),-40} " +
$"→ {doc.Status,-15} ({doc.TranslatedToLanguageCode})");
}
```

**Azure Translator capabilities in .NET:**

| Feature | SDK method | Notes |
|---------|-----------|-------|
| Text translation | `TranslateAsync` | 100+ languages, up to 50k chars/request |
| Language detection | `DetectLanguageAsync` | Returns language + confidence score |
| Transliteration | `TransliterateAsync` | Script-to-script conversion |
| Dictionary lookup | `LookupDictionaryEntriesAsync` | Bilingual dictionary |
| Dictionary examples | `LookupDictionaryExamplesAsync` | Contextual usage examples |
| Supported languages | `GetSupportedLanguagesAsync` | Dynamic language list |
| Document translation | `StartTranslationAsync` | PDF, DOCX, HTML, PPTX — async batch |


↥ back to top

## # 12. AZURE SPEECH SERVICE


## Q. What capabilities does Azure Speech Service provide?

**Azure Speech Service** offers a comprehensive set of speech AI capabilities for converting audio to text, text to audio, translating spoken language, and verifying speaker identity.

**Core features:**

| Feature | Description |
|---------|-------------|
| **Speech-to-Text (STR)** | Real-time and batch transcription with custom acoustic/language models |
| **Text-to-Speech (TTS)** | Neural voices (400+) in 140+ languages; custom neural voices |
| **Speech Translation** | Real-time translation of spoken audio to another language |
| **Speaker Recognition** | Verify or identify a speaker from their voice |
| **Pronunciation Assessment** | Score pronunciation accuracy (for language learning) |
| **Custom Speech** | Fine-tune STT on domain-specific vocabulary |
| **Custom Neural Voice** | Create a branded synthetic voice |

**Real-time speech-to-text example:**

```python
import azure.cognitiveservices.speech as speechsdk

speech_config = speechsdk.SpeechConfig(
subscription="",
region="eastus"
)
speech_config.speech_recognition_language = "en-US"

audio_config = speechsdk.audio.AudioConfig(use_default_microphone=True)
recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config)

print("Speak into your microphone...")
result = recognizer.recognize_once_async().get()

if result.reason == speechsdk.ResultReason.RecognizedSpeech:
print(f"Recognized: {result.text}")
elif result.reason == speechsdk.ResultReason.NoMatch:
print("No speech could be recognized.")
elif result.reason == speechsdk.ResultReason.Canceled:
print(f"Canceled: {result.cancellation_details.reason}")
```

**Neural Text-to-Speech:**

```python
speech_config = speechsdk.SpeechConfig(subscription="", region="eastus")
speech_config.speech_synthesis_voice_name = "en-US-JennyNeural"

synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config)

ssml = """