Rocketbots Academy Part 4

Rocketbots Academy Part 4

Welcome to Part 4 of the Rocketbots Academy, the final stop on the Academy express!

Today you’ll learn:

  • Your Fourth Task: Creating Foundational Intents
  • The Concept of Context
  • About Building Contexts
  • Your Fifth Task: Building a Context-Free Conversation

The last mile, here we go!

1. Task: Creating Foundational Intents 

Simulating a Conversation

This section is called Simulating a Conversation because a chatbot is nothing more than an expression-response machine. Amazingly, this simple capability allows us to build a convincing chatbot. The key is to have the right intents available for the users to explore.

Foundational Intents

It is unlikely that when you launch your chatbot you will have all the intents you need. However, you do need somewhere to start. Luckily our client, Nantucket Orchards, sent us a list of the 13 most frequently asked questions that they received on Facebook Messenger last month.

Frequently Asked Questions

Intentions / Questions Response Topic Freq Last Month
What is your address? / Can I buy apples at your orchard? You can buy our Apples & Apples Juice at our Orchards. We are located at 27 Forest Road. We are open from 10am to 4pm, Monday to Saturday. Logistics 600
What makes your apples so great? Our Apples are amazing because they are grown with love & care. These are no corporate apples. GS Apples 300
How fast do you deliver? / Do you deliver? We deliver within 2 business days or less. If you have a specific delivery time in mind please let us know. Logistics 250
What is so amazing about your juice? Our apple juice is amazing because of the apples we use and because it doesn’t contain pulp. Apple Juice 240
Tell me about your Apples. Nantucket Orchards grows amazing Granny Smith Apples using seeds brought from Italy by our founder over 300 years ago. GS Apples 200
What sizes can I order your juice? / Does juice come in 1L Jugs? Our juice comes in 1 Gallon Jugs. Apple Juice 180
What is the minimum order quantity for apples? The minimum order quantity for apples is 3 baskets. Each basket generally contains about 2 pounds of apples. GS Apples 160
What is the minium order quantity for juice? Please order at least 3 jugs of juice for delivery. Apple Juice 140
Is your juice made of 100% apples? / What is in your juice? Our juice contains only the Granny Smith Apples we grow at our orchard. Apple Juice 120
Which breed of apples do you have available? We only have the delicious Granny Smith Apples we grow in our orchard. GS Apples 120
Tell me about your Apple Juice. Our Apple Juice is a great way to enjoy the refreshing taste of our Granny Smith apples in a convenient liquid format. Apple Juice 110
How often do you harvest your apples? Our apples are harvested twice per year. GS Apples 60
Do you make your juice fresh every day? We press our juice once per week. Apple juice stays fresh much longer than that though. Apple Juice 40
  

Task 3: Preparation Task

In order to proceed to the next step in your learning please create and train 13 intents to train the above-provided questions & Intentions. Depending on the related product your intent name should be:
  • GS Apples | Name
  • Apple Juice | Name
  • Logistics | Name

Great!

This is all you need to know for the first task in this section.

2. The Concept of Context 

How Context Works

Before we get into terms & definitions, it’s useful to have a practical understanding. In a chatbot, context is nothing more than a lock, that leaves some intents closed. Meaning they cannot be triggered. In the below diagram Context = Apple Juice means that the previous message was about Apple Juice.
 738e9535da922ec58230556b6f9f159c34907997879db42378b2483083708357146058dfac3eb692144c56f1392653f82a2c63391c0ffbc0fb4fbf9ee3dccf6e59142ff5ef665db3c6c7f8b371e858732d9314dbab4c7b44684eed6b44eae7057d9b7234.png
Therefore, by using contexts, we can stop certain intents from being triggered, until that specific context is introduced to the conversation. We will discuss how this is done in DialogFlow below. But for now, let’s clear up some definitions.

Definitions

In this section we will be talking about context, this can be a difficult concept to grasp. Therefore it is important to understand the terminology below.
Context-Full Expression & Context-Full Intent
A Context-Full Expression contains a reference to the topic of the conversation. For example:
  • These Apples are tasty.
  • This apple juice has spoiled.
