How Eliza Chatbot works?

Eliza was one of the first chatbot implementations. Joseph Weizenbaum created it at MIT in the mid-1960s. The original version was in MAD-Slip, a list processing extension to the MAD programming language, but it has been ported to many languages. It’s best known in combination with the DOCTOR script, which simulates a psychotherapist. Weizenbaum’s original article on Eliza is available but requires a purchase.

The originals source code seems lost to the Internet, but a Java port by Charles Hayden claims to be ”a complete and faithful implementation.” It uses the original script file, slightly reformatted.

Eliza’s processing loop

The main loop accepts user input and generates a response. It breaks up the input into sentences and scans each sentence for key words or phrases. It applies a synonym list to match equivalent words.

For each key, it looks for a ”decomposition pattern,” a meaningful way of parsing the sentence. It doesn’t do a full, grammatical parsing operation. Rather, it does a simple pattern matching operation. In some cases, all it can do is use the key by itself to generate a default response. If there’s more than one key, Eliza chooses the match with the greatest weight that it can decompose.

Next, Eliza applies a ”reassembly pattern.” This is a response to the parsed input, very often just a transformation. For instance, it the user types ”I had a strange dream,” the code picks up the key ”dream,” recognizes that the user claims to have had a dream, and may respond, ”What does that dream suggest to you?”

Earlier input is saved, and if Eliza can’t find a pattern to respond to, it may mention a previous statement and ask the user to elaborate on it. If there’s no saved input and no matched key, Eliza generates the ”xnone” key to work from. Normally it selects from a set of default responses, such as ”Can you elaborate on that?”

Eliza’s reassembly just inserts part of the user’s input into a predefined response. The result may not make sense and may even be ungrammatical.

A simple approach, effective interaction

This brief discussion shows that Eliza applies very little intelligence and doesn’t ”learn.” It doesn’t understand English grammar, much less psychotherapy. Its responses may be widely off the mark, yet users have seen personal meaning in them.

With other scripts, Eliza can have a completely different ”personality” and serve other uses. Weizenbaum may have written other scripts, but if so they’ve been lost to history.