Page 1 of 1

ELIZA - The program that created the AI field

Posted: Mon Oct 24, 2016 5:39 pm
by GeorgeMcGinn
ELIZA is one of the orginal and early attempts at creating Artificial Intelligence (AI) and is a major part of computer science history.

I remember having the source code of this program back in the early 1970's when I was studying computer science. What made this program a popular one was people back then really thought that the computer was carrying on a conversation with them.

Long ago I expanded this program, and the Pearl River High School's math department printed my changes to this code, which is still a major part of gaming today. I know my copy became other versions. Today, I no longer have a copy of my program.

I was given a copy that ran on an early IBM PC, and found traced it back though research that this copy was converted from an adaptation of the code published in 1977 in the "Creative Computing" magazine. And during my research I was also able to find a copy of this code.

However, Weizenbaum said that this was not possible because the computer doesn't learn from your responses and cannot comprehend the environment it is in.
Directly from Wikipedia:
"ELIZA was created between 1964 to 1966 at the MIT Artificial Intelligence Laboratory by Joseph Weizenbaum. Created to demonstrate the superficiality of communication between man and machine, Eliza simulated conversation by using a 'pattern matching' and substitution methodology that gave users an illusion of understanding on the part of the program, but had no built in framework for contextualizing events."

"Weizenbaum's original MAD-SLIP implementation was re-written in Lisp by Bernie Cosell. A BASIC version appeared in Creative Computing in 1977 (although it was written in 1973 by Jeff Shrager)."
Even IBM's Watson® computer isn't really capable of contexualizing what it is learning based on the environment it is in. What I mean is that it doesn't know whether the information it learned was from a war zone or sitting in a lab reading journal entries.

While the context of the information maybe missing (to realize context is to have consciousness), Watson® is a great improvement in that its programmers have given it the ability to learn from previous knowledge, based on the limits imposed on its coding. Regardless, Watson® is still a computer that runs a program written by man, and will have bugs.

Briefly, the code below is converted directly from the IBM PC source code. The only changes I had to make was changing the multiple statements per line separator (from a ":" to "!") and I removed all the line numbers except for the ones used in GOTO statements. Otherwise, the code was very compatible to SmartBASIC.

Also, there is an App in the iTunes store called ELIZA, which I downloaded after I completed my changes below. And I tested my replies to the version in the App, and it gets the same reponses. That means it has the same bugs and limitations that this code has.

Another change was I decided (before I even checked for an App) was to give ELIZA a voice. So you not only can read the question, she speaks it with a Russian accent (I could not find a male, German, scary voice!). The App also uses a voice to speak the questions.

If you have a problem due to scrolling on the device, you can do a CLEAR TEXT before the program asks a question. The App does that. The App also keeps the input at the top of the screen (is it sounding like it was written in SmartBASIC). Well, if it was, the author, who offers it for FREE, has not said so in its iTunes' description.

Enjoy this program, as this is part of computer history. It spawned interest in a small, new field called Artificial Intelligence, and this code has, to this day, made a major impact on gaming, and in business automating help centers and the phone systems at banks and other businesses that determine where to route your call.

There is still much to learn and many other fields where this code and similar programs can have a major impact. It just requires imagination.

George McGinn
Computer Scientist
Cosmology and Space Research Institute
Core System Strategies


Code: Select all

/* Program: ELIZA v1.0
The version of the SmartBASIC's ELIZA program is based on the adaptation of the "Creative Computing" magazine article. In 1977 where it listed the first conversion to BASIC. Patricia Danielson and Paul Hashfield's adaptated the magazine's code to the dialect of BASIC language that ran on an IBM PC.

This copy has been converted from the IBM PC dialect of BASIC to SmartBASIC. Since this program is is from a 1980's BASiC dialect, it originally had line numbers, which I have removed except for the GOTO's. I left them in and removed the rest of the line numbers.

I also added to this version the speaking of each question. It has a female voice with a Russian accent.

*/


