Building conversational chatbots using Amazon Lex — Part 1

Unofficial Data Scientists
5 min readDec 4, 2020

--

In this modern world, people are less interested in talking to humans and are spending more time with gadgets to communicate. This intern made the techies to create a human like software which will try to understand a request from human and try to perform a task and keep it as short as possible.

Yes, I am talking about chatbots.

Robot which is representing a chatbot

This technology is been widely adopted by many service-based industries to automate many manual tasks and be able to provide prompt responses based on the data which was fed to the system.

Today we are going to create a simple yet interactive chatbot with Amazon Lex which is a managed service from Amazon to build conversational chatbots with automatic speech recognition (ASR) and Natural Language understanding (NLU) using deep learning functionalities which will help us to build high engaging user experience.

Let us get into AWS console and build a chatbot, but before that we need to know how AWS Lex architecture is built.

In a short note, Let me give you a brief about few important terms used in AWS Lex.

Amazon Polly: It is a cloud service from amazon to convert text to speech like audio.

Intent: Understand intent as a phrase or sentence which can be used to perform a specific action or task.

Utterance: To perform an intent, one should express their word, and this can be in many ways possible.

Slots: Consider slots as variables which store some specific information. This can be used in many intents. for example numbers, days, and months.

Now the fun begins with configurations.

Login to AWS account and navigate to AWS CLI https://aws.amazon.com/ and search for Amazon Lex.

Step 1: Create a bot and name it as you wish, for now I have names it as ’BikeRental’.

Click on BikeRental and start building the necessary functions for your bot.

Step 2: Create Intents

Intents are dialogues from the user which has a meaning to perform a task. An Intent has a Sample Utterances which can be in many ways a user can input a question.

Click on the “+” icons near intents tab and create an intent and name it.

you can see an intent named Product which actually holds the values of various products which the organization is offering, in this chatbot it is about vehicles/ bikes.

Now add few utterances which might be given as an input from the user in many ways so that the bot an actually understand the intent to perform the task.

For example

1. I want a bike.

2. i would like to rent a electric bike.

3. Can i book a car

4. I would like to book a cycle

Step 3: Create Slots

Slots are like parameters that capture the inputs like NAME, DATE, TIME, or any Custom input from user to further proceed a particular task. Slots can be designed to help the utterances to perform a task/ action.

we can use slots while providing an sample utterances which i have already showed in the above utterance image.

{producttype}

{quantity}

{time}

Further in the productType slot, we can input as many values as possible to match the intent from the user and can be used for other intents connections. In the above slot, i have mentioned bicycle, car and other vehicles types which the organization is going to offer. you can add as many products as you wish and save the slots or can add directly to the intent.

Fulfillment:

When you are interacting with a bot, it is a primary responsibility of bot to have a meaningful yet engaging setup in a conversation. Fulfillments will help the bot to keep it engaging with the order of slots placements (mostly). Fulfillments are managed by set of sequential order from the prompts or we can do it through lambda (which help us in preserving the sequence much efficiently)

Amazon Lambda (optional):

Lambda can be used to specify the order of custom slots to ensure the sequence is not missed in a conversation. Lambda can be very handy if you have to manage a large data which is already available and can directly dump the file to lambda functionality under fulfillment.

we have simplified the over all Lex in my simplest way of understanding, hope you can understand it better.

Error Handling:

Users can always have a high possibility of typing or asking questions which may not fit the bot’s functionality, this is when error handling session can perform the task and make sure the user stick to the agenda.

We can manually choose how many wrong intent an user can ask and then we can automatically end up the conversation.

Response:

Once the intent is finished with required slots, bot will try to push a response to the user of finishing a task or sending a confirmation prompt.

AWS also provides you with testing the bot you have developed using Lex on the same console which you have build and it can be a great way to debug your chatbot if you face any issues in further enhancing the bot to next level.

In the next stage we will help you out in deployment phase which we hope will be as exciting as we felt for the first time finishing up this project.

For further resources on developing chatbot using AWS Lex we suggest you to go through official documentation here.

References :

https://aws.amazon.com/lex

--

--

No responses yet