Overview

This exercise demonstrates how to create a conversational language understanding model using Azure AI Language Service. The model interprets user input, predicts intent, and identifies relevant entities.


Steps & Configuration Details

1. Provision an Azure AI Language Resource

  • Open Azure Portal (https://portal.azure.com) and sign in.
  • Select Create a resource → Search for Language Service → Click Create.
  • Configuration Items:
    • Subscription: Your Azure subscription.
    • Resource Group: Select or create a resource group.
    • Region: Choose from:
      • East US
      • West US 3
      • North Europe
      • South Central US
    • Name: Enter a unique name.
    • Pricing Tier: F0 (Free) or S (Standard).
    • Responsible AI Notice: Agree.

After provisioning, navigate to Keys and Endpoint in the Resource Management section.


2. Create a Conversational Language Understanding Project

  • Open Language Studio (https://language.cognitive.azure.com) and sign in.
  • Select Conversational Language UnderstandingCreate a project.
  • Configuration Items:
    • Azure Subscription: Your Azure subscription.
    • Resource Type: Language.
    • Resource Name: The Azure AI Language resource created earlier.
    • Project Name: Clock
    • Primary Language: English
    • Enable Multiple Languages: No
    • Description: Natural language clock

3. Define Intents

  • Navigate to Schema DefinitionIntents.
  • Add the following intents:
    • GetTime
    • GetDay
    • GetDate
  • Label each intent with sample utterances:
    • GetTime: "What time is it?", "Tell me the time."
    • GetDay: "What day is it?", "What's the day today?"
    • GetDate: "What date is it?", "What's today's date?"

4. Add Entities

  • Learned Entity: Location
    • Example utterances:
      • "What time is it in London?" → Label "London" as Location
      • "Tell me the time in Paris?" → Label "Paris" as Location
  • List Entity: Weekday
    • Example values:
      • "Monday" → Synonyms: "Mon"
      • "Tuesday" → Synonyms: "Tue", "Tues"
  • Prebuilt Entity: Date
    • Example utterances:
      • "What day was 01/01/1901?" → Label "01/01/1901" as Date
      • "What day will it be on Dec 31st 2099?" → Label "Dec 31st 2099" as Date

5. Train and Deploy the Model

  • Navigate to Training JobsStart a Training Job.
  • Configuration Items:
    • Model Name: Clock
    • Training Mode: Standard
    • Data Splitting: Default settings.
  • Deploy the model:
    • Deployment Name: production
    • Model: Clock
  • Test the model:
    What's the time in Edinburgh?
    
    • Expected intent: GetTime
    • Expected entity: Location = Edinburgh

6. Configure Your Application

  • Clone the repository:
    git clone https://github.com/MicrosoftLearning/mslearn-ai-language
    
  • Open the folder in Visual Studio Code.
  • Install dependencies:
    • C#:
      dotnet add package Azure.AI.Language.Conversations --version 1.1.0
      
    • Python:
      pip install azure-ai-language-conversations
      
  • Open the configuration file:
    • C#: appsettings.json
    • Python: .env
  • Update Configuration Values:
    • Azure AI Language Endpoint
    • API Key
  • Save the configuration file.

7. Add Code to Query the Model

  • Open the code file:
    • C#: Program.cs
    • Python: clock-client.py
  • Add references:
    • C#:
      using Azure;
      using Azure.AI.Language.Conversations;
      
    • Python:
      from azure.core.credentials import AzureKeyCredential
      from azure.ai.language.conversations import ConversationAnalysisClient
      
  • Create the AI Language client:
    • C#:
      Uri endpoint = new Uri(predictionEndpoint);
      AzureKeyCredential credential = new AzureKeyCredential(predictionKey);
      ConversationAnalysisClient client = new ConversationAnalysisClient(endpoint, credential);
      
    • Python:
      client = ConversationAnalysisClient(ls_prediction_endpoint, AzureKeyCredential(ls_prediction_key))
      
  • Submit a query:
    • C#:
      var projectName = "Clock";
      var deploymentName = "production";
      var data = new {
          analysisInput = new {
              conversationItem = new {
                  text = userText,
                  id = "1",
                  participantId = "1",
              }
          },
          parameters = new {
              projectName,
              deploymentName,
              stringIndexType = "Utf16CodeUnit",
          },
          kind = "Conversation",
      };
      Response response = await client.AnalyzeConversationAsync(RequestContent.Create(data));
      
    • Python:
      query = userText
      result = client.analyze_conversation(
          task={
              "kind": "Conversation",
              "analysisInput": {
                  "conversationItem": {
                      "participantId": "1",
                      "id": "1",
                      "modality": "text",
                      "language": "en",
                      "text": query
                  },
                  "isLoggingEnabled": False
              },
              "parameters": {
                  "projectName": "Clock",
                  "deploymentName": "production",
                  "verbose": True
              }
          }
      )
      

8. Run Your Application

  • C#:
    dotnet run
    
  • Python:
    python clock-client.py
    
  • Example prompt:
    What time is it in London?
    
  • The response should display the predicted intent and detected entities.

9. Clean Up

  • Delete Azure resources to avoid unnecessary costs:

This summary captures the essential steps while highlighting all configuration items and code references required for creating a conversational language understanding model using Azure AI Language.

Related Posts