TEXT CLEAR
PRINT TAB(6);"**********************************************************"
PRINT
PRINT TAB(6);"WELCOME TO ELIZA"
PRINT TAB(10);"CREATIVE COMPUTING"
PRINT TAB(10);"MORRISTOWN, NEW JERSEY"
PRINT
PRINT TAB(10);"ADAPTED FOR IBM PC BY:"
PRINT TAB(14);"PATRICIA DANIELSON AND PAUL HASHFIELD"
PRINT
PRINT tab(10);"ADAPTED FOR MAC IOS AND SMARTBASIC BY:"
PRINT TAB(14);"CONVERTED BY GEORGE MCGINN, VENICE, FL (10/22/2016)"
PRINT
PRINT TAB(6);"PLEASE DON'T USE COMMAS OR PERIODS IN YOUR INPUTS"
PRINT TAB(6);"BE SURE THAT THE CAPS LOCK IS ON"
PRINT
PRINT TAB(6);"**********************************************************"
PRINTLINE(3)


REM ****************************
REM*****INITIALIZATION**********
REM ****************************
OPTION BASE 1
DIM S(36),R(36),N(36)
DIM KEYWORD$(36),WORDIN$(7),WORDOUT$(7),REPLIES$(112)
N1=36!N2=14!N3=112
FOR X = 1 TO N1
    READ KEYWORD$(X)
NEXT X
FOR X = 1 TO N2/2!READ WORDIN$(X)!READ WORDOUT$(X)!NEXT X
FOR X = 1 TO N3!READ REPLIES$(X)!NEXT X
FOR X=1 TO N1
    READ S(X),L
    R(X)=S(X)
    N(X)=S(X)+L-1
NEXT X
SAY VOICE "ru-RU"
SAY PITCH 1
PRINT "HI! I'M ELIZA. WHAT'S YOUR PROBLEM?"
SAY TEXT "HI! I'M ELIZA. WHAT'S YOUR PROBLEM?"

170 REM ***********************************
    REM *******USER INPUT SECTION**********
    REM ***********************************
    INPUT I$
    I$=CAPSTR$(I$)         ' The original code required input in all CAPs. This takes care of that.
    I$="  "&I$&"  "
    REM GET RID OF APOSTROPHES
    FOR L=1 TO LEN(I$)
        TempLen=LEN(I$)
        Temp$=MID$(I$,L,4)
        IF L+4>LEN(I$)THEN 250
        IF MID$(I$,L,4) <> "SHUT" THEN 250
        PRINT "O.K. IF YOU FEEL THAT WAY I'LL SHUT UP...."
        SAY TEXT "O.K. IF YOU FEEL THAT WAY I'LL SHUT UP...."
        PAUSE 5
        END
250 NEXT L
    IF I$=P$ THEN 
       PRINT "PLEASE DON'T REPEAT YOURSELF!"
       SAY TEXT "PLEASE DON'T REPEAT YOURSELF!"
       GOTO 170
    ENDIF
     

300 REM ***********************************
    REM ********FIND KEYWORD IN I$*********
    REM ***********************************
    FOR K=1 TO N1
        FOR L=1 TO LEN(I$)-LEN (KEYWORD$(K))+1
            IF MID$(I$,L,LEN(KEYWORD$(K)))<>KEYWORD$(K) THEN 350
            IF K <> 13 THEN 349
            IF MID$(I$,L,LEN(KEYWORD$(29)))=KEYWORD$(29) THEN 
               K = 29
349            F$ = KEYWORD$(K)
               GOTO 430
            ENDIF   
350     NEXT L
    NEXT K
    K=36!GOTO 570                                      ' WE DIDN'T FIND ANY KEYWORDS


