Tech

Programming with Python: build chatbot

Chatbots and voice assistants are an integral part of today’s digital world. On online platforms, bots are increasingly serving as the first point of contact for customer communication, for example if you have questions about a DSL tariff from a provider. When asked by voice, Siri, Google Assistant & Co. provide information about the weather of the next few days, read the news and know the latest football results. The computer scientist Joseph Weizenbaum (1923 – 2008) laid the foundations for these ubiquitous technologies in the 1960s at the Massachusetts Institute of Technology (MIT) with the computer program “ELIZA”. The program answers a person’s typed questions or sentences. It uses a catalog of pre-made text fragments and tries to make the most appropriate answer possible.

Wheatbaum programmed the parodistic simulation of a psychologist using a client-centered therapy procedure as a “digital counterpart”. Such a role of conversation was relatively easy to imitate, according to Weizenbaum, because it is roughly shortened to get the patient to speak and reflect by asking questions. The source code of the original ELIZA was written in the SLIP programming language – it is now considered lost. In Weizenbaum’s publications, however, all the principles of ELIZA are documented, which are necessary for a copy in another programming language.

ELIZAs "father": Joseph Weizenbaum created the program at MIT in the 1960s.

ELIZA’s “Father”: Joseph Weizenbaum created the program at MIT in the 1960s.

We programmed our ELIZA reconstruction in Python 3.7 on the online programming platform Repl.it and christened ELIZA +. The program runs like the big role model as a pure console application with keyboard input. To avoid some complications of the German language, ELIZA understands and speaks English. We also wrote the internal comments in the code in this language. For the sake of simplicity, ELIZA + is case sensitive and only answers with lower case letters. This programming project requires basic knowledge of Python: For example, you should use keywords such as if, while, for, def, from and import know and with functions, arguments, classes, objects and the method __init__() be familiar. The article uses selected code excerpts to show how ELIZA + accepts, interprets and finds answers. The complete code can be found on the online programming platform Repl.it.

  • Access to all heise + content
  • exclusive tests, guides & backgrounds: independent, critically sound
  • Read c’t, iX, Technology Review, Mac & i, Make, c’t photography directly in the browser
  • Register once – read on all devices – cancel monthly
  • first month free, then monthly € 9.95
  • Weekly newsletter with personal reading recommendations from the editor-in-chief

Start FREE month

Start FREE month now

already subscribed to heise +?

Sign up and read

Register now and read the article immediately

More information about heise +

To home page

.