Hi There! Little Chatbot
- Voice input and NLP service Wit.ai
- Simple conversation mechanics
- Chatbot on Android with RiveScript
(This is part of a series of reports on my random experiments)
Is this the first post on my new website? WOW it is .
Last week I started exploring the different voice and language interfaces and decided to hack something.
I’ve set a simple goal: “Create an Android application that accepts voice inputs from the user, about the weather and time, and can ask for any missing information needed to come up with the answer.”
Some googling took me to Wit.ai. What a great service!
I’ll let you see for yourself (the website explains it better than I could), but this meant the language and voice input of the problem was, partially, solved.
Wit.ai is great but, only solves the first part of the problem, I still had to work on the conversation bit.
For this I implemented a simple solution (remember, I’m just exploring).
Wit.ai gives me an intent for the input sentence, here’s an example response:
The idea is simple:
- Select the best intent and guarantee the confidence is higher than a threshold
- Look for a suitable conversation for the current intent
- Keep a conversation state that keeps track of the known facts (I named them concepts) so far, including default values for missing facts
- If a fact is mandatory and has not yet been provided, ask a question to the user
- Send the response back to Wit.ai
- This time, check if the response answers needed facts for the current conversation
- If the answer is completely unrelated, assume it is another conversation
- If it answers some but not all facts, keep asking more questions
- If we have all the information we need, look for at Actuator that can… act on this data
A stupid example of a conversation:
How's the weather like?
It's sunny in London!
To achieve this I created two main interfaces:
There is also a Conversation factory that, based on the intent, will create the right conversation object or return null if none can be found.
Pretty soon I realised this wasn’t going to cut it. I was basically creating a very confusing and hard to manage chatbot… I like Wit.ai and all the flexibility you get from it, but I need to explore the conversation side of it.
I’m now replacing the conversations with a standard chatbot implementation.
After some research I ended up more confused than not. There are more chat scripts, markup languages, etc. than I could image. In the end I chose to give RiveScript a trial.
I couldn’t find any Android implementation, but there was a Java one (yes!).
(To help future developers, I submitted an already accepted pull request to build packages you can use on your applications).
So far I only got to the point where I can run the sample scripts on my application.
I didn’t find any show-stoppers on Android but I had to use my own file loading
For simplicity, I added all the required files to the
assets folder and
instead of relying on RiveScript’s loading methods, I’ve loaded the script
contents myself and streamed the results.
Here’s the main initialisation code required (note: I’m new to Java and this is an experiment, comments on how to improve the loading are very welcome):
The goal going forward is to:
- Use Android Speech-to-text capabilities and interface with the conversation scripts using voice.
- Convert the Actuators into a simple reflex agent that can decide what action to execute based on the current conversation state.
I hope any information on this page is of any help to anyone…
To be honest, my goal here really was to start writing and stop just talking about it. I recognise this one is very bland and directionless… but better ones will come .
Have a great day!