قالب وردپرس درنا توس
Home / Tips and Tricks / How to use AWS Lex to build interactive chatbots – CloudSavvy IT

How to use AWS Lex to build interactive chatbots – CloudSavvy IT



AWS Lex

AWS Lex is Amazon’s service for building your own chatbots. Lex built with the same machine learning technology as Alexa and can recognize the user’s intent, ask for additional data and then fulfill user requests using Lambda to run code.

What is AWS Lex?

AWS Lex consists of many different machine learning services, most of which are available as a standalone AWS service.

The first step is speech recognition ̵

1; converting spoken word into text that a machine can more easily understand. AWS’s transcription service does quite well, although it is better suited for non-real-time applications, such as subtitling video or transcribing audio call logs. This step is not necessary if you are creating a text-based chatbot, but it is crucial for bots like Alexa and Siri.

However, machines do not automatically understand human language, so extracting the useful bits from a given sentence is the key to the chatbot responding fluently to commands. AWS Comprehend does this with high accuracy and can select and identify keywords in input text.

Combined with custom logic to dictate the flow of a conversation, Lex can respond to user commands and send data to Lambda for further processing. During a conversation, AWS Lex can also ask users for additional information; For example, if a user is trying to book an appointment, Lex may ask the user for a date and time that suits them.

Lex text output can also be converted to speech using AWS Polly, providing a seamless chatbot experience.

With how measured all component services are, Lex itself is surprisingly easily priced – you charge $ 0.004 per voice request ($ 4 per thousand) and $ 0.001 per text request ($ 1 per thousand).

Unlike most AWS services, Lex is currently only available in three regions:

  • us-east-1 (N. Virginia)
  • us-west-2 (Oregon)
  • eu-west-1 (Ireland)

With how latency-dependent a chatbot usually is, it’s surprising that only a few regions are supported, but Lex also only supports English so the region choices make sense.

How does Lex work?

To get started, switch to the Lex console. Some sample applications have already been made that you can try yourself, but we will go ahead and create a new custom cure so you can see how they are built.

Create a custom cure.

It all starts with intentions. You can think of intentions as certain actions that your cure can take, such as scheduling appointments, ordering items, and so on. Every intention needs some trigger words, called opinions, that start the conversation. Try to keep these fairly short; for example, “book an appointment” works better than “I would like to book an appointment.”

AWS Lex Utterances

Your cure may have multiple intentions and multiple opinions associated with each intent. You should try to capture all the different ways in which a user can state his intention.

When the bottom starts an intention, it asks the user for additional data. Technically, you do not need additional data and you can let your bot end the conversation and perform its actions immediately.

Additional data comes in the form of slots. You can think of these similar arguments for a command – the bottom must ask the user for each argument before sending the final action. The arguments are type sensitive, so if Lex asks a user how many items they want to order, it does not accept “green” as an answer.

AWS already has many built-in types, most of which are identified by AWS Comprehend. If you ask a user for a date, use AMAZON.DATE, and if you request an address, use AMAZON.StreedAddress.

Each slot has its own prompt, which is displayed or read to the user. For example, if you ask the user for the date of their meeting, you can write something in the line “What day do you want to book your time for?”

AWS Lex Slots

You can also build your own game types. For example, if you offer a few different types of meetings, you can add them to your own type. Lex expands your track values ​​to include similar responses you can get from real-world users. You can also limit your custom column type to only exact words and synonyms, if you want it to be stricter. A good rule of thumb, however, is to include the types in the slot so that the user knows the options. Otherwise, some people may get stuck.

In addition, you can integrate slots directly into the opinions. If a user says “I want to book an appointment tomorrow,“You can cut the extra step and consider that place is filled. You can do this by surrounding the track name in parentheses in the opinion definition:

an appointment on {AppointmentDate}

This is all the configuration that your bot needs, but most users want to see a confirmation request before taking action, both for peace of mind and to ensure that the bot has not screwed up anything. Lex supports this under the “Confirmation Prompt” settings. You can include card variables in the prompt, which Lex fills in with what the user said (to the best of his knowledge, at least).

Lex confirmation settings

From here, you can hit Build to test your cure in the integrated test panel. It should respond to your statement and ask you for each of the places you have given it. It should respond well to changes in command structure, but if it does not, you may want to add more opinions or expand your slot definitions.

AWS Lex chatbot testing

By default, Lex runs in debug mode and simply returns the slot values ​​when done. You can change this to call a Lambda function and transfer the track values ​​as parameters to the function. It is up to you to decide what to do from here. You can also manually take more control of Lex with a Lambda validation hook; This allows you to run a Lambda function when a user responds, either validating and activating the input or prompting the user again.

When your cure is complete, you can provide a response message that lets the user know how the Lambda feature handled their entries, or simply thank them for their service.


Source link