Week 1: Personal AI Assistant

This article is part of a series: File, New: Personal AI Assistant

One week down and thankfully, the project is on track! This week’s sprint objective was to ‘Build a simple console-based chat bot, powered by a mildly-trained AI engine’, and so far, so good:

Screen Shot 2017-06-20 at 22.32.21

The biggest challenge I faced this week was learning how to train my Wit.ai bot engine. Unfortunately, most of the tutorials and demonstrations across the web are outdated, and the current Wit tools and concepts have changed significantly. There’s some good documentation on the official website, but it’s mostly geared towards utilising the API and not very descriptive when it comes to explaining to a complete beginner how to train your bot.

It therefore took a lot of trial and error, which fortunately was made easier by studying the source code of this library. I felt that for my purposes, I would want to customise how this library works, and so I embedded a copy of the .csproj in my project solution.

Training the AI engine

I needed a simple task that I could get my application to perform, so I decided that the first thing I would teach it to do was recognise a request for the current time. I began here, inputting a variety of sentences that contained the word ‘time’, and applying the ‘time’ keyword to my custom time entity:

Screen Shot 2017-06-20 at 22.48.09

After inputting as many variations of the same question as possible (“tell me the time”, “what time is it?’ etc.), I moved onto the Stories tab. Here you can create your ‘stories’, which are example interactions that would happen between a user and the bot. I created my ‘time’ story as such:

Screen Shot 2017-06-20 at 22.55.32.png

To explain this in a little more detail,

  • The bot recognises the ‘time’ keyword in the user’s request
  • The bot then returns with an action to perform, in this case “time” (which is predefined in my code)
  • My code returns a string value with the system’s current DateTime as a context object defined with a “currentTime” key
  • The bot returns a constructed sentence with the user’s DateTime value included.

Artificial Dumbness

The above works great with my code, which I’ll dive into below, but the problem I’m facing now is that since the time keyword is the only thing that I’ve taught my bot to understand, it doesn’t understand anything else, which leads it to make a wild guess – and the guess is almost always that I’m making another request for the time (with a ‘confidence’ factor of almost zero). So, my next task is going to be to teach the engine some other features, so that I can be sure that my AI will be able to differentiate between a request for the time and, for example, a request for the weather forecast. These are some of the things I’ll aim to teach it:

  • Weather forecasts
  • News headlines
  • Travel updates
  • Latest tweets / composing and sending tweets
  • Telling the time in different timezones
  • Movie listings
  • Setting a timer / alarm

I have more ideas in mind, but with each feature there will be the task of building the functionality for accessing various APIs and data sources, so as I add more features the amount of time it’ll take to achieve increases exponentially. I’m hoping that this handful of features will be enough to smarten up my AI, and won’t put too much stress on my timescale.

The source code

As promised, I’m keeping all of my work open source and freely available to anyone who wants to make use of it, under the MIT license. The repo is here.

To create my console-based concept, I created a PCL project which holds my App class, and all of the services I’ll be making use of. In that project I have referenced the Wit.NET project that I’ve mentioned above, allowing me to create a WitService class to manage the conversations. Here’s my WitClient:

public class WitService : IWitService
{
    Wit _witClient;
    WitActions _actions;

    public WitService()
    {
        _actions = new WitActions();
        _actions["send"] = Send;
        _actions["time"] = TellTheTime;

        _witClient = new Wit("", _actions)
        {
            WIT_API_VERSION = "20170307"
        };
    }

    public void BeginInteraction()
    {
        _witClient.Interactive();
    }

    WitContext Send(ConverseRequest request, ConverseResponse response)
    {
        Console.WriteLine(request.Message);

        return request.Context;
    }

    WitContext TellTheTime(ConverseRequest request, ConverseResponse response)
    {
        request.Context.Add("currentTime", DateTime.Now.ToShortTimeString());

        return request.Context;
    }
}

As you can see, there are 2 actions set up so far: the send action, which is required by default, and a TellTheTime action, which sends the current time string as a context entity to the AI.

The BeginInteraction() function calls the Interactive() property of the Wit client, which begins an interaction with the AI bot.

On to Week 2

The objective I’ve set for this week is Train the engine to understand commands that I want my assistant to act upon, and with the above list of features I hope to train into my AI, I’ve got my work cut out for me this week. The main challenges will be training for interactions which require multiple inputs from the user, for example:

user > “Compose a new tweet”

AI > What would you like your tweet to say?

user > “This project is incredibly challenging!”

AI > Awesome. Tweet sent!

 

If you want to know how I get on, follow the blog!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s