Brian McKeiver's Blog

Building a Kentico E-Commerce Chat Bot - Part 4


This is part 4 of my blog post series, Building a Kentico E-commerce Chat Bot. Make sure that you start the series by reading part 1. Today we will review the Language Understanding Intelligent Service (LUIS) aspect of the solution. During the review we will see how to create and train our bot to communicate with humans in a smart way.


Configuring LUIS and Intent

Now that we have our basic bot template setup we need to let LUIS know about it. LUIS is a Language Understanding Intelligent Service, which offers a fast and effective way of adding language understanding to applications. With LUIS, you can use pre-existing models from Microsoft Bing and Cortana whenever they suit your purposes and when you need specialized models, LUIS guides you through the process of quickly building them. LUIS is a part of Microsoft Cognitive Services.

Browse over to next. You should see a list of your LUIS apps. I would take this opportunity to rename the automatically generated name that Azure came up with for you. You can click the edit button (pencil icon) of the row to rename it to something you will remember. I just renamed mine the same as my Bot name.


My LUIS Apps


After you have renamed the app, go ahead and click the new name to get into the app properties. This is where we will add our first Intent. Intent is how LUIS understands the English language. 


Add LUIS Intent


Click on Add Intent and create the new Intent to match the code from your Bot template: MyIntent.


New LUIS Intent


Once you have the Intent created, you need to create some Utterances. Utterances are the phrases that represent examples of user queries or commands that your application is expected to receive and interpret. I am not going to go step by step through this, as the documentation on the site already has it all. 


New LUIS Intent Utterances


If your utterances contain the Entity you are looking for in them, you can map the part of the phrase that is the actual entity. Hover your mouse of the noun that represents the entity and tag it as so. You may want to create the Entity ahead of time on the Entities tab, but that is optional. Remember normal things like email and name are already prebuilt entities (you won't need to create those from scratch). I actually used the prebuilt entity email and created a custom entity to represent the billing zip code of the customer for my bot.


LUIS Utterances and Entity


Once you have your intent's utterances tagged with your entities, you are ready to train your LUIS app. Click the Train & Test side menu item, and then the Train Application button. Training your application allows the LUIS to create a model. LUIS generalizes from the examples you have labeled, and develops code to recognize relevant intents and entities in the future, thus improving its classification accuracy. This is the "understanding" part of the equation. It is what makes your bot smart. The more you chat with it, the more the model learns, and easier it is for the LUIS service to understand the intent of the human language.


Train LUIS Application


As you can see in the screen shot above. The longer sentence of "I'd like to check my order history" is closer is matched as a 1 value for the top scoring intent, while other intents only match it at a score of 0.07.

Lastly, you need to Publish your app, via the Publish App sidebar menu item. Once you do that you will find the Endpoint Url to access your new app.


Publish LUIS Application



What it Means to the Code

After you have the LUIS application setup and get your Endpoint Url you can test out the raw response your app gives based on certain queries via the browser. Click on the url as it is in the above screen shot and use the q= parameter to enter in different phrases. You can see how the service matches your query parameter to the correct intent.


LUIS API Query Response Example




I'm honestly just scratching the surface of the very basics of LUIS in this walkthrough. Microsoft is continually improving the service and adding new things like Prebuilt domains and Features that the LUIS application can take advantage of to become even smarter. This is such an interesting part of the solution that I could spend a lot more time on it, but if I do this blog post series will never complete. For that reason, I am going to move on.

Ok to recap, in part 1 we introduced the idea of chatbots and all of the technologies we need to power such a smart bot. In part 2 we reviewed the Kentico e-commerce side of the solution, and in part 3 we created the required Azure components including the main Azure Bot Service. This was part 4 of the series, on how to make our bot smart by utilizing LUIS. In the final post of the series we are going to put all the puzzle pieces together and create our working chat bot for a Kentico e-commerce site. Stay tuned.