MathSource Reviews: A Mathematica Version of Eliza
Author
Matthew M. Thomas
Title
MathSource Reviews: A Mathematica Version of Eliza
Description
In this MathSource review, we examine a Mathematica version of Eliza, as adapted from a Prolog program and submitted to MathSource by Matthew Markert. Popularized thirty years ago within and beyond the Natural Language Processing (NLP) community by Joseph Weizenbaum [Weizenbaum 1966], Eliza is designed to emulate a Rogerian psychologist. Eliza asks you questions; you provide responses; Eliza continues the dialogue with you. Three decades ago, Eliza generated much attention: This program--twice the age of the IBM PC--gave the appearance of allowing human-computer interaction. In his 1966 paper, Weizenbaum even had to address this appearance: He made statements to further rob ELIZA of the aura of magic to which its application to psychological subject matter has to some extent contributed; he also noted that the ELIZA program itself is merely a translating processor in the technical programming sense [Weizenbaum 1966, p. 43].
Category
Academic Articles & Supplements
Keywords
URL
http://www.notebookarchive.org/2018-10-10punkn/
DOI
https://notebookarchive.org/2018-10-10punkn
Date Added
2018-10-02
Date Last Modified
2018-10-02
File Size
37.99 kilobytes
Supplements
Rights
Redistribution rights reserved
This notebook has not been updated since 2002. 
MathSource Reviews
A Mathematica version of Eliza
MathSource Reviews
A Mathematica version of Eliza
A Mathematica version of Eliza
In[1]:=
Edited by Matthew M. Thomas
In this MathSource review, we examine a Mathematica version of Eliza, as adapted from a Prolog program and submitted to MathSource by Matthew Markert. Popularized thirty years ago within and beyond the Natural Language Processing (NLP) community by Joseph Weizenbaum [Weizenbaum 1966], Eliza is designed to emulate a Rogerian psychologist. Eliza asks you questions; you provide responses; Eliza continues the dialogue with you. Three decades ago, Eliza generated much attention: This program--twice the age of the IBM PC--gave the appearance of allowing human-computer interaction. In his 1966 paper, Weizenbaum even had to address this appearance: He made statements to further rob ELIZA of the aura of magic to which its application to psychological subject matter has to some extent contributed; he also noted that the ELIZA program itself is merely a translating processor in the technical programming sense [Weizenbaum 1966, p. 43].This review offers a cursory examination of Natural Language Processing (NLP)--the discipline most concerned with Eliza. Markerts Eliza.m is then specifically examined, as are two otherversions of Eliza found on the World-Wide Web. Anannotated session with the Mathematica Eliza version is then presented, with results from the other versions contributing to the annotation. That session and this review are then summarized.
Background
Background
Natural Language Processing (NLP) is the discipline into which programs such as Eliza best fit. NLP has been defined as both the ability of a computer to process the same language used by humans in normal discourse, and the field of study within cognitive science dealing with linguistic behavior [Obermeier 1989, p. 17]. A hybrid discipline that calls on both artificial intelligence and linguistics, NLP currently has applications in spelling- and grammar-checkers, and in selected machine translation applications. There is much potential for applying NLP to text database management; however, that potential has yet to be realized. At the end of the 1980s, it was reported that thousands of NLP programs were at the prototype stage, and hundreds of off-the-shelf NLP programs (the aforementioned spell-checkers et al) were available [Obermeier 1989, p. 12]. NLP has evolved from the 1950s through the 1980s. In 1950, machine translation was the primary NLP system application and garnered the most interest (and financial support). Later in the 1950s, however, machine translation researchers split into two groups. The first group pursued computational linguistics; the other worked with new linguistic theories. In the 1960s, incipient work in artificial intelligence promised new advances in NLP, and system applications shifted from machine translation to domain modeling. The hope of that decade was that NLP could be the proof for many cognitive issues. Weizenbaums Eliza program constrained those hopes, for while Eliza created the illusion of machine intelligence, it in fact could respond only to preprogrammed patterns. NLP evolution continued through the 1970s, with natural language interfaces supplanting domain modeling among system applications. Terry Winograds SHRDLU program revealed the potential NLP held, but did not address fundamental NLP problems. NLP also received consideration for knowledge-based problem solving in the 1970s. In the 1980s, NLP technology began to achieve its first commercial successes. As of the late 1980s, natural language front-ends for text databases were expected to develop in the 1990s. Chapter 12 of Obermeiers work [Obermeier 1989] offers more details of this evolution.
Note the role of Eliza in the NLP evolution. It was not an overly positive role Eliza played on NLPs behalf in the 1960s. Weizenbaum [Weizenbaum 1966] even devoted significant portions of his paper to downplaying hype that had grown around purported Eliza capabilities. Weizenbaum reported that the Eliza program had to handle five problems: 1) trigger word identification; 2) minimal content discovery; 3) appropriate substitution choice upon trigger word identification; 4) response generation in the absence of trigger words; 5) editing capability for covering input phrases to output. The central function of Eliza is basically text manipulation: The input data string is decomposed prior to trigger identification, and is reassembled as output based upon test results. What Eliza does has been described by Weizenbaum (and others in the NLP literature) as template application. Interested readers are referred especially to Figure 2 [Weizenbaum 1966, p. 39] and the discussion section [Weizenbaum 1966, pp. 42-43] of Weizenbaums paper. The latter offers an insightful assessment of human interaction with the Eliza program. Chapter 2 of Tennants 1981 work [Tennant 1981, pp. 19-48] examines early natural language programs. In addition to Eliza, these programs include BASEBALL (answered questions on game information for all American League baseball games in one year), SAD-SAM (created tree structure representations of kinship relations), SYNTHEX (designed to retrieve facts from an English text database), STUDENT (solved algebra story problems), and DEACON (rewrote phrases derived from an English sentence). The session with Eliza provides a detailed illustration of how various inputs contain trigger words and phrases that lead to specific outputs. The interested reader might compare that session to the forthcoming session in this review. Since Elizas debut thirty years ago, improvements to the program such as recursive transition networks [Gazdar and Mellish 1989, pp. 64-68] have been offered. Yet it is the traditional program that is most often emulated. It is this program on which Markerts Eliza.m for Mathematica is based, and on which at least two Web-based programs are based. Three Eliza versions are outlined in forthcoming sections of this review.
Examining Eliza.m
Examining Eliza.m
The code for Matthew Markerts Mathematica version of Eliza is MathSource item pub/Applications/Other/0204-635-0011, entitled Eliza.m. Submitted to MathSource in October 1992, it occupies only 3 kB memory and can be printed in full on only two 8.5 x 11 pages. It was submitted to MathSource in October 1992. Documentation for this code is sparse. Introductory comments cite Weizenbaums original Eliza code [Weizenbaum 1966], and admit that this program was translated from a Prolog version. The user is advised to feed only one sentence at a time to this Eliza version. Upon loading Eliza.m, the user must type Eliza and press the enter key to activate Eliza; typing goodbye (and hitting Enter) closes Eliza and returns control to its operating system, Mathematica. The user is also advised that a Mathematica notebook front end is not recommended for running Eliza.m: Some front ends have caused an extra output prompt for every response. Markerts Mathematica version of Eliza comprises three major routines. The first, BreakIntoWords[], has as its purpose the parsing of a sentence into a list of words. The second, StringClip[], offers an ad hoc means of finding a word sequence within an English sentence--the adjoining comment states that StringClip[] is not good code. It is the final routine, ElizaRead[], that takes control of the Mathematica session, processes user input, makes extensive use of BreakIntoWords[] and StringClip[], and (as Henry Higgins did for Eliza Doolittle) puts words in Elizas mouth. The Eliza.m code performs, as expected, a great deal of string processing. To that end, Mathematica primitives StringDrop[], StringLength[], StringPortion[], StringReplace[], and StringTake[] get frequent use, as do case-changing primitives ToLowerCase[] and ToUpperCase[]. Use is made of list-processing primitives Map[] and Flatten[]; Union[] is used for concocting output prose. The MemberQ[] primitive is at the core of much testing, and Random[] is of use when Eliza would otherwise have little to say. To see what output Eliza.m will produce given specific input, one need only glance at the Which[]-driven code ElizaRead[] comprises. Phrases in quotes such as Tell me your problem abound; clearly, these phrases will appear as code output. A slightly more careful ElizaRead[] reading reveals the type of inputs that evoke or trigger specific outputs. For example, including always in the input triggers Can you think of a specific example? as output. Similar trigger words are: mother, father, sister, brother, parents (Tell me more about your family.); depressed (I am sorry to hear that.); computer(s) (Are you afraid of computers?); yes (You sound very positive.); no (You sound very negative.). The last two are triggers if they appear as the first word in the input. In the aforementioned examples, one trigger word evoked an intact response phrase. A no-word input (i.e., a space) evokes Im sorry. I didnt catch what you just said. while one-word inputs other than yes and no evoke You are not very talkative. In addition, questions (inputs ending in a question mark) evoke a question (Why do you ask that?). There are also trigger phrases that bring about substitutions. To wit, my ... in the input evokes a your ... output; likewise, I am not ... in the input evokes a Do you think coming here will help you to be ... output. Two other cases: I need ... in the input evokes a What would it mean to you if you got ... output; You are ... in the input evokes a What makes you think I am ... output. If trigger phrases I am not ... and I need ... are part of inputs ending in periods, the outputs end in both a period and a question mark [see the sixth and eleventh outputs in the forthcoming Eliza.m example]. Conversely, if the you are ... trigger phrase does not have an input ending in a period, the last letter of the last word does not appear in the output. As such, a You are an expert on fire evokes What makes you think I am an expert on fir? as the output. What destroys the tree is of interest, irrespective of tree type. Many inputs may contain none of these trigger words or trigger phrases. Profanity-laced phrases can be examples of such inputs, and while some versions of Eliza explicitly address profanity [Tennant 1981, p. 42], Eliza.m does not. Nonetheless, when trigger words and phrases are absent from an input, Eliza.m has a standard set of outputs for use in that situation. These outputs are: In what way? I do not follow you. I am not sure I understand. Tell me more. Go on. I see. and appear in random order. These outputs are useful in sustaining the illusion of conversation, even though they have no specific link to the corresponding input. What if conflicting trigger words or phrases are present in the same input? Eliza.m appears to have no specific means of conflict resolution at work. Often, the output in the case of conflict is a function of the previous input/output pair. As the forthcoming examples show, an I am not depressed. input on the heels of an I am depressed. input evokes an output based on the depressed trigger word (triggered by the previous input), not on the I am not ... trigger phrase. See also how the identical thirteenth and fifteenth inputs produce an output triggered by your ... in one case, and an output triggered by father in the other. In other cases, trigger-word order in the input determines the output: I will always be the son of my father. evokes output triggered by always, not by father. A good Eliza version is supposed to emulate a Rogerian psychologist. Previous works [Weizenbaum 1966, Ten81] offer standard examples of the inputs Eliza is best able to accept. The following section identifies two Web-based versions of Eliza, whose output shall provide a basis for comparison with the Mathematica version. Input for the forthcoming example Eliza session is derived from the Eliza.m code. It serves to illustrate effects of the aforementioned trigger words, trigger phrases, and conflicting triggers within one input. This forthcoming example session is presented not only for your edification, but also for your amusement.
Web-based Versions of Eliza
Web-based Versions of Eliza
The documentation for the Mathematica Eliza version notes that the code has been translated from a Prolog version of Eliza. Invariably, the Prolog version had to have come from the appendix to Weizenbaums paper [Weizenbaum 1966]--either directly or indirectly. In assessing the Mathematica Eliza version, what other Eliza version might one use as a basis for comparison? Is it necessary to re-work Weizenbaums 30-year old code to run under a modern operating system? Or are there ready-made alternatives that prove viable for comparative purposes. Disinclined toward writing and debugging an Eliza program from Weizenbaums paper, I sought ready-made Eliza versions on the World-Wide Web. As of late April 1996, there were at least two such versions on the Web: One from the Balkans; one from Bell Labs. The beauty of these two programs is that one can run them through his or her Web browser, without having to download them. What one asks of the Mathematica Eliza version can concurrently be asked of the Web versions. Eliza from the Balkans could be found at URL www-ai.ijs.si/eliza/eliza.html. This Eliza version is brought to you by the AI Lab of the Institut Jozef Stefan, located in Ljubljana, Slovenia. Accordingly, I henceforth refer to it as the Slovene Eliza version. This Web page greets you with ELIZA--a friend you could never have before (a cumbersome greeting, but one gets the point). Under that headline is Elizas greeting: Hello. I am Eliza. How can I help you? After you type your response, the Slovene Eliza does not place its response after yours; instead, it refreshes the page. No history of your dialogue with the Slovene Eliza is offered. As will be seen in the following section, it appears that this Eliza version was adapted from a Prolog predecessor: Prolog-remnant bracket pairs appear in this versions output. Eliza from Bell Labs could be found at URL www.monmouth.com/~chayden/eliza/Eliza.html. It is the creation of Charles Hayden, who toils at Lucent Technologies (n=E9 Bell Labs). It is a Java applet, and as such requires version 2.0 or higher of Netscape (or the equivalent among other Web browsers). Author Hayden makes all of his Java code for Eliza available. He notes in the documentation that he wrote this Eliza version to help himself learn Java ... much as he had written an Eliza version in 1983 to teach himself the Macintosh operating system. Haydens Eliza version does offer a dialogue history. Haydens work exemplifies the utility of not only the Web but also MathSource: An individual, in teaching himself or herself something, creates and shares a work that (though just a means to an end) is of value and use to others. Matthew Markert may have been learning Prolog, Mathematica, or both when he created the subject of this review; his means to an end, however, now benefits the Mathematica community through MathSource. The forthcoming example session with Eliza.m is annotated, using complementary outputs from the Slovene Eliza and from Haydens Eliza where appropriate.
Example Session with Eliza.m
Example Session with Eliza.m
Let us run the Mathematica version of Eliza. The following is an annotated session with this version. To have a convenient basis for comparison, I submitted the same inputs to the Web-based versions that went to the Mathematica version; outputs from the former versions are compared and contrasted, where appropriate, to what came forth from Mathematica. Since using a Mathematica notebook front end is advised against in Matthew Markerts documentation, Eliza was run using a UNIX version of Mathematica. We begin by loading Eliza.m:
In[1]:=
<<Eliza.m
As instructed by the documentation, we type Eliza. Doing so activates the program:
In[2]:=
Eliza
Just as the Outer Limits television show took control of our TV sets on a weekly basis in the 1960s, so it is that Eliza has taken control of our Mathematica session. We are no longer dealing with a system for doing mathematics by computer, but a would-be Rogerian psychologist emulator. We resist the temptation to submit to Eliza the input Integrate[1/x, {x, 0, 1}]; instead, we feign sadness:
In[3]:=
I am depressed.
We then feign schizophrenia:
In[4]:=
I am not depressed.
The Slovene Eliza provided identical responses--Do you think coming here will help you not to be depressed?--to both inputs; Haydens Eliza, however, greeted our depression with sorrow and our lack of depression with the Slovene Elizas question. Having feigned sadness and schizophrenia, let us now express irritation at getting identical responses to diametrically opposite inputs:
In[5]:=
You are one sorry program.
We trigger the you are ... --> what makes you think I am ... substitution (a standard substitution among Eliza versions). We then pose a variation upon our fourth input:
In[6]:=
I am not depression-prone.
While the term depressed (negated or not) triggers the single response seen above, depression-prone has no such effect. Triggered in this case is an I am not ... --> do you think coming here will help you to be ... substitution. In the Slovene Eliza, not I am not ... but I am ... is the trigger phrase; Haydens Eliza asks Is it because you are not depression prone that you came to me? (perhaps the most Rogerian response of the three). Only the Mathematica Eliza seemed to have the period followed by the question mark in the sixth output. Let us now supply consecutive inputs, with No beginning the first and its antonym beginning the second:
In[7]:=
No, I cannot complain about anything.
In[8]:=
Yes, I am if you say I am.
For all three Eliza versions, yes and no are trigger words when beginning an input. The former, to Eliza, is always a sign of certainty and assurance; the latter, an indicator of negativity. We next utter an expression brought about by those fickle responses:
In[9]:=
Ugh.
This utterance triggers the terse input response by all Eliza versions. When the utterance is Yes. or No., however, Eliza must employ some measure of conflict resolution to determine whether the yes/no trigger or the terse input trigger takes precedence (generally, the former does). Inspired by an advertising campaign slogan for a certain beer brand, we take our dialogue with Eliza on a philosophical bent:
In[10]:=
Why ask why?
Questions evoke interrogative responses from Eliza. We then voice a tautology:
In[11]:=
I need what I need.
In contrast to the output youve just read, Haydens Eliza retorts What would ... if you got what YOU need? [emphasis mine]. There are two problems with the Mathematica Eliza response: 1) It ends with both a period and a question mark (see also the sixth output), and 2) its last pronoun should be you, not I. The substitution is incomplete. Nonetheless, both the Hayden and Mathematica version responses are superior to that from the Slovene Eliza: Why do you want []? The bracket pair is part of the actual response, perhaps a remnant of Prolog code from which the Slovene Eliza may have been translated. Let us now bring to bear discussion of our family:
In[12]:=
I will always be the son of my father.
In the Mathematica Eliza version, the always trigger took precedence over the father trigger; any use of always elicits a request for a specific example. Such is not the case with Haydens Eliza: Tell me more about your family is its response. The father trigger is also dominant in the Slovene Eliza, but again, those pesky brackets linger: Who else in your family []? We next present another truism to Eliza:
In[13]:=
My father fathered me.
Here, the father trigger dominates. Such is not always the case, though: On other occasions, the my ... --> your ... substitution is triggered (see below). =46rom both Web-based Eliza versions, the response was the same: Who else in your family fathered you? This response should remove any doubt among healthy people that Eliza is but an early NLP program, while driving those truly in need of Rogerian therapy off a cliff. Since Eliza is after all a computer program, it is only appropriate that it generate a response triggered by computer(s):
In[14]:=
My computer is not a cause of fear.
The Web-based Eliza versions asked similar questions. We close by again telling Eliza how we came to be: This time, the my ... --> your ... substitution is triggered ... bringing about yet another humorous response:
In[15]:=
My father fathered me.
In[16]:=
I have a sibling?
Weizenbaums paper alludes to the Eliza Doolittle character from Pygmalion. One wonders what George Bernard Shaw would have thought of the dialogue just presented.
Summary
Summary
Matthew Markerts Eliza.m code is basically an acceptable version of Weizenbaum's Eliza program. There are some technical flaws in the code, as 1) some outputs are ended with both a period and a question mark, 2) inputs ended without a punctuation mark can have the last letter of their last word truncated, and 3) some substitutions [the eleventh output above, for example] are incomplete. Otherwise, Eliza.m differs not much from the other versions. It is hard to imagine this program fooling anyone in interactive mode for long. Nonetheless, such programs do have their applications, such as in responding to irrelevant email [Gazdar and Mellish 1989, p. 64]. In a way, Eliza.m embodies the best of MathSource. Mathematica programs need not be flawless to find a home in MathSource: Flawlessness is the ideal, but must by no means be the criterion for admission. The programs need not themselves be an end; they can be a means to another end. It is likely that Eliza.m was the means to this end: The ability to translate Prolog code into its Mathematica counterpart. That Eliza.m was a means to an end does not mean that Eliza.m is without usefulness. In the least, Eliza.m provides a template for those who would write a fully functional, thoroughly debugged Eliza package in Mathematica. Caveat emptor is always in order, especially in regard to free packages from MathSource. These packages, however, can be worth much more than their price.
REFERENCES
REFERENCES
Gazdar, G. and Mellish, C. Natural Language Processing in PROLOG, Addison-Wesley Publishing Co., Wokingham, England (1989).
Obermeier, K. K. Natural Language Processing Technology in Artificial Intelligence: The Science and Industry Perspective, Ellis Horwood Ltd., Chichester (1989).
Tennant, H. Natural Language Processing, Petrocelli Books Inc., New York (1981).
Weizenbaum, J. ELIZA--A Computer Program for the Study of Natural Language Communication Between Man and Machine, Communications of the ACM, 9(1), 36-45 (1966).
Obermeier, K. K. Natural Language Processing Technology in Artificial Intelligence: The Science and Industry Perspective, Ellis Horwood Ltd., Chichester (1989).
Tennant, H. Natural Language Processing, Petrocelli Books Inc., New York (1981).
Weizenbaum, J. ELIZA--A Computer Program for the Study of Natural Language Communication Between Man and Machine, Communications of the ACM, 9(1), 36-45 (1966).
ABOUT THE EDITOR
ABOUT THE EDITOR
Matthew M. Thomas is a chemical engineering doctoral candidate at Washington University in St. Louis. The emphasis of his research is on control of batch chemical processes in general, and on autoclave curing of fiberglass/epoxy composite laminate materials in particular.Matthew M. ThomasDepartment of Chemical EngineeringWashington University of St. LouisSt. Louis, MO 63130-4899thomas@wuche2.wustl.eduELECTRONIC SUBSCRIPTIONSIncluded in the distribution for each electronic subscription is the file Eliza.m containing Mathematica code for the material described in this article.
Cite this as: Matthew M. Thomas, "MathSource Reviews: A Mathematica Version of Eliza" from the Notebook Archive (2002), https://notebookarchive.org/2018-10-10punkn
Download
