6.3.1.3. CLU Training and Deployment
6.3.1.3. CLU Training and Deployment
Train your model with labeled utterances, then deploy to production for real-time predictions.
Building on the capability spectrum from Section 1.1, CLU represents the "customizable" level for language understanding—you define intents and entities specific to your domain.
💡 First Principle: Users don't speak in commands—they say "Book me a flight to Seattle next Tuesday" not "BOOK_FLIGHT destination=Seattle date=Tuesday." CLU bridges this gap by learning to extract intent (what they want: BookFlight) and entities (the parameters: Seattle, Tuesday) from natural language. The exam tests whether you know CLU is for custom intent recognition—when pre-built capabilities don't cover your domain's specific intents.
🔧 Implementation Reference: CLU
| Item | Value |
|---|---|
| Package | azure-ai-language-conversations |
| Class | ConversationAnalysisClient |
| Method | analyze_conversation() |
| Endpoint | POST /language/:analyze-conversations |
Request Body:
{
"kind": "Conversation",
"analysisInput": {
"conversationItem": {"id": "1", "participantId": "user", "text": "Book a flight to Paris"}
},
"parameters": {"projectName": "FlightBooking", "deploymentName": "production"}
}
Response Structure:
{
"result": {
"prediction": {
"topIntent": "BookFlight",
"entities": [{"category": "destination", "text": "Paris"}]
}
}
}
Testable Pattern:
from azure.ai.language.conversations import ConversationAnalysisClient
from azure.core.credentials import AzureKeyCredential
client = ConversationAnalysisClient(endpoint, AzureKeyCredential(key))
result = client.analyze_conversation(
task={
"kind": "Conversation",
"analysisInput": {
"conversationItem": {
"id": "1",
"participantId": "user",
"text": "Book a flight to Paris tomorrow"
}
},
"parameters": {
"projectName": "FlightBooking",
"deploymentName": "production"
}
}
)
top_intent = result["result"]["prediction"]["topIntent"]
confidence = result["result"]["prediction"]["intents"][0]["confidenceScore"]
entities = result["result"]["prediction"]["entities"]
Error Handling Pattern:
from azure.ai.language.conversations import ConversationAnalysisClient
from azure.core.exceptions import HttpResponseError, ResourceNotFoundError
try:
result = client.analyze_conversation(task=conversation_task)
# Check confidence threshold
confidence = result["result"]["prediction"]["intents"][0]["confidenceScore"]
if confidence < 0.7:
# Low confidence - may need clarification from user
logging.warning(f"Low intent confidence: {confidence}")
except ResourceNotFoundError:
# Project or deployment not found
logging.error("CLU project or deployment not found. Verify names are correct.")
except HttpResponseError as e:
if e.status_code == 400:
# Invalid request - check conversation item format
logging.error("Invalid conversation request format")
elif e.status_code == 429:
# Rate limited
time.sleep(int(e.response.headers.get("Retry-After", 60)))
CLI Equivalent (REST):
curl -X POST "https://{endpoint}/language/:analyze-conversations?api-version=2023-04-01" \
-H "Ocp-Apim-Subscription-Key: {key}" \
-H "Content-Type: application/json" \
-d '{
"kind": "Conversation",
"analysisInput": {
"conversationItem": {
"id": "1",
"participantId": "user",
"text": "Book a flight to Paris"
}
},
"parameters": {
"projectName": "FlightBooking",
"deploymentName": "production"
}
}'