Cloud AI - Builiding a chatbot with Custom Slots (part -2)
DIFFICULTY
: Easy TIME
: 60 MINS COST
: 0$
WHAT YOU’LL NEED
:
An AWS account - Create one here!
Part -1 :Building a chatbox using Amazon Lex
AWS SERVICES
:
- Amazon Lex
Overview
In this project , we’ll create a practical bot, banker bot hat can help your imaginary customers check their account balance and transfer money between accounts!
In project one we got to know how to:
Define a basic intent.
Create lists of utterances.
Handle failures with FallbackIntent.
Define a MessageGroup to provide variations in your bot's responses.
Build and test your bot using text and speech.
Let’s Get Started…
Step 1 : Set up your Lex chatbot
Navigate to Amazon Lex (type Lex into the search bar of your Console).
Check your URL in your web browser - does it say
...console.aws.amazon.com/lexv2/...
?- If you're not seeing "lexv2" in your URL, click on Switch to the new Lex V2 console link in your left-hand menu.
Select Create bot.
Select Create a blank bot.
For Bot name, enter
BankerBot
.For Description, enter
Banker Bot to help customer check their balance and make transfers.
Under IAM permissions, select Create a role with basic Amazon Lex permissions.
Why do we need Amazon Lex permissions?
Amazon Lex needs the permission to call other AWS services on your behalf, later in this project series we’ll be integrating Lex with another service callled Lambda!
We’ll be using it to call another sevice called Lamda later!
Under Children’s Online Privacy Protection Act(OCPPA), Select No.
under Idle session timeout, keep the default of 5 minutes.
What does Idle session timeout mean?
Amazon Lex will only maintain a session for a set of length of time. If the user is idle and does not add any input for 5 Minutes, their session will end.
Select Next.
Now we're going to play around with your bot's voice.
Keep the language as English so you can explore Lex's full set of feastures in this project.
Under Voice interaction, click on the dropdown that says Danielle.
Click around different voice options to choose your favorite one!
For Intent classification confidence score threshold, keep the default value of 0.40.
What is intent classification confidence score threshold?
When you're using Amazon Lex to build a chatbot, this threshold is like a minimum score for your chatbot to confidently understand what the user is trying to say.Setting this to 0.4 means that your chatbot needs to be at least 40% confident that it understands what the user is asking to be able to give a response.
So if a user's input is ambiguous and your chatbot's confidence score is below 0.4, it'll throw an error message.
Select Done.
your basic bot structure is now complete, and you can now bring it to real life!
Create your first Intent
When your bot is created, you will automatically see a page called Intent:NewIntent.
What are Intents?
An Intent is what the user is trying to achieve in their conversation with the chatbot. Ex: checking a bank account balance.
In Amazon Lex, you build your chatbot by defining and categorising different intents. If you set up different intents, one single chatbot can manage a bunch of requests that are usually related to each other.
Lets change the naeme!
Under Intent details, enter
WelcomeIntent
for the Intent name.Add the description
Welcoming a user they say hello
.Scroll down to the Sample utterances panel.
Click the Plain Text button.
Copy the text below, which represent the user inputs (called utterances) that will trigger this intent, and paste it into the text window:
Hi
Hello
I need help
Can you help me?
Click back to the Preview button to see these utterances in chat form.
Scroll down to Closing response, and expand the speech bubble for Response sent to the user after the intent is fulfilled.
In the Message field, enter the following message:
Hi! I'm BB, the Banking Bot. How can I help you today?
Choose Save Intent.
Choose build, which is close to the top of the screen.
This can take 30 seconds…
Choose Test.
The following dialog will pop up, and you can interact with the bot by entering your opening mesage.
Try various different phrases and see what come up!
The ones that you have literally defined in your utterances section will definitely work.
But what about other utterances?
Since we have an intent classification confidence score of 0.40, other phrases with similar intents to the one’s we,ve defined could work too.
Test these:
Help me
Hiya
How are you
Good morning
What's another way you like to greet someone or say hi?
How does my chatbot respond to these user inputs?
The first three are successfully recognized - Amazon Lex is able to use its ML techniques what you have said against your utterances.
But the last two will fail in an Intent FallbackIntent is fulfilled response - meaning Amazon Lex doesn’t quite recognize your utterance. We’ll learn what fallbackIntent means in next few steps!
Try two of these utterances again, this time using voice!
Click on the microphone icon at the left of the chat box, speak "Hello" and then click on the tick on the right.
Now try another phrase!
Set Manage FallbackIntent
In your letf hand navigation panel, choose FallbackIntent.
What is FallBackIntent?
If your chatbot has a confidence score below 40% for all the intents you’ve defined ( in this case WelcomeIntent), the fallbackIntent is triggered.
Think of it as a custom error message that your chatbot will use to tell the user it doesn’t understand their input.
The default FallbackIntent message you saw just now ( “Intent FallbackIntent is filfilled”) can be a little confusing.
Let’s rephrase that message so its clear to the users that your chatbot doesn’t understand the user’s request.
Scroll down to Closing responses.
Expand the speech bubble for Response sent to the user after the intent is fulfilled.
In the message field add the following text:
Sorry I am having trouble understanding. Can you describe what you'd like to do in a few words? I can help you find your account balance, transfer funds and make a payment.
What is detailed message?
It’s often chatbot best practice to give a hint as to what kind of commands the bot can understand and respond to.
You’ll notice another toggle next to the label variations -optional.
Open the toggle.
Enterthe following text:
Hmm could you try rephrasing that? I can help you find your account balance, transfer funds and make a payment.
Add another variation!
What are variations?
variations are literally variations of same message in the main Message box. When Amazon Lex needs to return a fallback response, it will randomly choose a message from the group and return that.
Choose Save Intent.
Choose Build .
Choose Test.
Let’s Test 2-3 messages that failed in the last try! (I used little german in the execution part but you can use english and test).
Step 2 : Create a custom slot for account types
- In the Amazon Lex console, choose Slot types in your left hand navigation panel.
What are slots?
Slots are pieces of information that a chatbot needs to complete a user's request. Think of them as blanks that need to be filled in a form.For example, if the intent is to book a table at a restaurant, the chatbot needs specific details like: restaurant name, date, time, number of people.
Amazon Lex provides many ready-to-use slot types for common information, like dates and times, but you can also create your own custom slot types to fit your specific needs! That's what we're about to do.
Choose Add slot type.
From the dropdown, choose Add blank slot type.
Enter
accountType
for the Slot type name.Choose Add.
This will bring up a large Slot types editor panel! Woooooo welcome.
In the Slot value resolution panel, choose Restrict to slot values.
What does this selection mean?
Selecting Restrict to slot values makes sure that only the values that you specify will count as a valid accountType!Otherwise, Amazon Lex will use machine learning to accept other values that it sees users constantly entering.
Different use cases will require different settings, but our BankerBot will only offer customers 3 types of accounts - we don't want Amazon Lex to recognise any alternatives.
Now let's add the three account types!
In the Values field, enter
Checking
Select Add value, or just press Enter on your keyboard.
Do the same for
Savings
Enter
Credit
, and add a few synonyms in the second field. Press;
on your keyboard after every time you add in a new one:credit card
visa
mastercard
amex
amazon pay
Choose Add value to finish up your work for Credit.
Step 3 : Create the CheckBalance intent
In your left hand navigation panel, head back to Intents.
Choose Add intent, then Add empty intent.
Enter
CheckBalance
as your intent name.Choose Add.
Enter the following description in the Intent details panel:
Intent to check the balance in the specified account type.
Scroll down to Sample utterances.
Switch to Plain Text and paste in the following utterances:
What’s the balance in my account?
Check my account balance
What’s the balance in my {accountType} account?
How much do I have in {accountType} ?
I want to check the balance
Can you help me with account balance?
Balance in {accountType}
Why do some of the utterances have the text {accountType}?
This means that Amazon Lex is now prepared to look for slot values from the user's input.If a word fits what's expected for the accountType slot, Lex will automatically fill in that information and won't need to prompt the user for their accountType anymore (saving time for the user)!
Scroll down until you can see the Slots pane.
Choose Add slot button.
For slot's Name, enter
accountType
.For the Slot type, choose your custom slot value
accountType
- which you created in Part 1!Enter the following for Prompts:
For which account would you like your balance?
Choose Add.
You might remember that we mentioned the CheckBalance intent should also check for the user's birthday... let's create a Slot for the birth date!
Choose Add slot.
Use these values for your next slot:
Name:
dateOfBirth
Slot type:
AMAZON.Date
Prompts:
For verification purposes, what is your date of birth?
Choose Save intent.
Choose Build.
Choose Test.
Now let's chat with your new chatbot! Enter
I want to check my balance please.
Then, follow Amazon Lex's prompts and enter an account type and birth date.
Now choose Inspect near the top of your chat window.
The chatbot has already filled both slots -
accountType
anddateOfBirth
- with information it now knows about you.In your chat window, now enter
What's the balance in my savings account?
This time, Amazon Lex will only prompt you for your date of birth, as it already knows that it should be the Savings account it checks.
Nice - you've passed on
accountType
through your utterance!Congtats!!! It’s done…. you have finally initated the chatbot.
Now delete the resources what you have created or else keep it for the next part of the series your choice…!!!
Summary
well done!! Now we will kind of level up in the next part of this porject until then stay tuned….
Subscribe to my newsletter
Read articles from yyounos shaik directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
yyounos shaik
yyounos shaik
An Aspring Cloud Engineer