Augmenting Conversational UIs with Chitchat

Noah Huber-Feely
Jun 28, 2017 · 4 min read

I’ve recently begun revamping and expanding my own conversational user interface for the PAL (Personal Assistant & Learner) system I’ve built. While developing out its ability to handle more and increasingly complex tasks, so I can automate or at least streamline the majority of my daily operations, I realized that to have a truly compelling experience, it needed to be able to handle general conversation. After saying “Remember that I need to update the bylaws by our next meeting” and it replying “I’ve added the task to your to-do list for completion by 10:00 AM tomorrow.”, I should be able to fire off “Sweet!”, “Thanks!” or any of a myriad of possible appreciative statements. I could code out some simple logic for this to detect instances of a laundry list of these words and then have a simple bank of possible replies.

However, could a system like this scale as the number of possible things I could say increases. And how can I best have the system handle instances where instead of saying “Thanks. You are great!”, I say “Thanks. You are the best!” if this other possible reply isn’t programmed in? A framework for this kind of chitchat would make this immediately better and more powerful. There were a couple subpar solutions out there and some that didn’t allow one to properly structure and vet replies and responses. These generally focused on being an all encompassing dynamically learning chatbot, instead of augmentation to a conversational UI.

The Solution

With this problem in mind, I started building Clara, a framework that enabled one to hold this sort of chitchat when one of the commands (what I’ll call skills) are not being requested. The idea was to store possible statements and appropriate responses in structured JSON, and then create a system which accepts a user input and then using Levenshtein Distance computes the closest match in the JSON info. Then, using a simple statistical distribution, chooses one of the preset possible responses and outputs this to the user. This enables it to give a proper response, while also allowing the user to ask the same thing twice and receive different but similar responses each time.

The initial setup included a file and a directory convos/. Any JSON file inside the convos/ directory would be loaded by and indexed for later searching. This allowed one to easily drag and drop new conversation elements by the simple copying of a file into the directory. This would enable the distribution of statements and responses to be as streamlined as possible. Then it would open a command line and do the above operation.

I then developed a web API for the system which could be easily launched on any system with minimal setup using Flask. Simply executing python3 would start up the local Clara instance.

With this API now in place, I quickly set up a Heroku instance running it and plugged it into PAL for when the system didn’t detect I was invoking a command. PAL uses the robust Adapt intent parser built by the Mycroft team, and in my testing very rarely didn’t properly detect when I was invoking a command, or accidentally activate on something unrelated.

After this integration, the profound utility and system boost was very clear. I could now greet the system, ask it what it was up to, and relate how I was doing and query the system regarding how it was as well.

Because it became clear that emotional and mental state were important components of the system, I built a qualifier system and a simulated emotion utility. This enabled responses to be specifically reserved for when the system was happy, and I could also have it respond differently if the Clara instance was stressed. Although purely artificial, Clara quickly became much more life like with this update.

Utility and Integration

Anyone building a chatbot must be able to handle chitchat for their system to be user-friendly for the general population. Although one could hard code the logic for the query “Who is your creator?” this doesn’t scale as you need to handle more statements, and if you fail to also add “Who created you?” as a possible response, a system like Clara will be able to easily determine this input is very similar to the “Who is your creator?” you entered and deliver the proper response.

To check out Clara, you can view the repo at it’s GitHub page. You can get the system up and running on Heroku in an instant and integration is fairly straightforward.

Warning: The system is still at a fairly alpha level of development (and only works with Python 3.x), so although it has worked well for me, I haven’t tested and refactored it enough to safely recommend you deploy it as a core infrastructure. However, it might easily work perfectly and give your chatbot that leg up it needs to reach success.

Noah Codes

Noah Huber-Feely’s Blog