The intents which are created to capture Context-Full Expressions are called Context-Full Intents.
Context-Free Expression & Context-Free Intent
A Context-Free Expression does not contain a reference to the topic of the conversation. For example:
  • They are tasty.
  • It has spoiled.
The intents which are created to capture Context-Free Expressions are called Context-Free Intents.

The Trouble With Context-Free Expressions

Notice that the bot you created is trained using context full expressions. Therefore your bot can understand:
  • Why is your Apple Juice good?
  • What is so amazing about your juice?
  • What is the minimum order quantity for apples?
  • What is the minium order quantity for juice?
  • How often do you harvest your apples?
  • Do you make your juice fresh everyday?
However, if a person asks your bot: Why is it good? Suddenly there is a problem. The chatbot does not understand. And for good reason, the person has not specified what it is.
If determined what it is from the previous messages and added context-free expressions to your sample data this will not work. Because it may be different in different conversations.

Context in DialogFlow

In order to “remember” the topic of a conversation, DialogFlow has something called Contexts. This module is found above the User Says section of DialogFlow. There is both an input and an output context.
92516031ba4eeefd07495e8bcba9baa7048adb7ce86e6ef776f6d68d68d100a107cc9f5843283532476eb1ba354e1f058394d2c3f08bebdca18deea5286ca741eead8979bdc0d6a4b03cb7853eb4d8ee13199f324e7536d53a65888f1b754b187faccc8b.png
Output Context
The purpose of the output context is to add the topic DialogFlow should remember the current conversation is about.
The output context assigns a context to the conversation. In the example above we have placed AppleJuice. In practice this would be added to all intents that are about Apple Juice. The number in the output context represents the number of turns it will be remembered for.
Input Context
The purpose of the input context is to lock context free intents from being triggered until the relevant topic is part of the conversation.
The input context is used to lock an intent until the context is present in the conversation. Therefore, if we create an intent with the input context AppleJuice, the intent cannot be triggered by the person until the context AppleJuice is added to the conversation by first triggering another intent with AppleJuice set as output context.

3. An Introduction to Building Contexts

Why Context-Free Intents are Required

A natural conversation will go something like this.
  1. Human: What breed of apples do you have? Context-Full
    1. Bot: Granny Smith
  2. Human: How often do you harvest them? Context-Free
    1. Bot: Twice a year
  3. Human: Do you have Apple Juice? Context-Full
    1. Bot: Yes
  4. Human: What is the Minimum Order Quantity? Context-Free
    1. Bot: 3 Jugs
  5. Human: How much is a Jug? Context-Free
    1. Bot: 1 Gallon
As you can see the context is put in place by the human using a context-full expression, then the rest of the conversation continues using context-free expressions until the context is changed again with a context-full expression.

Intents that Require Context

In order to facilitate these kind of conversations with our bot, we need to determine which intents need a context-free intent. From our list of frequently asked questions we see that there 3 pairs of intentions that are similar, but concern different products.
  1. Why is it good?
    1. Why is your Apple Juice good?
    2. What is so amazing about your juice?
  2. Minimum order quantity?
    1. What is the minimum order quantity for apples?
    2. What is the minimum order quantity for juice?
  3. How often is it produced?
    1. How often do you harvest your apples?
    2. Do you make your juice fresh every day?

Adding Context with The Help of the Rocketbots Platform

We use the Rocketbots platform as an intermediary add context to the conversations for 2 reasons
  • DialogFlow output context requires you to specify the number of turns. This gets messy, as we see from the conversation above, we simply need the first context to be overwritten by the second when the conversation changes.
  • DialogFlow only remembers the context for a limited time, around 3 hours (or less). This results in a poor experience as in practice users tend to sometimes try and continue the conversation 1 or 2 days later.
