Cloud AI - Building a Chatbot with Amazon Lex (part-1)

yyounos shaikyyounos shaik
6 min read

DIFFICULTY : EASY TIME: 60 min COST: 0$

WHAT YOU’LL NEED : An AWS account - Create one here!

AWS SERVICES :

  • Amazon Lex

Overview

We’ll learn how to create a practical chatbot, BankerBot, that can help your imaginary customers check their account balance and transfer money between accounts!

This project is Part One!!! Now lets set up a chatbot in Amazon Lex and make it welcome its users!

Step 1 : Set up your Lex chatbot

  • Log in to your AWS Account.

  • 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!

Step 2 : 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!

Step 4 : 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).

  • Done… Congrats!!!

Step 5 : Delete your Resources

Time to clean up those resources - let’s make sure we don’t rack up any charges!!

  • Head to Aamzon Lex console.

  • Choose Bots on the Left-hand sidebar.

  • Choose the circle radio button next to BankerBot.

  • Choose Delete from your Action Drop-down.

  • Choose Delete.

Summary

Well Congrats!!! You have successfully created a chatbot using the Amazon lex. Will see you in the next project.

0
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