Amazon Lex -Deep Dive
Creating a Lex Bot
The course is part of these learning paths
We dive into the internals of Amazon Lex service, describing in detail the individual parts that make up the service. We'll introduce you to the key features and core components of the Amazon Lex service. We'll go over Chatbots in general and why they have become both useful and popular. You will be introduced to the key features and core components within the Amazon Lex service. We spend time understanding and reviewing Amazon Lex Bots, Intents, Utterances, Slots, and Slot Types. We focus on the developer workflow and how Amazon Lex integrates seamlessly with other AWS services. We take a look at, and review the capabilities of the Amazon Lex API and associated SDKs. Finally we'll review Versioning and Aliases and how they facilitate development within the Amazon Lex service.
Let's now begin with our review of the Amazon Lex service. Amazon Lex allows you to build conversational voice and text interfaces. Amazon Lex can be used to create and embed chatbots into your applications. Internally, the Amazon Lex service uses the same deep learning engine that powers Amazon Alexa. Under the hood, Amazon Lex uses automatic speech recognition, ASR, for converting speech to text, and natural language understanding, NLU, to recognize the intent of text. We'll go into these topics in greater detail as we progress through this course.
In essence, Amazon Lex allows you to quickly build really engaging chatbots, shielding you from the complexities of speech recognition and natural language understanding. But what really is a chatbot? Let's explore this in the next slide.
In layman terms, a chatbot is a computer program designed to simulate conversation with a human. Modern advancements in AI technologies such as natural language processing now make it possible for chatbots to hold deeper, longer and more natural conversations with humans.
So what makes Amazon Lex so compelling to use? At its core, Amazon Lex provides high-quality text and speech language understanding. Developers can leverage these capabilities through a simple and intuitive console which is incredibly easy to use. You can go from ground zero to a fully functional chatbot system within a matter of minutes. More advanced chatbot setups may take extra time. Amazon Lex is a cost-effective solution. As with most AWS services, Amazon Lex has no upfront costs and provides pay-as-you-go pricing. Amazon Lex provides deployment functions to allow you to quickly and easily roll out your conversational interfaces amongst multiple environments, using a combination of aliases and versioning. With Amazon Lex, you can scale out without concerns for bandwidth, as Amazon Lex does not impose bandwidth constraints. Finally, Amazon Lex is seamlessly integrated with several other AWS services. In particular, Amazon Lex utilizes AWS Lambda to execute validation and fulfillment business logic.
As mentioned earlier, Amazon Lex utilizes machine learning technology to train its internal models. Automatic speech recognition, ASR, for converting speech-to-text, together with natural language understanding, NLU, provide advanced methods to translate your voice and/or text commands into actionable commands. Amazon Lex can be used to implement some of the following business use cases. Commerce ChatBot, allowing you to order food for dinner. Enterprise ChatBot, allowing you to connect to enterprise data resources. Support ChatBot provides automated customer support and answers to FAQs. Health ChatBot answers questions regarding health and allows you to book a follow-up appointment.
Amazon Lex is a fully managed service, and as such, provides all the necessary features to build, deploy, scale and monitor your chatbot solutions. Let's quickly go over the high-level build steps required to build a chatbot within Amazon Lex. First, you create a bot. A bot within Amazon Lex is a container for all remaining configurations specific to the bot in question. Next, you need to define the intents that will be performed by your bot. An example of an intent could be, order food or rent car. Each intent will require one or multiple utterances that are used to activate or kick off the intent.
For the order-food intent, we could register an utterance such as, "I would like to order food, please." Utterances are phrases that invoke the intent. They can be spoken or typed by the user engaging with the chatbot. The chatbot will begin to reply and converse with you, soliciting extra data required to fulfill the intent. These extra data attributes are known as slots. Slots are input data required to fulfill the intent. Finally, your intent will invoke some business logic implemented within AWS Lambda. This fulfills or actions the intent. That was a lot to consider and digest. Let's break this down by going over each of the core concepts in finer detail. This will allow you to get more familiarized with both the terminology and programming model used to build Amazon Lex chatbots.
The top-level concept within Amazon Lex is the bot. A bot is the primary resource type in Amazon Lex. A bot consists of several child configuration items, such as intents, utterances, slot types, slots, and channels, to name a few. We'll cover off each of these individually as we continue. The unit of build and deployment within Amazon Lex is the bot itself. Developers can build and deploy multiple bots, each with its own set of skills and behaviors. An intent represents some sort of outcome or action that the bot may perform. An example of an intent could be something like, schedule appointment, or book flight, or book accommodation. A single bot can be composed of multiple intents. For each intent, you need to provide the following attributes. Intent name. A descriptive name describing what the intent accomplishes. Utterances. One or several phrases the user speaks or types activate the intent. Fulfillment process. The method used to complete or fulfill the intent, for example, a configured Lambda function implementing the respective business logic.
In addition to your own custom intents, Amazon Lex also provides several built-in intents that you can leverage. Each intent may require and have to solicit additional attributes, otherwise known as slots, from the user to complete this intended outcome. For example, a schedule-appointment intent will prompt the user to state an appointment date, an appointment starting time and an appointment duration. Each of these attributes would be assigned to their own slot. Slots can be optional or mandatory, and are also assigned a slot type, which we'll cover off in the next slide.
As you can see on this slide, each slot has a configured prompt which at runtime results in a message presented to the user requesting additional information.
Slot types provide a typing system for slots. That is, each slot you define requires you to specify a slot type. You can define and create your own custom slot types, or leverage any of the inbuilt slot types. For example, if you had a rent-car intent, you might have slots for car model and enumeration with values Ford, Audi and Mercedes, and car fuel, with enumeration values petrol, diesel, electric.
Each intent can have one or multiple utterances. An utterance is used to activate an intent and consists of a stated phrase, such as, "I would like to rent a car." The user either types or speaks the registered utterance to kick off the conversation with the chatbot. Note, after deployment of your chatbot, Amazon Lex provides a feature to monitor and track so-called missed utterances. Missed utterances are those that the user has supplied, but for which Amazon Lex cannot match at runtime against any of the registered utterances. As an administrator, it's important to monitor and review any missed utterances, as this allows you to update and refine the utterance list within an intent to ensure that it fires under as many commonly used phrases as possible.
Amazon Lex has the ability to integrate into other messaging platforms. It does so by providing the concept of channels. Developers can build and configure a chatbot application within Amazon Lex, and then deploy it to multiple channels. This approach allows conversations to take place from within platforms beyond AWS's or the developer's own applications. Currently, Amazon Lex provides channel connections to Facebook, Slack and Twilio. AWS will continue to expand on this set in the future.
All network connections established to Amazon Lex are done so only using HTTPS. With this in mind, all conversational data exchanged with Amazon Lex is encrypted, and can therefore be considered secure. Additionally, the Amazon Lex API requires a signature to be calculated and supplied with any API calls. This authenticates the chatbot client with the Amazon Lex service, ensuring that only authorized chatbot clients can connect.
Amazon Lex provides SDKs for most common development languages. As can be seen on this slide, current SDK support exists for iOS, Android, java, .Net, and several other languages. The Amazon Lex SDK provides support for both text and speech inputs. The extensive SDK support provided by Amazon Lex allows developers to build and integrate chatbot interfaces directly within their applications, whether it be a web frontend app, a mobile native app, or maybe a smart TV app.
Amazon Lex pricing follows the same typical AWS pricing models that you've become familiar with. With Amazon Lex, you pay only for what you use. You're charged based on the number of text or voice requests processed by your chatbot. Pricing starts at $0.004 per voice request, and $0.00075 per text request. Let's walk through a pricing example. If your chatbot application processed 2,000 speech requests, the cost for this would be $8. Similarly, if your chatbot application processed 2,000 text requests, the cost for this will be $1.50. Your usage is measured in requests processed, which are added up at the end of the month to generate your monthly charges. Note, Amazon provides a free tier option for Amazon Lex, enabling you to trial and test a service. From the date you get started with Amazon Lex, you can process up to 10,000 text requests and 5,000 speech requests per month for free for the first year.
Amazon Lex has the ability to integrate with other AWS platform services and vice versa. For starters, and as previously mentioned, Amazon Lex can be configured to offload business logic into Lambda. Lambda functions can be used as code hooks for initialization, validation and/or fulfillment requirements. Additionally, Amazon Lex works with Amazon Cognito for user authentication, and Amazon Polly for text to speech synthesis. Finally, AWS Mobile Hub has templates that can be used to automatically provision Amazon Lex chatbot setup.
The typical developer workflow involves the following sequenced steps. Configure. Developer declaratively configures their chatbot. Save. Developer periodically saves the current chatbot configuration. Build. Developer builds the current chatbot configuration. Building a chatbot creates a testable version of itself. Test. Developer performs conversational tests with the chatbot using the test interface within the Amazon Lex service console. Publish. Developer publishes the chatbot. This creates a version of the chatbot, and for which can be assigned to an alias. We'll dive into the details of versioning and aliases in the next slide. Monitor. Developer monitors the chatbots. For example, missed utterances can be reviewed and added back into the respective intent configuration.
As briefly mentioned in the previous slide, Amazon Lex provides versioning and alias capabilities. As a developer, you can leverage the versioning and alias capabilities to control the implementation that your client applications use. Each version is a numbered snapshot of your chatbot configuration. Amazon Lex automatically tracks a version for each iterative change that occurs for any resource within your chatbot configuration. This allows Amazon Lex to track and know what's being used within a particular version of your chatbot that you're testing. With versions, you can publish different snapshots of your chatbot configurations to different environments, such as development, test, and production.
An alias is just a pointer to a specific version of your tracked Amazon Lex chatbot. In your client application, say for instance your mobile app, your chatbot client code makes reference to a predefined alias. The alias is in turn mapped to a particular version of your chatbot. This isolates your mobile app from having to be rebuilt against future changing chatbot version numbers.
Versioning and aliases are essential to support the concurrent, continuous, and evolving development of your chatbots. That concludes this lecture. In the next lecture, we'll step you through a fully working Amazon Lex demonstration. Go ahead and complete this lecture, and we'll see you in the next one.
Jeremy is a Content Lead Architect and DevOps SME here at Cloud Academy where he specializes in developing DevOps technical training documentation.
He has a strong background in software engineering, and has been coding with various languages, frameworks, and systems for the past 25+ years. In recent times, Jeremy has been focused on DevOps, Cloud (AWS, GCP, Azure), Security, Kubernetes, and Machine Learning.
Jeremy holds professional certifications for AWS, GCP, and Kubernetes.