Adding Output Context
We use parameters to add a context to the conversation. We use the parameter name: RB_FIELD_TOPIC_MEMORY and we use the value as the context like below. This will store the context forever until it is overwritten by a new one.
659488264184a354243c681f00b2a07e40d5b99c1742038005802eecbe9653d774cc45f8626dc31a072b3cd8dd0f680a094062de2a5645ad4a724d4d54876e629d6762b5507cbdc45c920f305da12ff8f91b8199a5a7d78472350ad5187514a5a329a636.png
Adding Input Context
Whenever the contact triggers your output context it will be written to the Rocketbots Platform. Then whenever the contact sends a message the Rocketbots Platform will send the context to DialogFlow in the following format: rb-topic_memory-context_name.
Therefore you should add your input context like so using:
  • rb-topic_memory-apple_juice
  • rb-topic_memory-gs_apples
  • rb-topic_memory_logistics

 

087bec0d12506258e81b5a3b978cfa1d0d54cdc339c0987636f7b360bcd7995456d684cf0c6352d4770b9cea9d66e0971fe05b0b1f769927777fcd24d3abb5942b1dc6172dd0e0f7507b18eb01f62969e5986953d82cf1154cb0c21cbabb2112eb90236b.png

4. Task: Building a Context-Free Conversation

Learning Objective

You will gain experience in making context-free intents

Chatbot Objective

  1. Make 6 context-free intents with the following names:
    1. GS Apples (C) | Why is it good?
    2. Apple Juice (C) | Why is it good?
    3. GS Apples (C) | Minimum Order Quantity
    4. Apple Juice (C) | Minimum Order Quantity
    5. GS Apples (C) | How often do you produce?
    6. Apple Juice (C) | How often do you produce?
  2. Add the RB_FIELD_TOPIC_MEMORY parameter to the context-full intents. This add topics to your conversation when people trigger context-full intents Use the following values for your topic memory parameter:
    1. GS Apples
    2. Apple Juice
  3. For your context-free intents, you should add the following lines to the context in section, for each respective intent:
    1. rb-topic_memory-gs_apples
    2. rb-topic_memory-apple_juice

Activating Context Passing on the Rocketbots Platform

Now that you have set up your Context-Full and Context-Free intents in DialogFlow you will need to activate context passing on the Rocketbots Platform. On the Rocketbots Platform Passing via Context allows any custom field to be passed as a context to DialogFlow.
To activate the Passing via Context we must first create the topic memory custom field on the Platform. To do so you must first trigger a Context-Full intent through Facebook Messenger. In our example we can use the intent GS Apples | Why is it good?. Therefore we send the message, Why are your apples good? through Facebook Messenger.
If you are successful in triggering your intent, you have created the custom field Topic Memory on the Rocketbots Platform.
To check if your custom field has been created, go to the Rocketbots Platform and select settings using the navigation drawer on the left.
A drop-down list will show more options, where you can now choose Custom Fields.
Screen Shot 2018-04-13 at 2.22.50 PM.png
There you will see a table of custom fields created in your bot. You should see Topic Memory as below.

Screen Shot 2018-04-13 at 2.09.06 PM.png

There are is assortment of columns here associated with each topic, but for this section, we only need to care about “Pass Via Context”.
Click the three verticle dots at the end of the Topic Memory row and choose Edit Custom Field. This will bring up the settings window for that Custom Field’s settings.
Screen Shot 2018-04-13 at 2.10.44 PM.png
Switch Pass the Custom Field via Context to the API Provider. This will finish the activation of your chatbot’s memory topics.
You may now try to trigger one of your Context-Free intents using a Context-Free expression.

Welcome to the World of Chatbots

Test out your bots context-free intents and add extra training where necessary.
Remember this is only a foundation. The tools and strategies used in your bot building will increase over time.
Congratulations! 
You’ve done it! You just created your very own chatbot without missing a beat. 
Completing this Academy proves that you can build and manage your own chatbots.  
Want to keep it up? Click here to sign up for the Rocketbots platform or extend your trial.

-Congratulations on behalf of The Rocketbots Academy Team

Leave your Comment