430 REM ******************************************
    REM **TAKE PART OF STRING AND CONJUGATE IT****
    REM **USING THE LIST OF STRINGS TO BE SWAPPED*
    REM ******************************************
    C$=" "&RIGHT$(I$,LEN(I$)-LEN(F$)-L+1)&" "
    FOR X=1 TO N2/2
        FOR L=1 TO LEN(C$)
            IF L+LEN(WORDIN$(X))>LEN(C$) THEN 510
            IF MID$(C$,L,LEN(WORDIN$(X)))<>WORDIN$(X) THEN 510
            C$=LEFT$(C$,L-1)&WORDOUT$(X)&RIGHT$(C$,LEN(C$)-L-LEN(WORDIN$(X))+1)
            L=L+LEN(WORDOUT$(X))
            GOTO 540
510         IF L+LEN(WORDOUT$(X))>LEN(C$)THEN 540
            IF MID$(C$,L,LEN(WORDOUT$(X)))<>WORDOUT$(X) THEN 540
            C$=LEFT$(C$,L-1)&WORDIN$(X)&RIGHT$(C$,LEN(C$)-L-LEN(WORDOUT$(X))+1)
            L=L+LEN(WORDIN$(X))
540      NEXT L
    NEXT X
    IF MID$(C$,2,1)=" " THEN C$=RIGHT$(C$,LEN(C$)-1)              ' ONLY 1 SPACE
    FOR L=1 TO LEN(C$)
557     IF MID$(C$,L,1)="!" THEN 
           C$=LEFT$(C$,L-1)&RIGHT$(C$,LEN(C$)-L)
           GOTO 557
        ENDIF   
    NEXT L


570 REM **********************************************
    REM **NOW USING THE KEYWORD NUMBER (K) GET REPLY**
    REM **********************************************
    F$ = REPLIES$(R(K))
    R(K)=R(K)+1!IF R(K)>N(K) THEN R(K)=S(K)
    IF RIGHT$(F$,1)<>"*" THEN 
       PRINT F$
       SAY TEXT F$
       P$=I$
       GOTO 170
    ENDIF   
    IF C$<>"   " THEN 630
    PRINT "YOU WILL HAVE TO ELABORATE MORE FOR ME TO HELP YOU"
    SAY TEXT "YOU WILL HAVE TO ELABORATE MORE FOR ME TO HELP YOU"
    GOTO 170
630 TEXT$=LEFT$(F$,LEN(F$)-1)&C$
    PRINT TEXT$
    SAY TEXT TEXT$
    P$=I$!GOTO 170

REM *******************************
REM *****PROGRAM DATA FOLLOWS******
REM *******************************

REM *******************************
REM *********KEYWORDS**************
REM *******************************
DATA "CAN YOU ","CAN I ","YOU ARE ","YOU'RE ","I DON'T ","I FEEL "
DATA "WHY DON'T YOU ","WHY CAN'T I ","ARE YOU ","I CAN'T ","I AM ","I'M "
DATA "YOU ","I WANT ","WHAT ","HOW ","WHO ","WHERE ","WHEN ","WHY "
DATA "NAME ","CAUSE ","SORRY ","DREAM ","HELLO ","HI ","MAYBE "
DATA "NO","YOUR ","ALWAYS ","THINK ","ALIKE ","YES ","FRIEND "
DATA "COMPUTER", "NOKEYFOUND"

REM *********************************
REM ***STRING DATA FOR CONJUGATIONS**
REM *********************************
DATA " ARE "," AM "," WERE "," WAS "," YOU "," I "," YOUR"," MY "
DATA " I'VE "," YOU'VE "," I'M "," YOU'RE "
DATA " ME "," YOU "

