Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Personifying Chatbots: A Guide to Realistic Conversation

DZone's Guide to

Personifying Chatbots: A Guide to Realistic Conversation

If you want your chatbot to pass the Turing Test, it needs to be personified and personalized. Luckily, that's not *too* difficult to do!

· AI Zone
Free Resource

Bring the power of Artificial Intelligence to IT Operations. Brought to you in partnership with BMC.

Imagine that you are in a conversation with a chatbot and you feel that the human angle is completely missing because the bot starts its dialog with a very simple "hi" or "hello." You may want to personify the conversation by adding the name of the person (who's logged in) to the basic, boring greeting. Ever thought of this? What about appropriately responding to a user based on the time of day that they invoke your chat application? And what about passing values back and forth during a conversation between nodes or from the application to a node?

How can you make your dialog stateful?

Using context variables, the application can pass information to the dialog, and the dialog can update this information and pass it back to the application. A context variable is a variable that you define in a node, and optionally specify a default value for. Other nodes or application logic can subsequently set or change the value of the context variable.

You can define context variables with a default value on the Dialog tab of your Watson Conversation Service on IBM Cloud. You can test your dialog with context variables and system entities even before incorporating it into your application.Context variables

To understand the various building blocks of conversation, refer to this post.

Passing Context From the Application

Pass information from the application to the dialog by setting a context variable and passing the context variable to the dialog.

For example, your application can set a $time_of_day context variable and pass it to the dialog, which can use the information to tailor the greeting it displays to the user.

Shows a Welcome node that uses response conditions to check for the value of the $time_of_day context variable that is passed to the dialog from the application.

In this example, the dialog knows that the application sets the variable to one of these values: morning, afternoon, or evening. It can check for each value, and depending on which value is present, it can return the appropriate greeting. If the variable is not passed or has a value that does not match one of the expected values, then a more generic greeting is displayed to the user.

Passing Context From Node to Node

The dialog can also add context variables to pass information from one node to another or to update the values of context variables. As the dialog asks for and gets information from the user, it can keep track of the information and reference it later in the conversation.

For example, in one node you might ask users for their name, and in a later node address them by name.

Shows an introductions node that asks the user for their name, and stores it as a context variable. The next node refers to the user by name by using the $username context variable.

In this example, the system entity @sys-person is used to extract the user's name from the input if the user provides one. In the JSON editor, the username context variable is defined and set to the @sys-person value. In a subsequent node, the $username context variable is included in the response to address the user by name.

What Are System Entities?

The Conversation service provides a number of system entities, which are common entities that you can use for any application. Enabling a system entity makes it possible to quickly populate your workspace with training data that is common to many use cases.

System entities can be used to recognize a broad range of values for the object types they represent. For example, the @sys-number system entity matches any numerical value, including whole numbers, decimal fractions, or even numbers that are written out as words.

System entities are centrally maintained, so any updates are available automatically. You cannot modify system entities.

System Entities

Defining a Context Variable and Using @sys-person

You can either edit an existing dialog node or create a new node to define a context variable on the dialog. 

  • On your Dialog tab, navigate to an existing node and click to open the node.
  • Under Then respond with, Click on the three vertical dots > Open JSON editor.
  • Just above Output, you will add context as shown below:
    "context": 
      { "username": "@sys-person.literal" }, 
  • Close the JSON editor.

Whenever a name is encountered, the @sys-person entity automatically recognizes it and assigns it to the username context variable. You can use it by calling $username anywhere in your dialog.

You can test it by adding $username to the response condition in your dialog node.Dialog with Context Variable and System Entity

What we have seen up to now is just a drop in the ocean! You can further enhance your chatbot experience with advanced options as mentioned here (treat this as a recommended read).

If you any questions, drop a comment below or reach out to me @VidyasagarMSC.

Happy coding!

TrueSight is an AIOps platform, powered by machine learning and analytics, that elevates IT operations to address multi-cloud complexity and the speed of digital transformation.

Topics:
chatbot ,bot development ,ai ,tutorial ,context variables ,watson convesation

Published at DZone with permission of Vidyasagar Machupalli, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}