Building a Conversational Bot using LUIS

Nibedita Dutta Last Updated : 27 Apr, 2021
5 min read
This article was published as a part of the Data Science Blogathon.

Introduction

Companies are increasingly inclining towards having chatbots for their businesses for multiple applications. Amongst the numerous API providers in the chatbot landscape that focus on Natural Language Programming (NLP) and Natural Language Understanding (NLU), I would be demonstrating how to build a chatbot that can automate the process of scheduling interviews using Microsoft’s LUIS.

Scheduling interviews comes with a lot of challenges like finding out a suitable slot for everyone, including other participants, rescheduling an interview on a participant’s request, etc. To address all the above challenges, a bot for handling such requests would bring in operational efficiency that would reduce the time and efforts of employees.

 

Understanding how LUIS works

Language Understanding Intelligence Service (LUIS) – an API within Microsoft Cognitive Services, helps in enabling an application to understand what a user is wanting to say. This is achieved by LUIS by leveraging Natural Language Understanding (NLU) for transforming the words in a sentence into a machine-readable meaning representation. NLU, a subset of Natural Language Processing (NLP), helps in fishing out things like intent, timing, locations, and sentiments from a user’s query.

Using LUIS, we will see how to build a model that will aid in natural language understanding in our applications. At the core of a LUIS model are intents and entities. Intent refers to the motive behind a query that the user inputs while an entity represents an object that is related to the defined intents.

Understanding how LUIS works

For instance, consider a chatbot intended for automating the process of scheduling meetings. In this case, we would need LUIS to identify intents like ‘scheduleMeeting’, ‘checkMeetingTimes’ and recognize entities like ‘meetingParticipants’, ‘meetingRoom’ etc. If the user inputs – “Please schedule a meeting with Raj”, the goal of LUIS is to identify the intent as ‘scheduleMeeting’ and identify the entity – ‘meetingParticipants’ as ‘Raj’.

 

Getting started on LUIS

The first step for using LUIS is to create a Microsoft account using which you can sign into https://www.luis.ai. After signing in, you can create a new app and then start entering the desired intents that you would like to have on your bot and the entities that you would like LUIS to identify in them.
Since we would be creating a bot for scheduling meetings here, a few of the intents that I have created are around booking meetings, checking availability, checking the status of a meeting as shown in the figure below.

   Getting started on LUIS

In each of these intents, you would need to create samples of queries and define entities in each of them. These sample queries and defined entities would be needed to train your LUIS model so that the model identifies the intents and entities when a user queries on the bot to be able to give a relevant response based on the query.

For instance, under the intent of ‘Book Meeting’, I created sample queries like – ‘Please book a meeting with Mithila from 9 am to 10.30 am on 10th April 2021.’ In this query, I defined user (Mithila), startTime (9 am), endTime (10.30 am), date (10th April 2021) as the entities. As shown in the figure below, I trained the model with some similar queries.

luis model training

Publishing your app on LUIS

Post defining all the intents and entities, you can train your model and then test the model to see if all the intended intents and queries are correctly identified. If the model can correctly identify all the intents and queries, you can publish the app. You can invoke the LUIS API using the endpoint URL that you get on publishing the app.

Publishing your app on LUIS

Building up the backend

Since the objective of our bot is to schedule meetings for employees, we need to have an access to their calendars. We started out by creating some dummy mail IDs (Gmail IDs and outlook mail IDs) for creating an employee base. We leveraged the Cronofy API for developers to get access to the calendars of these dummy mail IDs.

Let us take an example of a particular intent to demonstrate how the bot integrates with the backend code. For instance, if a user queries on booking a meeting with an employee called ‘Raj’ today at 10 am, LUIS first identifies the intent as ‘scheduleMeeting’ and entities as ‘meetingParticipant’,’date’and ‘time’. Based on the intent and entity identified by LUIS, we wrote a python function to first get the mail address of the entity ‘meetingParticipant’ from a database (that could be a CSV file) and then to trigger the Cronofy API for this mail address to check if the employee’s calendar is free and subsequently to send a meeting invitation to the employee using the SMTP module in Python. Once the code is executed, LUIS responds back to the user saying ‘Meeting invitation has been successfully sent to Raj’. On the other hand, if the employee’s calendar is busy during this schedule, the bot returns the response ‘Sorry, Raj is busy during this time.

We wrote similar functions in the backend for other corresponding intents. The intent ‘MeetingStatus’ would check if all the participants have accepted the meeting or not again by reading the calendars of all the meeting participants and checking their response to the meeting utilizing Cronofy API. Similarly, the availability of a person at a particular time on a certain day was checked by the intent ‘checkAvailablity’. The intent ‘SuggestTime’ would suggest meeting times with a list of participants based on their availabilities on a particular day. You can find the whole Github code here.

 

Testing & debugging your bot

In our case, we created a python app that invokes the LUIS API when a user queries on a bot channel (like Facebook Messenger, Telegram, Slack, etc.). You can test and debug how the chatbot performs while building your app using a desktop application called Microsoft’s Bot Framework Emulator. The Emulator shows the messages as they would show on a webchat user interface and keeps a track of the JSON requests and responses to the messages exchanged on the bot.

Testing & debugging your bot

About Author

Nibedita Dutta

Nibedita completed her master’s in Chemical Engineering from IIT Kharagpur in 2014 and is currently working as a Senior Consultant at AbsolutData Analytics. In her current capacity, she works on building AI/ML-based solutions for clients from an array of industries.

Nibedita completed her master’s in Chemical Engineering from IIT Kharagpur in 2014 and is currently working as a Senior Data Scientist. In her current capacity, she works on building intelligent ML-based solutions to improve business processes.

Responses From Readers

Clear

Congratulations, You Did It!
Well Done on Completing Your Learning Journey. Stay curious and keep exploring!

We use cookies essential for this site to function well. Please click to help us improve its usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy & Cookies Policy.

Show details