Mind Matters Natural and Artificial Intelligence News and Analysis
Chatbot conversation on smartphone screen app interface with artificial intelligence technology providing virtual assistant customer support and information, person hand holding mobile phone
Chatbot conversation on smartphone screen app interface with artificial intelligence technology providing virtual assistant customer support and information, person hand holding mobile phone
Featured image: Chatbot/NicoElNino, Adobe Stock

You can build your own chatbot

New tools have made it comparatively easy
Share
Facebook
Twitter
LinkedIn
Flipboard
Print
Email

Natural Language Interfaces (the technical term for a chatbot) are becoming more and more popular. Many dial-in phone services have switched from numeric interfaces (“Dial 1 for sales, 2 for service, etc.”) to natural language interfaces (“Please say what you are calling about”). Where they have taken off though is with chatbots.

Many online help systems at least start with chatbots, which collect basic information about a problem or situation and point to existing solutions before passing the contact off to a human expert. Additionally, the rise of the Generation Text, as well as the proliferation of chat-based groupware such as Slack, means that text-based natural language interfaces are one of the best ways of interacting with young people.

Is it hard to build chatbots? Today, with the right tools, it is actually fairly straightforward and even non-specialists can learn to do it easily. Let’s look at how you can build a simple chatbot using Amazon Web Services (AWS).

Perhaps because Amazon is best known to the public for its huge collection of books and merchandise for sale, as well as its huge streaming lineup, many people do not know that its core profit center is elsewhere. Since 2006, Amazon has been renting out its massive data centers to technology professionals. While it started with rentable storage and servers, since then, Amazon has continually expanded the technologies that it makes available to developers. The company currently offers over 90 services and the most recent additions to its product lineup include a suite of artificial intelligence tools.

Amazon Lex is the tool we will use to develop a demo chatbox:

To get started on Amazon Lex, you first need to sign up for an account on AWS. After signing up and logging in to AWS, search for the Amazon Lex service to get started.

When you first start, Amazon Lex will ask you if you want to try a sample bot or create a custom bot. For this example, click on “Create Your Own Custom Bot.” Next, Lex will ask you to name your bot.

For this tutorial, we will create an order-taking bot for a restaurant. You can call it OrderBot. Next, select an “Output Voice” for voice interactions, and a timeout (how much delay in interaction is allowed before the bot resets). You can ignore the “IAM role field.” Finally, select that your bot is not subject to COPPA (the Children’s Online Privacy Protection Act). Then click “Create.”

You now have an “empty bot,” a bot which essentially does nothing. Let’s give the bot something to do. Because we are taking orders for a restaurant, we might want the bot to take an order for a sandwich. In Amazon Lex, this task for the bot is called an “intent.” We are going to create an intent by clicking on the “+” icon next to “Intents.” Then we will click “Create Intent” and give our intent a name, like “OrderSandwichIntent.”

Now we need to think about the things that a customer who wanted to order a sandwich might say to a chatbot. We can quickly think of several, such as “I would like a sandwich” or “Can you make me a sandwich?” or even just “I am hungry.” Think of as many ways of asking for a sandwich as you can and enter them all, one at a time, into the “Sample utterances” box. Click the “+” icon after each one. Note: Do not use any punctuation. These are all prompts that tell the bot which script it is going to use (in our case, the OrderSandwichIntent script).

Now, making a natural language interface isn’t too different from any other kind of interface. As with any interaction with a computer, you need to identify the data you need to process the interaction. Natural language interfaces merely provide a more intuitive way of providing that data. For our purposes, we will focus on two items for the sandwich, the type of bread and the toppings. These data points are known as “Slots” to Amazon Lex.

Skip the section that says, “Lambda initialization and validation.”

So, in the “Slots” field, we will add a slot and put “Bread” in the “Name” field. Computers work better if they have an idea of what kind of information should go in each field. The “Slot Type” field tells Lex what type of information it should expect. In our case, we will go with “Food.” Then, in the “Prompt” field, we will enter the words we want the bot to use, to ask for this information. In our case, we will ask it to say, “What kind of bread do you want on your sandwich?” Then click the “+” button to add this slot into your intent. Next, we will add a slot for the toppings. We will use “Toppings” for the name, “Food” for the slot type, and “What toppings would you like on your sandwich?” as the prompt. Again, click the “+” button to add this slot into your intent.

Now we want to add a “confirmation” prompt, to make sure that the bot has understood the user correctly. Under the “Confirmation Prompt,” click the checkbox to enable the confirmation prompt. Under “confirm,” add the text, “Are you sure you want a sandwich on {Bread} with {Toppings}?” This tool will pull in the values that the user gave the bot for the Bread and
Toppings slots and repeat them to confirm. You can also add a response if the user does not confirm, such as “Thank you, we will not place this order.”

The “Fulfillment” section is the point at which you or another developer would connect your bot to a function either on your servers or on AWS. We will leave this alone for now because we aren’t connecting this to a real order processing system.

Finally, under “Responses,” click on “Add Message.” Enter “Thank you for your order!” for the message, and click the “+” button. Lex allows you to add as many messages as you want, and it will choose one to use at random. Finally, click on “Save Intent” at the bottom of the screen.

Now, to build your bot, click on the “Build” button at the top right hand of the screen. When the build is done, you will notice s a place on the right-hand side of the screen (labeled “Test Chatbot”) that you can use to test out your new bot. You can see my interaction with my bot below.

Notice that, in my initial inquiry, even though I didn’t exactly match the bot’s “sample utterances,” it was able to make a guess at what I was indicating.

Now we can publish the bot. When you click the “Publish” button, it will ask for an alias. You Are being asked to name this version of the bot. So we can call this OrderBotVersionOne.

Once it is published, we can connect it to other services.

For instance, if you have a Twilio account, you can connect the chatbot to an SMS Messaging (i.e., text messaging) phone number. Then the bot can chat over text messaging from your phone. If you have a Slack channel, you can connect your bot to Slack. You can make these connections via the “Channels” tab.

If I have an SMS number on my Twilio account, I can add it just by adding the authentication details from Twilio and giving the channel a name. Amazon will then generate a URL that I can paste into Twilio (on the “Webhooks” section of the SMS number’s messaging configuration).

Now I can text that phone number and have a chat interaction!

From here, we can add more intents if we wish (say, a DrinkOrderIntent or a SaladIntent) and add the slots needed for each one.

As you can see, modern tools make building bot interactions a very straightforward task!


More of Jonathan Bartlett’s tutorials and tips on machine learning:

Successful generalization is a key to learning. In machine learning, the Solomonoff induction helps us decide how successful a generalization is.

and

Machine learning tip: Set boundaries for the problems. We cannot take a giant pile of unorganized data, shove it into a machine, and expect useful results.


Jonathan Bartlett

Senior Fellow, Walter Bradley Center for Natural & Artificial Intelligence
Jonathan Bartlett is a senior software R&D engineer at Specialized Bicycle Components, where he focuses on solving problems that span multiple software teams. Previously he was a senior developer at ITX, where he developed applications for companies across the US. He also offers his time as the Director of The Blyth Institute, focusing on the interplay between mathematics, philosophy, engineering, and science. Jonathan is the author of several textbooks and edited volumes which have been used by universities as diverse as Princeton and DeVry.

You can build your own chatbot