(Updated: 2007/03/26)
ELIZA: Everything You've Always Wanted a Therapist to Be
Last updated by: Henry Chow (henry_ckh at yahoo dot ca)
Comments to: Steve Wolfman (wolf at cs dot ubc dot ca)
Sources and contributions: This lab is derived from prior (Java) versions created by Kathy Lo. Subsequent revisions were made by Michael Chiang. Source code ported from Java to JavaScript by Steve Wolfman.
Contents
Wouldn't it be great if computers could understand what we say? What about the ability to have an actual conversation with a computer? What if a computer could take the place of a psychologist, saving patients hundreds of dollars in fees? Can computers be taught to think? In this lab you will observe the behavior of a working model of ELIZA and build your own version as well.
Read through the lab, and any class notes related to the lab. You should have experience using a text editor, such as Notepad or Crimson Editor, and a web browser, such as Firefox or Internet Explorer.
ELIZA was invented in the early 1960s at MIT by Joseph Weizenbaum. The name "Eliza" comes from the play Pygmalion, in which a woman named Eliza Doolittle was taught to act and speak like an aristocrat without truly understanding what she was saying. ELIZA attempts to emulate a Rogerian psychologist by taking a patient's answers and reformulating them as questions. When it was first released, many people confided their deepest secrets to this computer program, believing it to be human, and some psychologists believed that ELIZA could be used in place of a real psychologist! Surprisingly enough, the technology behind ELIZA was not very advanced, as you will see!
ELIZA is a classic example of natural language processing (NLP). This field of computing science / psychology / linguistics studies how computers can be taught to understand natural language (such as English) through text or speech, or even how to translate a text into another language. There are many versions of ELIZA out there, some more "intelligent" than others, but they all rely on one principle: pattern matching.
But what is a pattern? A pattern is a specification of what should appear and in what order. For example, <letter><number><number><letter> is a pattern. Strings that match this pattern include strings like "c67r" and "p98t". Strings that don't match this pattern are strings like "he39" and "699s". In ELIZA, a pattern might look like <anything><" mother "><anything>. Strings that match this pattern include strings like "I talked to my mother today" and "My mother bought me a pair of shoes", but not "I find him very mothering". Why? Note the space before and after the word "mother" in the pattern.
In this lab you will be able to observe this pattern matching in action, as well as write some patterns of your own.
http://www.chayden.net/eliza/Eliza.html
Respond to Eliza and continue the conversation for a few question / answer exchanges. What do you notice?
Question: Does Eliza seem intelligent to
you? If so, what aspect of your conversation convinced you so? If not, what
could she do better to appear more intelligent?
For example, try to visualize the following associated keywords and phrases:
Keyword Phrase
“mother” “Tell me more about your family.”
“classes” “It appears you have some issues with school.”
Now, assume that the user responds to Eliza with the statement “My mother drives me crazy!”. Eliza will search the keywords of the dictionary, and recognize the word “mother” as a keyword that the table contains. As a result, Eliza will respond with the phrase associated with this keyword, which is “Tell me more about your family.”.
(You will notice that if Eliza is unable to find a word in the dictionary’s list of keywords, it will respond with a randomly chosen general phrase, such as “Please elaborate on that a little more." or "Please, do go on.")
Try adding at least five more pairs of keywords and associated responses to the dictionary:
To test your modified version of Eliza, enter any sentence containing the word "mother" into the text field and see what Eliza replies. (In fact, the "mother" on its own will do the same thing.) Do the same for "classes". Note how the this.qa = {...} statements in the code relate to this behaviour.
NOTE: The double quotes are used by the programmer indicate to JavaScript that the text enclosed within are to be taken verbatim, and not to be executed to perform some function, with the exception of special characters such as '\n' which generates a return character.
Question: If in a sentence the keywords "mother" and "classes" both occur, Eliza will try to match the one that occurs first. Is this ideal? If not, how should Eliza handle this case? (Hint: think of an example of such a sentence such that Eliza's canned output makes no sense).
Rather than search for a keyword and respond with the corresponding phrase, this time Eliza searches through a list of phrases, not words, which we will refer to as patterns. If the pattern is found in the dictionary, Eliza responds with the corresponding phrase. We will refer to these pairs of phrases as pattern-response pairs. Visualizing this table (as in Part II step 7), our Keyword is now a pattern, and the Phrase is now called the Response.
Pattern
Response
“I hate
*KEYWORD*”
“Why do you hate *KEYWORD*?”
So, when a user tells Eliza “I hate you”, Eliza
looks up and finds the phrase “I hate *KEYWORD*” in the dictionary, and
recognizes that the corresponding response is “Why do you hate
*KEYWORD*?”. Because the user has typed “you” as the *KEYWORD* in the
pattern, Eliza refers to first dictionary of keyword pairs, and recognizes that
the keyword associated with “you” is “me”, and therefore uses “me” in place of
the *KEYWORD* in the Response. Thus, Eliza responds to “I hate you” with
“Why do you hate me?”.
Add at least five more patterns that Eliza should watch out for. The patterns (that is, the left side of the pattern-response pair) must abide by the following rules.
An example of an acceptable
pattern would be this.startPhrases = {"this part has to be in lowercase
with a space around *KEYWORD* ", "This part cAn bE wRiTten HOWEVER
you want"};
Question: Explain the role of "*KEYWORD*" in the JavaScript code.
Show your TA:
Marking scheme: For Part II: modified greeting as in step 6 (1 mark), three new phrases as in step 7 (1.5 marks), five keyword-response phrases as in step 7 (2 marks). For Part III: five additional new keywords as in step 3 (2 marks), and 5 pattern-response phrases as in step 4 (2 marks). Questions from parts I, II and III (0.5 marks each).
(Note: This lab is due on Monday, June 11 at 7:00pm. You will only have Wednesday(June 6) and Friday(June 8) lab sessions to work on this lab.)
Reference Links
Check out http://en.wikipedia.org/wiki/Eliza for more information on Eliza and http://en.wikipedia.org/wiki/Loebner_prize for pointers to related, somewhat more advanced efforts. Joseph Weizenbaum's research paper on Eliza , published in 1966, describes how his invention worked!