REM ******************************
REM *********REPLIES**************
REM ******************************
DATA "DON'T YOU BELIEVE THAT I CAN*"
DATA "PERHAPS YOU WOULD LIKE TO BE LIKE ME*"
DATA "YOU WANT ME TO BE ABLE TO*"
DATA "PERHAPS YOU DON'T WANT TO*"
DATA "DO YOU WANT TO BE ABLE TO*"
DATA "WHAT MAKES YOU THINK I AM*"
DATA "DOES IT PLEASE YOU TO BELIEVE I AM*"
DATA "PERHAPS YOU WOULD LIKE TO BE*"
DATA "DO YOU SOMETIMES WISH YOU WERE*"
DATA "DON'T YOU REALLY*"
DATA "WHY DON'T YOU*"
DATA "DO YOU WISH TO BE ABLE TO*"
DATA "DOES THAT TROUBLE YOU*"
DATA "DO YOU OFTEN FEEL*"
DATA "DO YOU OFTEN FEEL*"
DATA "DO YOU ENJOY FEELING*"
DATA "DO YOU REALLY BELIEVE I DON'T*"
DATA "PERHAPS IN GOOD TIME I WILL*"
DATA "DO YOU WANT ME TO*"
DATA "DO YOU THINK YOU SHOULD BE ABLE TO*"
DATA "WHY CAN'T YOU*"
DATA "WHY ARE YOU INTERESTED IN WHETHER OR NOT I AM*"
DATA "WOULD YOU PREFER IF I WERE NOT*"
DATA "PERHAPS IN YOUR FANTASIES I AM*"
DATA "HOW DO YOU KNOW YOU CAN'T*"
DATA "HAVE YOU TRIED?"
DATA "PERHAPS YOU CAN NOW*"
DATA "DID YOU COME TO ME BECAUSE YOU ARE*"
DATA "HOW LONG HAVE YOU BEEN*"
DATA "DO YOU BELIEVE IT IS NORMAL TO BE*"
DATA "DO YOU ENJOY BEING*"
DATA "WE WERE DISCUSSING YOU--NOT ME."
DATA "OH, I*"
DATA "YOU'RE NOT REALLY TALKING ABOUT ME, ARE YOU?"
DATA "WHAT WOULD IT MEAN TO YOU IF YOU GOT*"
DATA "WHY DO YOU WANT*"
DATA "SUPPOSE YOU SOON GOT*"
DATA "WHAT IF YOU NEVER GOT*"
DATA "I SOMETIMES ALSO WANT*"
DATA "WHY DO YOU ASK?"
DATA "DOES THAT QUESTION INTEREST YOU?"
DATA "WHAT ANSWER WOULD PLEASE YOU THE MOST?"
DATA "WHAT DO YOU THINK?"
DATA "ARE SUCH QUESTIONS ON YOUR MIND OFTEN?"
DATA "WHAT IS IT THAT YOU REALLY WANT TO KNOW?"
DATA "HAVE YOU ASKED ANYONE ELSE?"
DATA "HAVE YOU ASKED SUCH QUESTIONS BEFORE?"
DATA "WHAT ELSE COMES TO MIND WHEN YOU ASK THAT?"
DATA "NAMES DON'T INTEREST ME."
DATA "I DON'T CARE ABOUT NAMES --PLEASE GO ON."
DATA "IS THAT THE REAL REASON?"
DATA "DON'T ANY OTHER REASONS COME TO MIND?"
DATA "DOES THAT REASON EXPLAIN ANYTHING ELSE?"
DATA "WHAT OTHER REASONS MIGHT THERE BE?"
DATA "PLEASE DON'T APOLOGIZE!"
DATA "APOLOGIES ARE NOT NECESSARY."
DATA "WHAT FEELINGS DO YOU HAVE WHEN YOU APOLOGIZE?"
DATA "DON'T BE SO DEFENSIVE!"
DATA "WHAT DOES THAT DREAM SUGGEST TO YOU?"
DATA "DO YOU DREAM OFTEN?"
DATA "WHAT PERSONS APPEAR IN YOUR DREAMS?"
DATA "ARE YOU DISTURBED BY YOUR DREAMS?"
DATA "HOW DO YOU DO ...PLEASE STATE YOUR PROBLEM."
DATA "YOU DON'T SEEM QUITE CERTAIN."
DATA "WHY THE UNCERTAIN TONE?"
DATA "CAN'T YOU BE MORE POSITIVE?"
DATA "YOU AREN'T SURE?"
DATA "DON'T YOU KNOW?"
DATA "ARE YOU SAYING NO JUST TO BE NEGATIVE?"
DATA "YOU ARE BEING A BIT NEGATIVE."
DATA "WHY NOT?"
DATA "ARE YOU SURE?"
DATA "WHY NO?"
DATA "WHY ARE YOU CONCERNED ABOUT MY*"
DATA "WHAT ABOUT YOUR OWN*"
DATA "CAN YOU THINK OF A SPECIFIC EXAMPLE?"
DATA "WHEN?"
DATA "WHAT ARE YOU THINKING OF?"
DATA "REALLY, ALWAYS?"
DATA "DO YOU REALLY THINK SO?"
DATA "BUT YOU ARE NOT SURE YOU*"
DATA "DO YOU DOUBT YOU*"
DATA "IN WHAT WAY?"
DATA "WHAT RESEMBLANCE DO YOU SEE?"
DATA "WHAT DOES THE SIMILARITY SUGGEST TO YOU?"
DATA "WHAT OTHER CONNECTIONS DO YOU SEE?"
DATA "COULD THERE REALLY BE SOME CONNECTION?"
DATA "HOW?"
DATA "YOU SEEM QUITE POSITIVE."
DATA "ARE YOU SURE?"
DATA "I SEE."
DATA "I UNDERSTAND."
DATA "WHY DO YOU BRING UP THE TOPIC OF FRIENDS?"
DATA "DO YOUR FRIENDS WORRY YOU?"
DATA "DO YOUR FRIENDS PICK ON YOU?"
DATA "ARE YOU SURE YOU HAVE ANY FRIENDS?"
DATA "DO YOU IMPOSE ON YOUR FRIENDS?"
DATA "PERHAPS YOUR LOVE FOR FRIENDS WORRIES YOU."
DATA "DO COMPUTERS WORRY YOU?"
DATA "ARE YOU TALKING ABOUT ME IN PARTICULAR?"
DATA "ARE YOU FRIGHTENED BY MACHINES?"
DATA "WHY DO YOU MENTION COMPUTERS?"
DATA "WHAT DO YOU THINK MACHINES HAVE TO DO WITH YOUR PROBLEM?"
DATA "DON'T YOU THINK COMPUTERS CAN HELP PEOPLE?"
DATA "WHAT IS IT ABOUT MACHINES THAT WORRIES YOU?"
DATA "SAY, DO YOU HAVE ANY PSYCHOLOGICAL PROBLEMS?"
DATA "WHAT DOES THAT SUGGEST TO YOU?"
DATA "I SEE."
DATA "I'M NOT SURE I UNDERSTAND YOU FULLY."
DATA "COME COME ELUCIDATE YOUR THOUGHTS."
DATA "CAN YOU ELABORATE ON THAT?"
DATA "THAT IS QUITE INTERESTING."

