How ELIZA works

ELIZA is a classic rule-based chatbot. It produces responses using a simple pipeline: find a keyword, match a pattern, swap pronouns, then fill a response template. It feels “smart” mainly because the script is good at keeping you talking.

pattern matching reflection rules templates fallbacks

The basic loop

  1. Normalize input (trim, simplify punctuation)
  2. Check for keywords (“mother”, “feel”, “because”)
  3. Try patterns (often regex-like matching)
  4. Apply reflections (“I” ↔ “you”, “my” ↔ “your”)
  5. Choose a template and insert the transformed phrase
  6. Fallback if nothing matches (“Please go on.”)

Reflections (I ↔ you)

A key trick: take part of what you said and flip it into the bot’s perspective. That’s why “I feel sad” becomes “Do you often feel sad?”

// Example reflection mapping (simplified)
const reflections = {
  "i am": "you are",
  "i": "you",
  "me": "you",
  "my": "your",
  "you are": "I am",
  "you": "I"
};

Rules and templates

ELIZA’s script is basically a set of rules. Each rule has patterns and possible responses. A match produces a response template like:

"Why do you say that (1)?"

Where (1) is a captured phrase from your input (after reflections).

Why it works (psychologically)

ELIZA often responds with open questions, gentle prompts, and reframing. Humans are extremely good at projecting meaning onto vague but plausible replies. For the deeper implications, see Ethics.

FAQ

Next: ELIZA’s influence on modern chatbots.