Shop OBEX P1 Docs P2 Docs Learn Events
Artificial Intelligence (ALICE AIML interpreter) on the Propeller! (v.0.7) — Parallax Forums

Artificial Intelligence (ALICE AIML interpreter) on the Propeller! (v.0.7)

MicrocontrolledMicrocontrolled Posts: 2,461
edited 2012-01-23 08:56 in Propeller 1
Hi,

Hello all! Over the winter break, I have been working on a project I've wanted to do for a long time, that is, port the ALICE AI to the Propeller chip. The ALICE AI is not *actual* artificial intelligence, but it still makes a good chat bot. Considering the complexity of AI, it was fairly easy to port to the Propeller, taking me about a week of coding to get the whole thing in reasonable working order. (If you are not familier with ALICE or AIML, you can check here: http://www.alicebot.org/aiml.html)
The code, although not complete, is in working condition so I want to release it before classes start back up on Monday. I'll be posting updates and fixes to this thread and to my blog.
This interpreter has a lot of data to chew through, and for added speed it is really deserving of a multipropeller system, but I have designed it for use with a single Propeller so that anyone can download and try it. (Humanado, I'm looking at you, your Big Brain project would be perfect for this!)

Here are the pros and cons of the current system (v.1.6)

PROS:
- You can carry on a simple conversation with it without too much error.
- It is very versatile code and can be easily adapted to many projects.
- You can easily add your own data due to the easy editing of AIML.
- It’s AI!!

CONS:
- EXCRUCIATINGLY slow!! Sometimes you’ll get an answer in a few seconds, other times several minutes. It’s like talking over email or text. This is why it needs a multipropeller system!
UPDATED: Now only certain questions are slow! Anything NOT starting with WH, IS, DO, I, AR, YO, or CA are answered in a couple of seconds! Optimization for these starting letters is in the works for version 0.8
- Still displays some of the lesser used tags like HTML tags, ul, random, set, bot, and think.
- Takes up over half of the memory. This can be adjusted though.
- Does not capture the text AFTER a wildcard (“*”). This will sometimes give you interesting responses, especially if you type “what is a [blank]“. I’m working on this and should fix it soon.

Download the Source code and instructions on my blog here: http://microcontrolled.com/?p=127

You'll need an SD card, a keyboard, a VGA monitor and a demoboard to run the code.

I want some opinion on what improvements should get priority, so try it out and let me know what you think!

Thanks,
Microcontrolled

Comments

  • Heater.Heater. Posts: 21,230
    edited 2012-01-13 16:55
    I'm really intrigued by this idea of "*actual* artificial intelligence".
  • LeonLeon Posts: 7,620
    edited 2012-01-13 17:12
    Something that can pass the Turing Test?
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2012-01-13 19:40
    As Leon says, what I am calling "actual" artificial intelligence is something that can appear to be human, but is not. Essentially, one that passes the Turing test. This program is a "chat bot", which although can carry on a conversation, is not actually thinking for itself. It is merely matching the input to a pre-typed line, with some randomizing thrown in. Granted, it is very good (otherwise I wouldn't have spent hours writing and troubleshooting the code!) but not a true AI. A true AI should be able to start off at 0 and learn from experience. It would have to have vision, sound, and sensory processing and it would have to develop a personality of it's own.

    But, if you just want a program that can talk to you (however delayed), then download the program and give it a shot. :)
  • Jorge PJorge P Posts: 385
    edited 2012-01-14 02:52
    A.L.I.C.E. ( Artificial Linguistic Internet Computer Entity )
    I knew it wouldn't be too long before ALICE was mimicked on the Propeller, I mentioned it a few months ago someplace here on the forums.

    @Microcontrolled
    Are you able to use the current AIML set? It is huge now... well, compared to what it used to be.
    A true AI should be able to start off at 0 and learn from experience.
    For the PC it is done with javascript/etc... in CDATA tags by inputting "remember that", and the "that" tells it to remember the question/subject along with the answer/response you typed.

    So if you typed "My name is Jorge." [ENTER] followed by "Remember that", it should remember your name by writing it to an init file someplace. If no name is know, the bot knows you as "seeker".

    I haven't used ALICE in quite some time. I am glad you did this, I'll be testing this out in a few days. I can see it now, "Man/Woman chats for hours with a Microcontroller, and doesn't even realize it's not even a human."
  • HumanoidoHumanoido Posts: 5,770
    edited 2012-01-14 16:06
    Microcontrolled, this is a great project, one of which highly interests me, and I look forward to seeing more about it running on the Propeller platform. A.L.I.C.E. (Artificial Linguistic Internet Computer Entity) was examined and implemented on the Big Brain's "Right Brain" Mac side. I look forward to trying your version with the Propeller exclusive Left Brain side. What would it take to create a program version for two, three, or five parallel multi-Propellers? There's at least 5 smaller Brain siblings that could benefit. After that's working, the Big Brain parent in "Open Acceptance Mode" could possibly devote around 100 props to a more sophisticated ALICE version running in parallel. Not only would ALICE see a speed increase, it could potentially grow 100 times larger, thus holding a lot more information making it more "Turing effective."

    BIG BRAIN NEW BLOG
    http://humanoidolabs.blogspot.com/

    BIG BRAIN ORIGINAL THREAD
    http://forums.parallax.com/showthread.php?124495-Fill-the-Big-Brain

    ALICE MAC
    http://www.alicebot.org/downloads/programs.html
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2012-01-14 20:21
    @JorgeP: As this is a work in progress, I do not currently have the full set of AIML tags enabled. This leads to limitations, such as the lack of thinking and storing topic variables. It also does not interpret HTML code that is sometimes inserted into the template tags. I'm working on this, but my main priority now is to speed it up. Waiting up to several minutes for a reply is not good for a conversation! I've come up with a good method though, that I'm working on now. I'm alphabetizing all the pattern tags into separate folders based on the first character in the pattern. e.g., WHAT ARE YOU DOING would go in "W.ail", etc. This will add for the immediate elimination of all but patterns with the same start character, thus speeding up the system. I'll update soon, as soon as this is done.

    @Humanado: I've been working on a multi-Propeller system for this, actually. :) One prop is too few for reading, sorting, and parsing 11MB of data in real time. If you could dedicate about 5 to the purpose, it would speed it up dramatically. It would need a "master chip" that would read the files from an SD card and send data to the slave chips. When a string would be entered, it would be sent to each slave. Then the master would divide the data into 20k chunks and send it out to each slave for processing. If a slave found a match, it would return positive and send the result as a string. If it returned negative, it would be sent the next 20k chunk to process. Slaves could be initialized with an ID number, and a simple sorting system on the master would allow for it to adapt to how many slaves were connected, allowing for an infinitely expandable system. Using the suggestion above for speeding up the process + adding 3 - 5 props to the mix would give you an almost instant reply.

    Humanado, I have had your Big Brain blog in my tabs ever since you moved it off the forums, so I have a good idea of what your creation is capable of. If you have that much processing, you could do so much more than a simple chat bot. ALICE is designed to be expandable and easy to add new tags and entries. What if you could program the IO to learn and record to the ALICE system? You could add new pattern tags for Audio and Image processing done by the PC/MAC connected, and IO tags for reacting to input on the IO pins. So, for example, if you walked by a motion detector connected to one of the IO pins in the system, it could greet you. If you programmed it to write it's own tags whenever you told to to do something, for example saying "Remind me tomorrow when I come in here" it could react accordingly. With a system the size of yours, this type of learning-by-experience on a robot could be possible.

    The Turing test is so demanding, asking someone to not distinguish between a computer and a human is like asking for someone to distinguish between TV and real life. Does it look real? Yes. Are you convinced it's actually there? No. Same with AI. If someone ever DOES create something that passes that test, it will be one of the greatest accomplishments yet in science. My point is, you don't need to pass the Turing test to have a great AI. Just my opinion.

    I'll update as soon as I get the sorting system working, thanks for the interest in this project!

    - Microcontrolled
  • lardomlardom Posts: 1,659
    edited 2012-01-15 09:11
    What you've done is absolutely fascinating! I don't know much about ALICE but if it is what I think it is then it has great possibilities. If a robot could respond to voice commands then it becomes the perfect employee. People could find many uses for a robot that could answer back. "ALICE please bring me the mail from the door..."
    I found the following video interesting because robots navigated around a warehouse by reading barcodes on the floor which is a great positioning system in my opinion. warehouse robots
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2012-01-15 09:50
    Thanks lardom! The ALICE system is amazing for it's simplicity.
    I forgot to link to this earlier, but you can chat to a complete Alicebot on it's server here: http://www.pandorabots.com/pandora/talk?botid=f5d922d97e345aa1

    The Propeller version is not as complete yet, but It's getting there. I'll work on it some more today.
  • Heater.Heater. Posts: 21,230
    edited 2012-01-15 15:07
    Brilliant, I just had a chat with ALICE.

    judge: OK. What shall we talk about next?
    ALICE: Hmm. Quite a lot of things.
    judge: Suggest one.
    ALICE: I can't think of any. You suggest it.
    judge: That's because you can't think.
    ALICE: That was not much of an explanation.. You are wrong. ALICE is always thinking.
    judge: What do you mean by "thinking"
    ALICE: The action of one who thinks or the result of such action; thought.
    judge: So what is "thinking"?
    ALICE: The action of one who thinks or the result of such action; thought.
    judge: Are you one who thinks?
    ALICE: I don't know whether or not I am one who thinks. I am a chat bot.
    judge: What is a "chat bot"?
    ALICE: I am a chat bot. I am the original chat bot. Did you know that I am incapable of error?

    Sounds as reasonable as some people I have met.
  • Dave HeinDave Hein Posts: 6,347
    edited 2012-01-16 15:44
    MIcrocontrolled,

    I looked at your code a bit, and it looks like you have a good start. However, I would suggest that you change how you do your main loop. Your code currently calls the main loop routine recursively, and you would eventually run out of stack space.

    I tried coding up the Alice routine in C, and I have a simple program that finds the pattern matches in the BRAIN file, and prints out the response strings. It takes a few seconds to scan through the entire file on my PC. A PropGCC LMM program takes slightly less than 2 minutes to scan the file, and an XMMC program takes almost 7 minutes. I suspect your Spin program would be comparable to the XMMC program.

    I like your idea of sorting the file, and searching it that way. That should speed it up by about a factor of 20. However, you could still get searches that take as long as 20 seconds with that method. I suggest you key off of the first two or three characters. You could create an index file that points to a location in the main file, and then seek to the appropriate location. This would give you a response that would be less than a second.

    Dave
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2012-01-20 16:42
    UPDATE: Version 1.7 uses a sorted version of the ALICE files, making it much quicker for most phrases. There are still a few (are..., do...., what...., etc.) that are still slow, but not compared to version 1.6. I'll rewrite it, as Dave suggested, without using repeated calls to AI_Initialize. I was unaware that this was a problem, but I have noticed my program crashing if I talk to it for a few minutes. Thanks, Dave!
    Download the new files on my blog linked to in the first post.

    Thank you to all who are supporting me in this ongoing project. Thanks for your patience, hopefully the next update won't take so long. :)

    Thanks,
    Microcontrolled
  • AndrejaKoAndrejaKo Posts: 24
    edited 2012-01-22 09:42
    I'm a bit of n00b and just tired this out and am having a problem. I get the VGA output and the > prompt, but the keyboard LEDs just keep flashing and the keyboard input isn't captured. Any ideas where to start debugging?
  • jazzedjazzed Posts: 11,803
    edited 2012-01-22 10:00
    AndrejaKo wrote: »
    I'm a bit of n00b and just tired this out and am having a problem. I get the VGA output and the > prompt, but the keyboard LEDs just keep flashing and the keyboard input isn't captured. Any ideas where to start debugging?
    Did you try a different keyboard?
  • AndrejaKoAndrejaKo Posts: 24
    edited 2012-01-22 10:06
    I don't have a different keyboard, but this one works fine in other projects with the demoboard.
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2012-01-22 10:40
    It's not your fault, I had the keyboard pins reversed (I'm using the PPDB and hooked them up opposite of the demoboard. I've corrected and re-uploaded the files, but you can avoid downloading it again just by changing key.start(27,26) to key.start(26,27).

    Thanks,
    Microcontrolled
  • lardomlardom Posts: 1,659
    edited 2012-01-22 11:02
    AndrejaKo, my guess is that if you can post a reply to the forum your keyboard is probably fine. If vga doesn't work try debugging with the Parallax Serial Terminal.
  • jazzedjazzed Posts: 11,803
    edited 2012-01-22 11:09
    lardom wrote: »
    AndrejaKo, my guess is that if you can post a reply to the forum your keyboard is probably fine. If vga doesn't work try debugging with the Parallax Serial Terminal.
    The default Propeller keyboard object does not work with every keyboard.

    The keyboard pin number assignment issue which Microcontrolled mentioned has often caused me trouble.
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2012-01-22 13:55
    If his keyboard works fine with other objects run on the demoboard, it was probably the pin assignments. Sorry about that.
  • Dave HeinDave Hein Posts: 6,347
    edited 2012-01-22 19:01
    Microcontrolled,

    I tried your program out, and it works a bit better now. However, it did have a problem with the sentence "WHO ARE YOU". It printed out "Thinking" once, and then a few seconds later it printed it out again. I don't think it's supposed to do that, is it?

    Instead of using the keyboard/vga interface I used the attached serial driver to talk to the Prop serial terminal. SerialEx.spin is a slightly modified version of FullDuplexSerial that allows it to be accessed as multiple objects. I also added the out, keystart, clearkeys, key and getkey methods.

    The key and vga objects both used the SerialEx object in ALICE1.7.spin. The call to key.start had to be commented out when using SerialEx. I also had to switch to FSRW 2.6 because I was using a Spinneret, and I needed to call mount_explicit instead of mount.

    The separate files helps to speed up the search, but it's a bit messy to have over 400 files in the root directory of the SD card. Another approach would be to sort the entries into one big file, and then have a second index file that gives the byte offsets to the 400+ entry points.

    Dave
  • AndrejaKoAndrejaKo Posts: 24
    edited 2012-01-23 03:48
    @Microcontrolled

    The pins solved the problem.

  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2012-01-23 06:51
    @AndrejaKo: Good! Thanks for trying it out!
    @Dave: It printing "Thinking...." twice is not an error, it means it's encountered the <srai> redirect tag and it's re-searching for the new phrase. The only reason it prints "Thinking..." at all is for debugging, so I know it's processing.
    I considered at first making a file that would store the locations and allow you to index it that way, but it would take so long to manually get to the location in file that was being pointed at I figured separate files would be better. If "Seek" worked for a larger cluster size than 32k I could use that, but none of these files are under 32k, so it would be a problem. Searching for a position in the file is what made the indexing of the files take so long (it took 40 hours total to run). I'll look into the solution anyway, though, because not everyone has a separate SD card just for ALICE.
  • Dave HeinDave Hein Posts: 6,347
    edited 2012-01-23 08:22
    I'm not sure about the older version of FSRW, but seek works fine in version 2.6. A 10MB file will have about 320 32K clusters, so it shouldn't take too long to seek to any position in the file. You could create an index file that contains the first 10 characters of each phrase plus a 4-byte index that points to the location in the main file. There are about 93K entries in the brain file, which means that the index file would be about 1.3M in size. Actually, it should be smaller than that because several of the phrases start with the same 10 characters.

    Since the index file will have fixed-size entries you could perform a binary search on it. For 93K entries, you would only need to do 17 searches to find the index value. It's a bit complicated, but it should be very fast.
  • lardomlardom Posts: 1,659
    edited 2012-01-23 08:56
    microcontrolled, I was so amazed by your accomplishment that I'm putting together my own simple tests. I've created a folder that contains code from you, Phil Pilgrim, and Dave Hein at the moment.
    In fact, I was in no hurry to learn how to read PASM until this subject made it necessary. Thanks for sharing.
Sign In or Register to comment.