Custom Language Models
When prebuilt NLP features aren't specific enough for your domain, you build custom models. This topic covers CLU (Conversational Language Understanding — the LUIS replacement), Custom NER, Custom Text Classification, Custom Question Answering, and Azure Bot Service integration.
Custom model terms — defined before code
The replacement for LUIS (Language Understanding). A custom model that identifies the user's intent (what they want to do) and extracts entities (key information) from natural language utterances. Trained on your labelled examples. Available in Azure AI Language.
What the user wants to accomplish. "Book me a flight to Paris" → intent: BookFlight. "What's the weather like?" → intent: GetWeather. CLU classifies user utterances into your defined intents. Each utterance maps to exactly one intent.
Key information extracted from the utterance. In "Book a flight to Paris on March 15th" — entities: {destination: "Paris"}, {date: "March 15th"}. Entities have types you define. They are the "slots" the intent needs filled to take action.
A sample input sentence used to train CLU. You provide many example utterances per intent, each labelled with the correct intent and any entities. The model learns to generalise from these examples to new, unseen utterances.
A special CLU intent for utterances that don't match any of your defined intents. Always add a None intent with examples of out-of-scope or irrelevant utterances. Without it, the model may incorrectly classify everything into one of your defined intents.
A custom model for Named Entity Recognition. When the prebuilt NER categories (Person, Location, etc.) are not specific enough — you define your own entity types and train on labelled documents. Example: LegalCase, ContractClause, RegulatoryBody for legal documents.
A custom model for classifying documents into your own categories. Two modes: single-label (each document belongs to exactly one category) and multi-label (a document can belong to multiple categories). Trained on your labelled document examples.
A custom knowledge base that answers questions in natural language. You provide question-answer pairs (from FAQs, manuals, or web URLs). The model uses semantic similarity to find the best matching answer to a user's question. Replaced QnA Maker.
The collection of question-answer pairs in a Custom Q&A project. Sources: manually entered pairs, imported FAQ documents, or URLs of web pages with Q&A content. The model indexes these and finds relevant answers at runtime.
Azure's platform for building, deploying, and managing conversational bots. Bots are logic applications that connect to messaging channels (Teams, webchat, Slack, etc.). Usually connected to CLU for intent recognition and Custom Q&A for answering FAQs.
The programming SDK for building bots in Python, C#, JavaScript, or Java. You write dialog logic, state management, and channel integration code. Works with Azure Bot Service for hosting and channels.
A modular conversation flow component. A bot is composed of dialogs — each dialog handles a specific conversation scenario. Dialogs can stack, call each other, and return results. Types: WaterfallDialog (step-by-step), ComponentDialog (reusable), AdaptiveDialog.
Understanding what users want to do
LUIS (Language Understanding) was deprecated. The exam refers to CLU (Conversational Language Understanding) for all intent/entity recognition tasks. CLU is part of the Azure AI Language service — same endpoint, same SDK. If you see a question about building a chatbot that understands user intents → CLU.
A telephone operator hears "I need to cancel my subscription" and routes the call to the cancellation team. They don't need to understand everything — just the intent (cancel) and who it affects (subscription). CLU is that operator — it classifies user messages into intents and extracts key information (entities) so your code can take the right action.
Building a CLU model — the process
Language Studio (language.cognitive.azure.com) → Create CLU project → Add intents (BookFlight, GetWeather, Cancel, None) → Add entity types (destination, date, duration).
For each intent, add 15–30+ example utterances and label entities within them. "Book a flight to [Paris]destination for [next Monday]date" → intent: BookFlight. Minimum 5 utterances per intent recommended.
Language Studio → Train model → Select training type (standard or advanced). The service trains on your labelled examples. Evaluation metrics: Precision, Recall, F1 score per intent.
Review confusion matrix — which intents are being confused with each other? Add more utterances to low-scoring intents. Deploy to production slot when satisfied.
Python — Calling CLU from Python
Install: pip install azure-ai-language-conversations
import os
from azure.ai.language.conversations import ConversationAnalysisClient
from azure.core.credentials import AzureKeyCredential
# ── Create the CLU client ──────────────────────────────────────────────
# CLU is part of Azure AI Language — same cognitiveservices.azure.com endpoint
clu_client = ConversationAnalysisClient(
endpoint = os.environ.get("LANGUAGE_ENDPOINT"), # cognitiveservices.azure.com
credential = AzureKeyCredential(os.environ.get("LANGUAGE_KEY"))
)
# ── Analyse an utterance ───────────────────────────────────────────────
user_utterance = "I'd like to book a flight to Paris for next Friday"
# analyze_conversation() sends the utterance to your CLU model for classification
with clu_client: # "with" ensures the client is properly closed
result = clu_client.analyze_conversation(
task = {
"kind": "Conversation", # Task type for CLU
"analysisInput": {
"conversationItem": {
"id" : "1",
"participantId": "user1",
"text" : user_utterance # The user's message
}
},
"parameters": {
"projectName" : "FlightBookingCLU", # Your CLU project name
"deploymentName": "production", # Your deployment slot
"verbose" : True # Return all intent scores
}
}
)
# ── Extract the prediction ─────────────────────────────────────────────
prediction = result["result"]["prediction"]
# Top intent — the intent with the highest confidence score
# This is what you act on in your application
top_intent = prediction["topIntent"] # e.g. "BookFlight"
top_score = prediction["intents"][0]["confidence"] # e.g. 0.97
print(f"Intent: {top_intent} (confidence: {top_score:.2f})")
# Entities — key information extracted from the utterance
for entity in prediction.get("entities", []):
# entity["category"]: the entity type you defined (e.g. "destination")
# entity["text"]: the actual text extracted (e.g. "Paris")
# entity["confidenceScore"]: how confident (0-1)
print(f" Entity: {entity['category']} = '{entity['text']}' "
f"({entity['confidenceScore']:.2f})")
# ── Use the result in your application ────────────────────────────────
# Route to the right action based on the top intent
if top_intent == "BookFlight":
print("→ Routing to flight booking handler")
elif top_intent == "GetWeather":
print("→ Routing to weather information handler")
elif top_intent == "None":
print("→ Utterance not understood — show help menu")
Building knowledge bases for FAQ bots
Custom Question Answering (the replacement for QnA Maker) lets you build a knowledge base from FAQ documents and web pages. Users ask questions in natural language and the service finds the best matching answer.
Custom Q&A is like a librarian who has memorised your entire FAQ document. When a customer asks "How do I reset my password?" — even if they phrase it as "I forgot my password" or "Can't log in, need password help" — the librarian finds the right answer because they understand the question's meaning, not just the exact words.
Building a Custom Q&A knowledge base
| Source Type | What it is | Best for |
|---|---|---|
| Manual entry | You type Q&A pairs directly in Language Studio | Small knowledge bases, frequently updated content |
| File import | Upload Word/PDF/Excel/TSV files containing Q&A pairs | Existing FAQ documents, product manuals |
| URL import | Provide URLs of web pages with FAQ content — the service extracts Q&A pairs | Websites with existing FAQ pages (extracts automatically) |
Python — Calling Custom Q&A
import os
from azure.ai.language.questionanswering import QuestionAnsweringClient
from azure.core.credentials import AzureKeyCredential
# QuestionAnsweringClient connects to your Custom Q&A knowledge base
qa_client = QuestionAnsweringClient(
endpoint = os.environ.get("LANGUAGE_ENDPOINT"),
credential = AzureKeyCredential(os.environ.get("LANGUAGE_KEY"))
)
user_question = "How do I cancel my subscription?"
with qa_client:
result = qa_client.get_answers(
question = user_question,
project_name = "CustomerSupportKB", # Your Q&A project name
deployment_name = "production", # Deployed slot
top = 3 # Return top 3 matching answers
)
# result.answers is a list sorted by confidence (highest first)
for answer in result.answers:
print(f"Confidence: {answer.confidence:.2f}")
print(f"Answer: {answer.answer}")
print(f"Source: {answer.source}")
print()
# Use the top answer if confidence is above a threshold
# Confidence below 0.3-0.4 usually means no good match was found
if result.answers[0].confidence > 0.4:
print(f"Bot response: {result.answers[0].answer}")
else:
print("Bot response: I'm not sure I have an answer for that. Can I connect you with a human agent?")
Building custom extractors and classifiers
Custom NER
When you need to extract entity types not in the prebuilt NER model. Define your own categories (LegalCase, ContractDate, RegulatoryBody) and train on labelled documents. Follow the standard Azure AI Language custom model workflow: create → label → train → evaluate → deploy.
Custom Text Classification
Classify documents into your own categories. Two modes:
Single-label: each document gets exactly one label (Spam / Not Spam, or Positive / Negative / Neutral).
Multi-label: a document can have multiple labels (a news article can be both "Technology" and "Business").
"Company wants to extract person names and dates from emails." → Prebuilt NER (already handles these)
"Company wants to extract contract clause numbers and party names from legal documents." → Custom NER (domain-specific entities)
"Company wants to classify support tickets as billing, technical, or account." → Custom Text Classification (single-label)
"Company wants to tag news articles with all relevant categories." → Custom Text Classification (multi-label)
Building conversational bots
Azure Bot Service is the platform for hosting and deploying bots. The Bot Framework SDK is used to write the bot logic. Together they integrate with CLU, Custom Q&A, and messaging channels like Teams, webchat, Slack, and email.
The Bot Framework SDK is the entire building — floor plan, rooms, communication systems, reception desk. CLU is the knowledge in the receptionist's head — which department handles what, what customer requests mean. Custom Q&A is the FAQ manual on the desk. Together they create a complete customer service experience. The building alone doesn't know what visitors want; the knowledge alone has no building to operate in.
Bot architecture — how the pieces connect
| Component | Role | Where it lives |
|---|---|---|
| Channel | Where users interact — Teams, webchat, Slack, SMS | Configured in Azure Bot Service |
| Azure Bot Service | Hosted endpoint that receives messages from channels and forwards to your bot code | Azure portal resource |
| Bot Framework SDK | Your Python code — handles turns, dialogs, state, responses | Azure App Service (or Container) |
| CLU | Classifies user utterances into intents and extracts entities | Azure AI Language resource |
| Custom Q&A | Answers FAQ-style questions from knowledge base | Azure AI Language resource |
Custom Language Models — what the exam tests
1. CLU = LUIS replacement — If the exam mentions LUIS or asks about intent/entity recognition for a chatbot → CLU (in Azure AI Language). No more separate LUIS resource.
2. Custom Q&A = QnA Maker replacement — Same concept, now inside Azure AI Language. Both CLU and Custom Q&A use the same Language endpoint.
3. Always include a None intent in CLU — Without it the model classifies all utterances into your defined intents even when none match.
4. Single-label vs multi-label classification — Exam scenario: "an article can belong to both Technology and Business" → multi-label. "Each ticket is either billing or technical, never both" → single-label.
5. Custom Q&A confidence threshold — Always check the confidence score before presenting an answer. Below ~0.4 typically means no good match — offer escalation to a human agent instead.
Test your understanding
Which Azure AI Language feature should be used to identify what the customer wants?
B is correct. CLU is designed exactly for this scenario — identifying user intents and extracting entities in a conversational context. You define intents (ReturnOrder, TrackDelivery, etc.), provide labelled utterance examples, and train the model to classify new messages. It also extracts entities (like order numbers) from those messages. Custom Text Classification (A) classifies documents into categories but doesn't extract entities. Custom Q&A (C) answers questions from a knowledge base — not for routing/intent detection. Prebuilt NER (D) would find order numbers but not identify the overall intent/action.
You've finished Implement Natural Language Processing Solutions (15–20% of exam). Reinforce with flashcards and quiz, then move to Part 5.