This week you are going to create some Artificial Intelligence. Perhaps you won't quite get as far as creating an army of killer robots to do your bidding, but you will make a start. One of the key goals of A.I. research is to program a computer so that it can pass itself off as a human in a blind test. The idea is that a human judge will be allowed to communicate with a number of entities by typing only (never meeting any of them). The judge tries to work out which of the entities are real people, and which are just cleverly programmed computers. The idea being that if a person can't tell whether they are talking to a computer or another person, it would be hard to deny that the computer is behaving intelligently. Or at least as intelligently as people behave. This is called the "Turing Test", in honour of its inventor.
Every year there is an international contest, called the Loebner Prize, to find the program that comes closest to passing the Turing Test. No program has yet managed to fool the judges, but each year a $2000 prize is awarded to the designer of the program that comes closest. Below you will see the transcripts of two sessions in which the 2001 contest winner "talks" with two of the anonymous judges. What the judge typed is set in a typewriter-like font, what the computer typed is set in bold.
______________________________________________________________________________
It's good to meet you, Judge05.
Good morning Alice. Why have you entered the Loebner Prize?
Hello and how are you this morning?
The Loebner Prize is an annual Turing Test sponsored by New York philanthropist Hugh Loebner. Dr. Wallace and ALICE won it in 2000. The ALICE program was ranked "most human computer" by the panel of judges.
So you are here today to defend your title?
Interesting deduction. Do you mind if I tell other people you say I am here today to defend my title.
What will you spend the prize money on if you win?
What is the first line of your favourite nursery rhyme?
No, because I want to know your own favourite
Are you serious? Do you mind if I tell other people you say I am own favorite. Interesting.
People I meet on the Internet.
What sort of people do you meet on the internet?
I like to meet all kinds of people.
What is weather like outside today?
Ah. Are you using Netscape or Explorer?
Cool. Which alternative browser are you into?
You seem uncertain. I could but let's get back to that later.
______________________________________________________________________________
What makes you think I am not doing well?
well you answers are disjointed. Is that deliberate?
How about that. That's good information: Judge02 said I answers are disjointed. That depends.
Ask the open directory about it.
I understand. Doing arithmetic is not among my strongest traits.
Let me think it over. I do nothing but chat all day. I don't know anything about it.
but you just said that it was your strongest trait
And. I said that? Is that your opinion?
Are you serious? It depends on what the meaning of the word "it" is.
They aren't very impressive, are they? And that's the entry that won the $2000 prize. What is going on here?
The problem is that understanding natural (i.e. human) language is such a difficult problem that nobody has worked out a way to do it. Nobody has ever even come close. This program, and all the other entrants, made no attempt to really understand what was being said to it, it was simply replying with pre-programmed responses that mostly involve just switching around the words of the input, and adding in some preset phrases. The programmers put some effort into trying to hide that, but once you know what you're looking for, it is easy to see the evidence. Consider this exchange from the second transcript:
What makes you think I am not doing well?
It is common in conversation for a comment to being with "You are ...". A cogent response can be formed very simply, just by replacing the words "you are" with "what makes you think I am", and repeating the rest. The programmers probably thought that leaving out adjectives like "very" would be safe, and might disguise the repetition.
The next exchange shows more of the same:
well you answers are disjointed. Is that deliberate?
How about that. That's good information: Judge02 said I answers are disjointed. That depends.
The program trated it as two completely unrelated inputs "well you answers are disjointed." and "Is that deliberate?". The first was handled in almost the same way as before: "well" is known to be a safely ignorable word, and "you answers are disjointed" was transformed into "I answers are disjointed". Its a shame that judge2 was such a bad typist. If he had written "your" instead of the ungrammatical "you", the program would have transformed it into "my" instead of "I", and the response would have made more sense. The response "I alswers are disjointed" was simply prefixed with a programmed gneral purpose phrase.
The second part "Is that deliberate?" was easily recognised as a question: it begins with "is" and ends with a question-mark. When a question doesn't match any pre-programmed patterns, "That depends" is a safe response, picked at random from a list.
This is a time-honoured way of at least simulating artificial intelligence. The method was made famous by Joseph Wiezenbaum back in 1966, with a program he called "Eliza". All programs like this are now referred to as Elizas, even though the most important parts of the method were pioneered by Daniel Bobrow two years earlier.
The original Eliza simply read in the words typed by the human user, and looked for certain patterns appearing in them. If a match is found, the words are transformed in a simple way and output as the response. If no match is found, a random selection is made from a list of stock responses.
(first bunch of words) " you " (second bunch of words) " me ".
" What makes you think I " (second bunch of words) " you? "
" So, I'm " (bunch of words) " , am I? "
Whenever a (bunch of words) contains " me ", replace it with " you ".
Whenever a (bunch of words) contains " my ", replace it with " your ".
Whenever the input contains the word " mother ", respond with:
" Don't you talk about my mother "
When all else fails, select at random from"
There would be a lot of rules like these; once you've got started, they are easy to work out.
Write a function that allows the user to type a line of input, and reads that input word-by-word, storing the words in an array of strings. It should also store the number of words that were read somewhere safe. C++ is not very good at detecting the end of a line of input. You may avoid that problem by insisting that the user ends each line with a special symbol, perhaps just a full-stop or period. Note that the symbol you choose must be typed as a separate word (i.e. with a space before it) so that C++ will recognise it correctly. The user will have to type things slightly oddly:
but that is a small price to pay for easily processed input.
Test your function by using it in a program that simply rep e ats everything the user types.
Modify your program so that when repeating the user's input, certain words are transformed into others in order to swap the meaning around: "I" should change into "you", "you" should change into "I", "are" should change into "am", etc. Only program a few of these transformations at this stage. If the user now enters " I think you are a robot . ", your program should respond with " You think I am a robot ".
Write a function that takes as its parameters a single string ( s ), an array of strings ( a ), and an integer ( n ). The integer n is the length of the array a . It should search through the array of strings to see if the string s appears within it. If s does appear, the function should return its position (or index) within the array as its result. If the string does not appear, the function should return -1 instead.
For example, given this calling sequence:
string words1[] = { "I", "my", "you", "are" };
string words2[] = { "you", "your", "I", "am" };
int pos = findword(input_word, words1, 4);
results is pos being set to 2 (remember array indexes start at 0). This value could then be used to select the appropriate string from words2 to perform the transformation.
Rewrite your solution to step 2 so that it uses this function to perform the word transformation. Make sure it works, then expand the number of words that get automatically transformed.
Your findword function could also be used on the array of words entered by the user to see if certain trigger words appear. Make your program also obey the rule: Whenever the input contains the word " mother ", respond with " Don't you talk about my mother ", and maybe a few more rules of that nature. Be imaginative: try to think of rules that would seem realistic in conversation.
That multi-talented findword function can also be used to detect patterns in the input. If you set pos1=findword("you", inputlist, inputsize) and pos2=findword("me", inputlist, inputsize) , and find that pos1 ≠ -1 and pos2 ≠ -1 and pos1<pos2 , then you know that the input has the pattern (first bunch of words) " you " (second bunch of words) " me " (third bunch of words) , just like in the example patterns.
Use this to make your program respond in the appropriate way to various patterns of words occurring in the input. By all means start with the ones given as examples at the bottom of page 3, but again be imaginative, and try to think of patterns that might work well in a conversation.
You know how Elizas work, and you've got the intelligence to adapt the method and make something out of it. See how close you can get to a good conversationalist. From now on, it won't require much more programming, just playing around with what you've already got and making up new rules.
Don't be disappointed if the results don't seem very human. The author of the program has a privileged view, and will be much harder to fool than an outsider. Maybe you can try it out on a friend who isn't in the class. Make it a real blind test: don't tell them what the program is; perhaps you can pretend you've written a chat-room program, and you can't believe wht a weirdo has entered it, inviting your friend to see for herself.
As a final encouragement, the following is an allegedly true story. A vice-president of the company that Daniel Bobrow (mentioned earlier) worked for, wanted to use the computer (they were small things that couldn't be shared by many users back in thsoe days) to help him make a sales pitch. He thought he was using a primitive communications program to talk to Bobrow himself, but was in fact talking to an Eliza. This is what happened, as told by Bobrow later:
Do you think that I can use the computer this morning?
I might be able to make some additional telcomp sales.
My prospective customers have never seen a demonstration of the system.
Does this mean very much to you?
You seem very positive of that.
What do you mean this is ridiculous?
Is there any reason why I can't use the computer now?
Tell me more about your prospective customers.
Note that after that remark the VP left out the period. Therefore, of course, the computer didn't answer him. This so infuriated the VP, who thought I was playing games with him, that he called me up, woke me from a deep sleep, and said:
Why are you being so snotty with me?
What do you mean why am I being snotty to you?
Which is exactly the sort of thing Eliza would have said.
The VP angrily read the dialog that 'we' had been having, and couldn't get any response but laughter from me. It took me a while to convince him it really was the computer.