Skip to main content

ELIZA for MicroPython

ELIZA is a retro chatbot that simulates a psychotherapist, based on the original 'ELIZA' script created by Joseph Weizenbaum in 1966. The detailed output provides insights into the workings of this iconic dialogue system and supports learning basic natural language processing concepts.

Reference

"ELIZA - A Computer Program For the Study of Natural Language Communication Between Man and Machine" by Joseph Weizenbaum, 1966.

DOI: 10.1145/365153.365168 S2CID: 1896290

Example conversation

ELIZA: DO COMPUTER WORRY YOU
CLIENT: WHAT IF THEY START TO THINK
ELIZA: DO YOU THINK ITS LIKELY THAT THEY START TO THINK
CLIENT: ARE YOU THINKING YOURSELF
ELIZA: WHY ARE YOU INTERESTED IN WHETHER I AM THINKING MYSELF OR NOT

Example log with processing information

CLIENT: YES BUT MAYBE EVERYONE HAS PROBLEMS EVEN A COMPUTER
Message: 'YES BUT MAYBE EVERYONE HAS PROBLEMS EVEN A COMPUTER'
	Text segmentation: 'YES BUT MAYBE EVERYONE HAS PROBLEMS EVEN A COMPUTER'
	Processing sentence: 'YES BUT MAYBE EVERYONE HAS PROBLEMS EVEN A COMPUTER'
	Tokens: 'YES', 'BUT', 'MAYBE', 'EVERYONE', 'HAS', 'PROBLEMS', 'EVEN', 'A', 'COMPUTER'
	Keystack (detected keywords): 'COMPUTER' (rank: 50), 'EVERYONE' (rank: 2), 'YES' (rank: 0), 'MAYBE' (rank: 0)
	Altered sentence: ' YES BUT MAYBE EVERYONE HAS PROBLEMS EVEN A COMPUTER'
	Processing rules associated with keyword: 'COMPUTER'
		No decomposition defined for rule (use top answer)
	Found response for keyword: 'COMPUTER' (ignoring remaining keywords)
Response: DO COMPUTER WORRY YOU
ELIZA: DO COMPUTER WORRY YOU

How to install

python -m pip install --upgrade micropython_eliza

How to run

Start chat in the console:

python -m micropython_eliza.chat

See an example conversation:

python -m micropython_eliza.demo

How to use

import sys
from micropython_eliza import eliza

USERNAME_IN_CHAT = "YOU"

agent = eliza.create()
print("\n<press enter with no message to exit>")
print(f"{agent.name()}: {agent('')}")
print(f"{USERNAME_IN_CHAT}: ")
msg = sys.stdin.readline().strip()
while msg:
    print(f"{agent.name()}: {agent(msg)}")
    print(f"{USERNAME_IN_CHAT}: ")
    msg = sys.stdin.readline().strip()

To enable printing info and debug messages, provide log handlers, e.g.:

agent = eliza.create(log_info=print, log_debug=print)

Release files for micropython-eliza 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for micropython-eliza 0.1.1
File Size Uploaded
micropython_eliza-0.1.1.tar.gz 14.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for micropython-eliza 0.1.1
File Interpreter ABI Platform
micropython_eliza-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 31.1 kB

Release files / micropython_eliza-0.1.1.tar.gz

Download URL micropython_eliza-0.1.1.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6693290a33b4124f0f0047a91ca0e88c14c11fd7d50eea9476873629c6e165a6
BLAKE2b-256 checksum
How to use checksums
11fe0af549bd1eeb2fae0478e51cb53cb85176f8cb8aad724f810fe71689275b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.0

Release files / micropython_eliza-0.1.1-py3-none-any.whl

Download URL micropython_eliza-0.1.1-py3-none-any.whl
Size 16.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
af98048864e0a176ca74d3260bc03201a775c630967ad747132bc96d60f22e54
BLAKE2b-256 checksum
How to use checksums
b32093f977f271e4a77ecf24e93b32ab786dadb9cfa9132bca0738d9f92f82c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.0

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page