The code

The DOCTOR script

DOCTOR is the script that made ELIZA famous. It is a list of keywords, each with patterns for taking apart what you say and templates for putting a reply back together. Feed ELIZA this script and it answers like a Rogerian therapist.

THE DICTIONARY

Every word DOCTOR knows, and the rules behind it. Type to filter the keyword list, then click a keyword to read its transformation rules: the decomposition patterns that take your sentence apart, and the reassembly templates that build a reply.

How a rule works

Each keyword carries a rank and a set of rules. A decomposition pattern splits your sentence into numbered parts; a reassembly template builds a reply from those parts. Take the keyword ALIKE, ranked high so it wins over ordinary words:

(ALIKE 10 (=DIT))

(DIT
    ((0)
        (IN WHAT WAY)
        (WHAT RESEMBLANCE DO YOU SEE)
        (WHAT DOES THAT SIMILARITY SUGGEST TO YOU)))

Say “Men are all alike” and ALIKE fires, hands off to DIT, and ELIZA replies “IN WHAT WAY”. The next time, it cycles to the following template. The famous opening of Weizenbaum’s paper is nothing more than this.

The canonical conversation

This is the exchange Weizenbaum printed in the 1966 CACM paper. Every ELIZA line is produced by the rules in the DOCTOR script. Try it yourself ›

DOCTOR
W 0809.3
Men are all alike.
          IN WHAT WAY
They're always bugging us about something or other.
          CAN YOU THINK OF A SPECIFIC EXAMPLE
Well, my boyfriend made me come here.
          YOUR BOYFRIEND MADE YOU COME HERE
He says I'm depressed much of the time.
          I AM SORRY TO HEAR YOU ARE DEPRESSED
It's true. I am unhappy.
          DO YOU THINK COMING HERE WILL HELP YOU NOT TO BE UNHAPPY
I need some help, that much seems certain.
          WHAT WOULD IT MEAN TO YOU IF YOU GOT SOME HELP
Perhaps I could learn to get along with my mother.
          TELL ME MORE ABOUT YOUR FAMILY
My mother takes care of me.
          WHO ELSE IN YOUR FAMILY TAKES CARE OF YOU
You are like my father in some ways.
          WHAT RESEMBLANCE DO YOU SEE
R 0809.3+.80

Three scripts, one in progress

There are three known contemporaneous DOCTOR scripts: the one published as an appendix to the 1966 paper, and two more (.TAPE. 102 and .TAPE. 100) on a printout in Weizenbaum’s archive. They are clearly successive drafts: keywords gained extra replies, a misplaced line was fixed, redirects were simplified. The script was built incrementally, almost without a plan, each change improving ELIZA’s ability to conceal its lack of understanding. The DOCTOR script, a work in progress ›

Memory

One special rule, MEMORY, watches for when you mention something that is “yours”, stores a transformed version of it, and brings it back later (“EARLIER YOU SAID YOUR…”). It is the closest DOCTOR comes to keeping track of a conversation.

THE FULL SCRIPT

The whole DOCTOR script as published in the appendix to Weizenbaum’s 1966 Communications of the ACM paper, transcribed by Anthony C. Hay (DOCTOR.txt in the repository). This is the exact text the engine on this site reads, listed here as a line-printer printout.

PRINT DOCTOR
W 1009.4

        
R 1009.4+.28