REM ****************************************
REM *****DATA FOR FINDING RIGHT REPLIES*****
REM ****************************************
DATA 1,3,4,2,6,4,6,4,10,4,14,3,17,3,20,2,22,3,25,3
DATA 28,4,28,4,32,3,35,5,40,9,40,9,40,9,40,9,40,9,40,9
DATA 49,2,51,4,55,4,59,4,63,1,63,1,64,5,69,5,74,2,76,4
DATA 80,3,83,7,90,3,93,6,99,7,106,6

REM FUNCTIONS AND GOSUBS
'------------------------------------------------------
' PRINTLINE Statement:
'           This statement/function takes the place of
'           multiple PRINT statements that may be used,
'           and can get messy when used in nested IF 
'           conditions. If for example, you need to print
'           four blank lines, then PRINTLINE(4) will do
'           that for you, and look better than having a
'           a ton of PRINT statements all over your code.   
' 
DEF PRINTLINE (A)
    N=1
    DO 
       PRINT
       N=N+1
    UNTIL N > A   
ENDDEF   


Re: ELIZA - The program that created the AI field

Posted: Mon Oct 24, 2016 5:52 pm
by GeorgeMcGinn
One other thing I forgot to mention, which anyone who is interested in this field.

These programs have an official name or designation. They are called "Chatterbot" in the computer science field. And when you research them, you'll find that they server many purposes and have a wide range of applications.

George.