In Lab 2 (basic dialogue management), you used a simplistic mapping
(called grammar
in the code) from user utterances to entities. In the
first task of this lab, you will replace this grammar with a
statistical NLU trained and deployed using Conversational Language
Understanding (CLU) in Azure.
Go to https://language.cognitive.azure.com/ and ensure that you are
signed in with your Azure account. Choose “Create new ->
Conversational language understanding”. As part of this, you may
need to create a new Azure language resource. Note that resource
names are unique across the entire Azure platform, so you may need
to include some arbitrary digits or numbers in it
(e.g. language_resource_57372
).
As project name, you can e.g. enter: appointment
.
In the “Schema definition” menu of your project you will find the option to create Intents and Entities. Intents are a result of automatic classification of sentences (or expressions) performed by a model/machine. In order to get the model to recognize your intents, you will have to train them first with examples of what sentences with such intents look like. The model will average those sentences to infer your intents. We won’t use entities until point (6).
- Example:
- Intent: Book a restaurant
- Example utterance: “I’d like to make a reservation for tonight.”
- Example utterance: “Find me a good Italian place nearby.”
First, create two intents, corresponding to “create a meeting” and “who is X” (X= name of a famous person). Make sure to use the same names for these intents as you do in your code. Then, choose “Data labeling” in the navigation menu to the left and add around 10 training examples for each intent. (At this stage, you can come up with examples on your own. You can improve the training data later.)
To train the model for the first time, choose “Training jobs” in the
navigation menu and select “Train a new model”. As model name, you can
choose appointment
. (When you re-train the model later on, select
“Overwrite an existing model”.)
In order to use your trained model in your dialogue system, you
first need to deploy it. Choose “Deploying a model” in the
navigation menu and then “Add deployment”. Again, as deployment name
you can choose appointment
. (When you re-train your model later on
and want to re-deploy it, overwrite the existing deployment name.)
After deploying, you can see the URL of your deployment by selecting
the model and clicking on “Get prediction URL”. You will need it in
step 4.3 below.
- Update SpeechState to the latest version:
yarn up speechstate
- Create a copy of
dm.js
:dm4.js
(for Lab 4). Inmain.js
modify the import:import { setupButton } from "./dm4.js";
- Configure your NLU by adding the following to your files:
- create a NLU_KEY const in your
azure.js
file and import it (together with your KEY). - In
dm4.js
, create the object “azureLanguageCredentials”:const azureLanguageCredentials = { endpoint: "" /** your Azure CLU prediction URL */, key: NLU_KEY /** reference to your Azure CLU key */, deploymentName: "" /** your Azure CLU deployment */, projectName: "" /** your Azure CLU project name */, };
- To your
settings
const add said object:const settings = { azureLanguageCredentials: azureLanguageCredentials /** global activation of NLU */, azureCredentials: azureCredentials, asrDefaultCompleteTimeout: 0, asrDefaultNoInputTimeout: 5000, locale: "en-US", ttsDefaultVoice: "en-US-DavisNeural", };
- create a NLU_KEY const in your
- Whenever you need to use Azure CLU, add the following parameter to
LISTEN
event.({ context }) => context.ssRef.send({ type: "LISTEN", value: { nlu: true } /** Local activation of NLU */, }),
This enables
RECOGNISED
events to contain NLU results (accessible viaevent.nluValue
).
Finally, you need to rewire the logic in your code to support 2 aforementioned intents.
Entities are specific names (named entities) such as locations, people, organizations… and other concepts such as emotions, opinions… and are used to extract meaningful information from sentences. A sentence such as “Get tickets for Taylor Swift’s concert in Sweden” could be classified as “Intent: Buy tickets” and have the entities “Artist: Taylor Swift”, “Country: Sweden”. You can read more about labeling here: https://learn.microsoft.com/en-us/azure/ai-services/language-service/conversational-language-understanding/how-to/tag-utterances?tabs=portal
To get started, go back to “Schema definition” and add the entities that you need. For example, in the case of the appointment intent, you can have entities such as: “meeting title”, “meeting time”, “yes/no”, etc. Again, entity names should correspond to those in your code.
There are two ways of creating entities: by the “Schema definition” menu or inside “Data labeling”.
- For the first option, you can select pre-built entities or give a list with your entities.
- For the last option, by hovering over a sentence that has been used/is going to be used as training for your intent, an opening square bracket will appear, this marks the start of the entity. After clicking, a closing square bracket will appear, then you can click to choose the end of what you consider an entity. By training the model with such labeled entities, the model will (try to) learn the pattern of what they are.
You can experiment and choose the most appropriate method for each entity.
Finally, you need to rewire the logic in your code to support entities. For “who is X” path, in response to user’s query you will need to provide some basic information about the person (i.e. a celebrity).
Based on insights from testing your own system, and from having the system tested by peer students, you should now try to improve NLU coverage. There are no specific requirements concerning how much coverage you need. You are not expected to spend more than an hour on this task.
Export your NLU project by choosing “Projects” in the navigation menu to the left, then select your project and click Export. (You might need to unblock a pop-up window.) Save the exported content as a JSON file (.json extension).
Commit your changes (new file dm4.js
) and push them to your repository
(your fork of this repository). This will update your pull
request. Rename the pull request to e.g. “Labs 2,3,4 submission”.
Submit:
- link to your pull request
- your exported NLU model (JSON file)