Friday, July 29, 2011

In development: Parsing statements

The singleton and events have been implemented. It appears to be working.

As I try to create response patterns, I quickly deviated to parsing messages to handle multiple statements. Some helpful code that helps make this easier is comparing strings without case-insensitivity:

return sText01.Contains(sText02, StringComparer.InvariantCultureIgnoreCase);

Another helpful code is the ability to search by specific properties within an object:

Message msg = _Brain.Dialogues[SessionId].History.Find(
delegate(Message msg2)
{
return msg2.Value == "Existing message here";
}
);

Once I attempted to break out any multiple statements, I tried to break statements into subject, verb, etc. Quickly this got out of hand too since I do not have all the information I need.

Focusing back at just giving some simple commands, the next step is to start creating the back-end stuff. This might take a while as I'd like to see the capabilities of linq.

Thursday, July 28, 2011

In development: Adding events and singleton

I diverged a little from creating static responses while thinking how to generate a learning type of AI. Now that I separated the MW from the UI, I thought it would be interesting to try to design the MW more like a person. Thus I created a brain where most of the functions or generated.

In the brain, I started with generic senses of touch, smell, see, hear, and taste. Besides hear, the others senses will just currently be not implemented. I just thought it interesting to leave it open for possible future enhancements. Hear and see are very plausible.

For output, I only added speak at this time because there are no other simplified generic list of outputs.

The next step was difficult as I read through the different senses, brain, thought, and philosophy of thought. There is little that we fully understand so at this point, I just decided on what I am most comfortable and familiar with. It may be completely wrong but might as well figure out why it's wrong that thinking it all through.

I went with creating a conscience as a separate entity that "listens" to certain brain functions. The internal working of the brain, I will classify as sub-conscience although I could separate it out but that can be implemented later.

Since my AI will just have one brain and one conscience, I made these singleton types so that only one instance is guaranteed. The conscience will access certain parts of the brain, in particular the listening buffer. An event is created whenever the brain hears something. Another event is a timer to periodically check certain statuses (primarily create responses when silence has reached a certain period of time).

The step I am considering now is about memory. I am leaning towards creating a sensory, short-term and long-term memory architect. Sensory would be the instant responses like hi, hello... perhaps just recalling that we had already greeted at some point. Short-term will be things discussed but not beyond the conversation. Could potentially add a limit to the queue to "forget" certain things if the conversation becomes long but that's another phase. Long term will be important facts stored in the data-base. I haven't quite figured how to release all this yet though.

Saturday, July 16, 2011

New interaction, plus two new modes, minus some responses

http://www.dlastlee.com

The interaction has been updated as previously mentioned. Took some time to modify the AJAX interface to play the way I want to. There is a two second delay to allow users to send multiple messages before the AI responds.

To test this, I have created a mode to copy the user. By sending a message to "copy me", the AI will switch to a mode to copy the user. The user messages are queued, then the AI will respond in the same order. The mode will last a random number of times with a maximum of 15 before it gets "tired" of playing.

To further additional modes, a simple game was also implemented. This can be triggered by entering "play guess number". It is not complete, but the portion to generate a random number and allow the user to guess is published. Depending on the number of guesses, a different response is given. The breaks are if you finish within 20% of the possible numbers, 50%, and just completing.

Responses have also been modified to allow multiple responses, although a delay has not been implemented. They will appear almost instantly. I may or may not modify this in the future as it's more a UI modification.

I have also separated the library of messages to its own static class. A useful functionality I found was also searching arrays with ignoring cases:
array.Contains("str", StringComparer.InvariantCultureIgnoreCase);
array.Contains("str", StringComparer.OrdinalIgnoreCase);
array.Contains("str", StringComparer.CurrentCultureIgnoreCase);
[[source: http://stackoverflow.com/questions/952679/how-can-i-make-array-contains-case-insensitive-on-a-string-array]]

There is a lot of places for improvements in the response. One of the tricky parts of redundancies in similar terms with almost the same definitions. A simple example is different ways to agree to a question (e.g. y, yes, Y, Yes, of course, definitely, sure, why not, etc.). Besides case sensitivity, there is also misspelling. If a user mistypes yes as yse (sic), it is still highly possible it was meant to be yes. This is especially more useful for larger words. Another case is for words that are commonly misspelled or have multiple ways of spelling. To understand that a person may be speaking of Johnathon but may spell the name as Jon or John, Jonny, etc. Or "their" vs "there".

Next step will primarily be concentrating on how a figuring out the topic of the conversation, learning more of the user, and maybe start on some database stuff.

Monday, July 11, 2011

Attempting at a basic conversation AI

After finally saving enough to buy and build a system, I went over the long list of ideas that I've been wanting to build. I went through many iterations, and one that I seem to have got stuck on is building a conversational AI.

There are some things in life that a person just wants to see what he's capable of and this is one of those things for me. So please no solutions; maybe a gentle nudge or better yet a challenging question to my methods.

So I have been working on this for a couple weeks on and off. My first version of course was very simple model to respond to the user's response. This is primarily to set up my development environment and make sure things work. I worked through a few kinks in the JavaScript side.

I then attempted to start building lists of similar texts so that there is more dynamic responses. I simply used the Random class to generate which text to pick. Some examples include greetings like "hi", "hey", "hello", etc.

Then there were certain user messages (i.e. statements or questions) that have similar meanings thus the response would be the same set: "How are you?", "How're you?", "How're you feeling?", "What's up?", etc.

The latest obstacle was handling multiple level questions. If a user responds to a question, then the user's message is dependent on the question. Thus I have to remember what I asked to respond properly. If the user responds "Yes", I will need to provide a response appropriate to the question asked (e.g. "Are you bored?", "Are you hungry?"). It wouldn't be right to say "Go eat something" when I asked "Are you bored?".

Next step is to add a back-end to the application. Recently, I just haven't had time to take a break from developing the middle-ware.

I also need to vamp up the front-end to better handle a different style of conversation. Currently the message-response model cannot handle someone that splits ideas among several lines. This requires a lot of change to the conversation topics. In the mean-time, the AI should be able to send multiple messages.

It'll probably be a while till my next code update.