Introducing the next generation of the Conversational Language Understanding client library

Nayer Wanas

The need to develop intelligent solutions that understand short text has grown. With more complex solutions being developed, the need to improve and enable the development of these complicated scenarios is growing. These scenarios range from intelligent customer support bots to standalone systems that understand user input. To tackle such scenarios, the Language Cognitive Service has decided to use the multilingual transformer-based model. Applying this model, users will realize a significant improvement in performance compared to the already existing Language Understanding Service (LUIS).

The new preview Conversational Language Understanding (CLU) service also supports the ability to create orchestration projects. These orchestration projects are powered by the multilingual Dual Transformer Encoder (DTE). The DTE allows you to configure a project to route to multiple customizable language services. These services include question-answering knowledge bases, other CLU projects, and classic LUIS apps.

Get more info on CLU service

The CLU Cognitive Service is now in preview!

Read all about the CLU service and get started with the libraries and Quickstart.

To understand how a user might use CLU to analyze a conversational utterance in a chatbot scenario, consider the following example. The user of the chatbot would provide a textual utterance as an input. This utterance could be a transcription from speech. This input utterance would be sent to a conversational endpoint as a synchronous operation along with the corresponding key and project name. These parameters can be stored in an environment variable, configuration setting, or any way that works for your app.

var endpoint = new Uri("https://myaccount.api.cognitive.microsoft.com");
var credential = new AzureKeyCredential("{api-key}");

var client = new ConversationAnalysisClient(endpoint, credential);

Let’s see some code on how the app might want to use this library. Although you can use any of our languages (.NET or Python), .NET is used for the provided examples. These libraries are currently in beta and support the new CLU service.

Analyze a conversation

Given an input utterance by the user, you could call the client as a synchronous operation to analyze the input for a given model name and deployment slot.

Response<AnalyzeConversationResult> response = client.AnalyzeConversation(
    "Menu",
    "production",
    "We'll have 2 plates of seared salmon nigiri.");

Console.WriteLine($"Top intent: {response.Value.Prediction.TopIntent}");

You could also provide an utterance in different languages to the same model to use the embedded multilingual power directly. To understand an utterance in a different language, you could send it as is. As an alternative, identify the language as a parameter when sending the utterance to the endpoint:

Response<AnalyzeConversationResult> response = client.AnalyzeConversation(
    "Menu",
    "production",
    "Tendremos 2 platos de nigiri de salmón braseado.");
{
    Language = "es"
}
Console.WriteLine($"Top intent: {response.Value.Prediction.TopIntent}");

Use an orchestration project to integrate several projects

Through an orchestration project in CLU, you can connect services that understand user input. You can also connect other CLU projects, custom Question Answering knowledge bases (QnA Maker v2), and LUIS apps. The orchestration project type will:

  • Route to the most appropriate project, KB, or app based on the connected services’ data.
  • Return the correct response.

First, call the orchestration app to obtain a prediction:

Response<AnalyzeConversationResult> response = client.AnalyzeConversation(
    "DomainOrchestrator",
    "production",
    "Where are the calories per recipe?");

OrchestratorPrediction orchestratorPrediction = 
    response.Value.Prediction as OrchestratorPrediction;

You can then access the project-specific result based on the returned JSON. For example, you could process a conversation using the following code:

string respondingProjectName = orchestratorPrediction.TopIntent;
TargetIntentResult targetIntentResult = orchestratorPrediction.Intents[respondingProjectName];

if (targetIntentResult.TargetKind == TargetKind.Conversation)
{
    ConversationTargetIntentResult cluTargetIntentResult = 
        targetIntentResult as ConversationTargetIntentResult;

    ConversationResult conversationResult = cluTargetIntentResult.Result;
    ConversationPrediction conversationPrediction = conversationResult.Prediction;

    if (!String.IsNullOrEmpty(conversationResult.DetectedLanguage))
    {
        Console.WriteLine($"Detected Language: {conversationResult.DetectedLanguage}");
    }

    Console.WriteLine($"Top Intent: {conversationResult.Prediction.TopIntent}");
    Console.WriteLine($"Intents:");
    foreach (ConversationIntent intent in conversationPrediction.Intents)
    {
        Console.WriteLine($"Intent Category: {intent.Category}");
        Console.WriteLine($"Confidence Score: {intent.ConfidenceScore}");
        Console.WriteLine();
    }

    Console.WriteLine($"Entities:");
    foreach (ConversationEntity entity in conversationPrediction.Entities)
    {
        Console.WriteLine($"Entity Text: {entity.Text}");
        Console.WriteLine($"Entity Category: {entity.Category}");
        Console.WriteLine($"Confidence Score: {entity.ConfidenceScore}");
        Console.WriteLine($"Starting Position: {entity.Offset}");
        Console.WriteLine($"Length: {entity.Length}");
        Console.WriteLine();
    }
}

You could also access a Question Answering response as follows:

string respondingProjectName = orchestratorPrediction.TopIntent;
TargetIntentResult targetIntentResult = orchestratorPrediction.Intents[respondingProjectName];

if (targetIntentResult.TargetKind == TargetKind.QuestionAnswering)
{
    QuestionAnsweringTargetIntentResult qnaTargetIntentResult = 
        targetIntentResult as QuestionAnsweringTargetIntentResult;

    KnowledgeBaseAnswers qnaAnswers = qnaTargetIntentResult.Result;

    Console.WriteLine("Answers: n");
    foreach (KnowledgeBaseAnswer answer in qnaAnswers.Answers)
    {
        Console.WriteLine($"Answer: {answer.Answer}");
        Console.WriteLine($"Confidence Score: {answer.ConfidenceScore}");
        Console.WriteLine($"Source: {answer.Source}");
        Console.WriteLine();
    }
}

More resources

For more information, see the following resources:

0 comments

Discussion is closed.

Feedback usabilla icon