Subscribe

Share

Emerging Technologies

Build a Chatbot in Minutes

Get started with Oracle Intelligent Bots in Oracle Mobile Cloud Enterprise.

By Frank Nimphius

March/April 2018

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.

chatbots figure 1

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:

  1. Open a browser and access the Oracle Mobile Cloud Enterprise home page. Authenticate with the user credentials you defined when you provisioned the cloud service.
  2. Click the hamburger icon in the upper left to open the Oracle Mobile Cloud Enterprise menu.
  3. Click the Bots menu item (shown in Figure 2), which opens the Oracle Intelligent Bots dashboard in a separate browser window or tab.

    chatbots figure 2

    Figure 2: Oracle Mobile Cloud Enterprise dashboard

  4. Click the New Bot icon to create a new bot project.
  5. Enter OracleMagazineOnlinePizza in the Name field and, optionally, enter a description of your choice in the Description field.
  6. Click Create.

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.

chatbots figure 3

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.

  1. Click the green + Intent button.
  2. Enter Order Pizza, replacing any default text, in the Name field.
  3. Enter Order a Pizza in the Description field.
  4. Enter the following example sentences, one by one, to the Examples field, replacing the default Enter your example utterances text prompt, and then confirm each entry by pressing the Enter key.
    I like to order a pizza.
    Pizza please
    Can I order pizza?
    I want a large pizza
    I fancy a pizza
    
  5. Click the green + Intent button (at the top left) and enter Cancel Pizza to create a new intent.
  6. Repeat step 10 using the following values:
    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
    
  7. Click Train (at the top right of the screen).

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.

  1. Click the test icon (the right arrow in the upper right of the screen).
  2. Click the Intent option (below the Test header text).
  3. In the Message field, type I like pizza and click the Send button (as shown in Figure 4).

    chatbots figure 4

    Figure 4: Oracle Intelligent Bots integrated tester for testing intent recognition

  4. Ensure the Order Pizza option is selected and click the Add Example button.
  5. Click Train.
  6. With the I like pizza text in the message field, click the Send button again.
  7. Now replace the text in the Message field with Gimme a pizza.
  8. Click the Send button.
  9. Replace the text in the Message field with Ignore my order, and click the Send button. Note how this text resolves to the Cancel Pizza intent.
  10. Click the test icon to close the tester.

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.

  1. Click the Entities menu item (on the left, below Intents).
  2. Click the green + Entity button.
  3. Name the entity PizzaType.
  4. For Configuration -> Type, select Value list.
  5. Add the following values by clicking the +Value button, entering a name in Value field in the Create Value dialog box, and clicking the Create button after each new value is entered to close the dialog box.
    Cheese
    Veggie
    Pepperoni
    Supreme
    Chicken
    
  6. Add one more value, meat lover, and add meat and beef to the Synonyms field in the Edit Value dialog box—pressing Enter between the synonym entries—and click Update.

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.

  1. Repeat steps 25–28 and create a PizzaSize entity with the following values and their synonyms (included in parentheses).
    large    (big, lrge, lrg)
    medium   (med)
    small
    
  2. Select the Intents menu item (on the left).
  3. Select the Order Pizza intent.
  4. Click the green + Entity button (on the right).
  5. Scroll to and select PizzaSize.
  6. Scroll to and select PizzaType.
  7. Click the test icon (the right arrow in the upper right).
  8. Click the Intent option (below the Test header text).
  9. In the Message field, type I like a big pizza supreme and click the Send button.
  10. Notice the entity and entity values recognized in the request string.
  11. Click the test icon to close the tester.

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).

  1. Click the Flows icon on the left.

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"
  1. Before you can create your own conversation, you need to do some housekeeping. First, in the flow editor, delete all content in the states section: delete everything below states.
  2. Also delete the greeting and name variables in the variables section.
  3. Optionally, delete all comments starting with a # character for a cleaner look.
  4. Create new variables as shown below. Ensure that the indenting of the new variables you create uses two initial blank spaces more than what is used for variables.
    variables:
      iResult: "nlpresult"
      pizzaType: "PizzaType"
      pizzaSize: "PizzaSize"
    
  5. Place the cursor below states.
  6. Click the green + Components button and select User Interface.
  7. Select Output in the left menu (you might need to scroll) and toggle the Remove Comments control so it is enabled.
  8. Click the Apply button.
  9. In the flow editor, change output to welcome. The welcome state should be indented two blanks further to the right compared to states.
  10. Click the Validate link in the upper right. If this shows a green alert, your formatting is correct. If it shows red, then hover your mouse over the red overlay in the left margin of the flow editor to learn about the problem.
  11. Place the cursor to the right of text: and type Welcome. I am a pizza bot. Can I have your order please?" (including the surrounding quote marks).
  12. Click the green + Components button and select Language.
  13. In the left menu, select Intent. Ensure the Insert After drop-down list shows welcome and click the Apply button.
  14. Edit the intent component so it looks as shown below. Be sure you get the indenting right—each indent uses two blank spaces.

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.

  1. Click the green + Components button and select User Interface.
  2. Select Output in the left menu, ensure the Insert After drop-down list shows intent, and click Apply.
  3. Rename output to unresolved.
  4. Edit the unresolved code in the flow editor to look as shown below:
    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.

  1. Click the green + Components button and select User Interface.
  2. Select List – set variable in the left menu (you might need to scroll) and ensure the Insert After drop-down list shows unresolved.
  3. Click Apply.
  4. Rename variableList to startOrder.
  5. Edit the startOrder state code so it looks as shown below (again, pay attention to the indenting).
    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.

  1. Click the Validate link (in the right upper right) to ensure your code formatting is correct. If it is not, correct it.
  2. Repeat steps 60–62, but make sure the Insert After drop-down list shows startOrder.
  3. Rename variableList to askSize and edit the state code so it looks as shown below:
    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.

  1. Click the green + Components button and select User Interface.
  2. Select Output in the left menu, ensure the Insert After drop-down list shows askSize, and click Apply.
  3. Rename output to printOrder.
  4. Edit the printOrder state code to look as shown below:
    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.

  1. Click the test icon in the upper right.
  2. Click the Reset button in the header of the tester to reset the test environment.
  3. Ensure the Bot link is active in the header of the tester.
  4. Type Hi into the Message field and click Send.
  5. After the bot displays the welcome message, type I like a pizza with cheese on it, please into the Message field and click Send.
  6. Because you did not specify a size for the pizza, select one from the displayed list. In response, the pizza bot should display a message saying that your cheese pizza of the selected size is complete.
  7. Try another. Type Hi into the Message field and click Send.
  8. Now type I like pizza into the Message field and click Send.
  9. Select a pizza from the list and then select a size.
  10. Try a last order. Type Hi into the Message field and click Send.
  11. Type I like a medium size pizza cheese and click Send.

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:

  1. Go to the Oracle Intelligent Bots dashboard.
  2. Click the Import Bot button in the upper right of the dashboard.
  3. In the opened dialog box, navigate to the location to which you saved the downloaded zip file and select it.
  4. Click Open.
  5. Close the upload confirmation dialog box by clicking the X at the right side.
  6. If you already have existing bots defined in your environment, chances are good that you won’t immediately spot the downloaded bot. To find the bot, type OracleMagazine into the Filter field above the green New Bot + icon.
  7. Click the OracleMagazineOnlinePizza bot to open it.
  8. Click the Train link in the top menu on the right side. The link should show an exclamation mark because the bot is not yet trained after the download and import.
  9. Click the test icon to try the downloaded bot.

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

TRY Oracle Mobile Cloud Enterprise and Oracle Intelligent Bots.

LEARN more about Oracle Mobile Cloud Enterprise and Oracle Intelligent Bots.

DOWNLOAD the bot for this article.

Photography by Getty Images/iStockphoto