By Frank Nimphius
March/April 2018
Editor's Note, June 2019: Oracle Digital Assistant is the successor to Oracle Intelligent Bots in Oracle Mobile Cloud Enterprise. It's a standalone PaaS service, and it contains all of the Oracle Intelligent Bots functionality explained in this article.
2017 was a banner year for chatbots, and 2018 is expected to be another one. Young people in particular refuse to download specific mobile applications just to get in touch with specific organizations. In the same way they communicate with friends and social media followers, young people like to use speech or messengers such as Facebook to book, buy, order, or complain about products and services.
Leveraging conversation as a channel for business has become a necessity for organizations to stay connected with this new generation of consumers. Many companies, especially those that focus on customer service, have already reacted to the trend and added chat capabilities to their websites.
But how scalable is customer service where each incoming customer message is answered by a human? If message volume exceeds the human capacity to handle it, customers would likely experience the same delays and frustrations users experience when waiting on traditional call centers for an agent to pick up and handle the call. This is where chatbots can help, because their job is to automate conversation between users and services on the conversational channel.
So what is a chatbot? A chatbot is computer program that simulates a conversation with a human to serve users on the conversational channel. Often, chatbots are associated with artificial intelligence and machine learning. Though you could easily build bots without these technologies, the majority of chatbots are built based on artificial intelligence and machine learning in order to understand the intent of and extract information from user input, which in most cases is free text or speech.
Oracle Intelligent Bots is a feature of Oracle Mobile Cloud Enterprise—which is part of Oracle Cloud Platform—for building multichannel mobile back ends and bots. Using Oracle Intelligent Bots and following the instructions in this article, you are going to build a pizza bot that leverages artificial intelligence and machine learning to understand user intent and to extract values from user input. To access Oracle Intelligent Bots, sign up for a free Oracle Mobile Cloud Enterprise trial.
About the Sample Bot
Following the steps in this hands-on article, you will build a simple pizza bot. The process will familiarize you with the Oracle Intelligent Bots user interface and the terminology involved in building chatbots.
Figure 1 shows a screenshot of a conversation that you, as the bot user, can have with the bot at the end of this tutorial. The screenshot is taken from the integrated tester in Oracle Intelligent Bots and shows the user input in bubbles with a blue background and the bot responses in bubbles with a gray background.
Figure 1: Pizza bot in the Oracle Intelligent Bots integrated tester
Creating the Pizza Bot
From here, the article’s steps assume that you have access to Oracle Intelligent Bots through a trial or paid subscription to Oracle Mobile Cloud Enterprise.
Start creating your new bot by performing the following steps:
Figure 2: Oracle Mobile Cloud Enterprise dashboard
The new bot opens in the development environment. Figure 3 shows the bot development environment with annotations added to make it easy for you to see the menu options to use in these hands-on instructions.
Figure 3: Oracle Intelligent Bots development environment with annotations
Defining Intents and Training the Bot
After you complete the previous steps, the Intents screen opens, as shown in Figure 3. If the Intents screen is not open, click the Intents icon.
Intents represent what a user wants to achieve within a conversation. For the sample pizza bot, you’ll create two intents: Order Pizza and Cancel Pizza.
I like to order a pizza. Pizza please Can I order pizza? I want a large pizza I fancy a pizza
I don't want my pizza anymore Forget my order please Can you cancel my order? I changed my mind, no pizza anymore Please delete my pizza order
What you just did: You created two intents and provided example sentences for each for the bot to learn what a user wants. Those example sentences are called utterances and they build the learning foundation for the bot to create a prediction model that helps it to understand the user intent, even if the user uses different words when ordering or cancelling a pizza.
Note: Oracle Intelligent Bots displays green or red notifications to acknowledge the success or failure of an operation. Close a notification by clicking the X on the right.
Testing the Language Understanding
Now is a good time to test how well the bot was trained and if it is ready to accept orders and cancellation requests.
Figure 4: Oracle Intelligent Bots integrated tester for testing intent recognition
What you just did: With the small set of training sentences you added, the expectation is that the bot understands a basic pizza order, but that it is far from perfect. With 45.8% confidence, the bot identified the I like pizza input as a request to order pizza.
To fine-tune the bot’s understanding for the Order Pizza intent, you added that sentence to the bot utterances, and a follow-up bot test showed a higher confidence that what the user wanted was to order pizza. Though “Gimme a pizza” was not among the training sentences, the bot identified it as an order request. If it didn’t work, you would have added it as an example in the tester to refine the bot’s understanding.
Create Entities for the Information in a Sentence
“I like to order a giant pizza with Salami and Cheese” contains more information than just the intent. For the bot to be able to extract the information that matters, you create entities.
Cheese Veggie Pepperoni Supreme Chicken
What you just did: You created an entity for the pizza types sold by the bot. You selected Value list as the entity type, allowing you to define a finite list of values. For the meat-lover pizza, you defined synonyms, which also will be recognized by the bot in a pizza order and associated with the meat-lover pizza. Synonyms allow you to consider alternative names or slang for a value defined for an entity.
large (big, lrge, lrg) medium (med) small
What you just did: You created two entities for the type and size of a pizza. You then associated the entities with an intent (Order Pizza) so that Oracle Intelligent Bots extracts those entities if they’re contained in the user input.
Note: If the entities don’t show in step 39, ensure that you assigned the entities to the right intent.
Designing the Pizza Order Flow
With the language model trained and the entities created, it’s time to design the conversation the bot will have with users who want to order a pizza. For the sake of brevity, this article implements only the order pizza use case (and intent).
Note: Oracle Intelligent Bots creates a sample conversation for every new bot you create. You can test this sample by clicking the test icon in the upper right corner. If you haven’t already, select the Bot link in the test menu. Then, in the Message field, type hi and follow the instructions on the screen to receive a personal welcome message. When you’re done, click the test icon again to close the tester window.
intent: component: "System.Intent" properties: variable: "iResult" confidenceThreshold: 0.7 transitions: actions: Order Pizza: "startOrder" #Cancel Pizza: unresolvedIntent: "unresolved"
variables: iResult: "nlpresult" pizzaType: "PizzaType" pizzaSize: "PizzaSize"
What you just did: The bot flow is defined as states associated with components. You created a welcome state to introduce the bot to the user. The intent state uses a System.Intent component to receive the user input and then it analyzes the input to determine what the user wants (to order a pizza) and glean the information about the pizza type and size contained in the user string. The confidenceThreshold property says that all user input that does not have a 70% confidence for the intent that the bot associated it with should be handled by the unresolvedIntent action. Note that the Cancel Pizza intent is commented out using the hash character (#) because this hands-on tutorial does not implement this use case.
Next, add a state to handle the unresolved intent. In the sample bot application, the unresolved intent simply prints a message for the user to try again.
unresolved: component: "System.Output" properties: text: "Sorry, I did not understand the request. Please try again." keepTurn: false transitions: next: "intent"
What you just did: The unresolved state prints a message to the user and directs the flow control to the intent state. Using this information, the user can rephrase the request.
Now add states to complete the order process.
startOrder: component: "System.List" properties: prompt: "Please select a pizza type" options: "${pizzaType.type.enumValues}" variable: "pizzaType" nlpResultVariable: "iResult"
What you just did: The startOrder state shows a list of pizza types if the user input does not contain this information. If the information is found in the user input, or if the user selects a pizza from the list, the pizza type value is stored in the pizzaType variable.
askSize: component: "System.List" properties: prompt: "What size pizza would you like?" options: "${pizzaSize.type.enumValues}" variable: "pizzaSize" nlpResultVariable: "iResult"
Note: Whenever the code block defining a state does not contain a transitions property (such as with the intent state), the flow navigation goes to the next state below in the flow editor. You use the transitions property to break out of a sequential flow.
printOrder: component: "System.Output" properties: text: " Your order of a ${pizzaType.value} pizza, size ${pizzaSize.value}is complete." keepTurn: false transitions: return: "done"
What you just did: The printOrder state acknowledges the order and prints the pizza type and pizza size as defined by the user. To add values to static text, Oracle Intelligent Bots uses expressions (as used in the text property). The transitions property directs the flow control to a return statement, which completes the bot conversation.
Testing Your Pizza Bot
You tested the intent recognition and entity extraction earlier and know that they work. So now let’s see if the conversation flow works as planned.
What you just did: You tested three use cases for the designed bot conversation. In the first, you ordered a pizza without mentioning the pizza size. As a result, the bot asks you for the size and displays your options. You then tested an order in which you did not mention the type and size of the pizza. The bot recognized the two missing pieces of information and asked for both. Lastly, you tested language understanding by providing all of the information in a single user input. And because the bot found all the required information, it did not ask for anything and immediately printed the pizza order.
Importing the Solution
This article also provides the completed pizza bot as a downloadable zip file. After you download OracleMagazineOnlinePizza.zip, do the following:
Conclusion
In this article, you created a simple pizza bot that has a very simple conversation flow. Real bot use cases have more-complex flows and need to integrate with back-end systems. In follow-up articles, I will explain how you can enhance your pizza bot with additional features and more-complex conversation flows.
Next Steps
LEARN more about Oracle Digital Assistant.
DOWNLOAD the bot for this article.
Photography by Getty Images/iStockphoto