Chatterbot

A chatterbot (also chatbot, chatterbox) is a bot program which attempts to maintain a conversation with a person. While it is true that a good understanding of a conversation is required to carry on a meaningful dialog, most chatterbots do not attempt this. Instead they attempt to pick up cue words or phrases from the person which will allow them to use pre-prepared or pre-calculated responses which can move the conversation on in an apparently meaningful way without requiring them to know what they are talking about. One exception to this approach is Jabberwacky which attempts to model the way humans learn new facts and language.

The classic early chatterbots are ELIZA and PARRY. More recent programs are Racter and A.L.I.C.E.. A collection of games and functional features accessed via natural language processing allows ELLA to further extend the potential of chatterbots.

Contents

WikiChat -- a simple Chatterbot example

In principle a chatterbot can be a very short program. For instance the following QBASIC program—which should be copied and saved as WikiChat.BAS—implements a chatterbot which will learn phrases in any language by repetition in much the same way that a parrot does.

WikiChat:
  DEFINT A-Z
  GOSUB Initialise
  GOSUB LoadData
  GOSUB Converse
  GOSUB StoreData
  SYSTEM

Initialise:
  LET DictionarySize = 1000
  DIM Context$(DictionarySize)
  DIM Alternatives$(DictionarySize)
  LET EmptyRow = 0
  LET EndOfResponseCharacter$ = CHR$(180)
  LET ContextLength = 6
  LET CurrentContext$ = STRING$(ContextLength, EndOfResponseCharacter$)
  LET DictionaryFile$ = "WIKICHAT.MEM"
  RANDOMIZE TIMER
  RETURN

Converse:
  DO
    LINE INPUT "Human: "; Response$
    IF Response$ = "" THEN EXIT DO
    LET Response$ = Response$ + EndOfResponseCharacter$
    GOSUB Analyse
    LET Response$ = ""
    GOSUB Generate
    PRINT "Computer: "; Response$
  LOOP
  RETURN

Analyse:
  DO WHILE Response$ > ""
    LET CurrentCharacter$ = LEFT$(Response$, 1)
    LET Response$ = MID$(Response$, 2)
    GOSUB InsertCharacter
    LET CurrentContext$ = MID$(CurrentContext$, 2) + CurrentCharacter$
  LOOP
  RETURN

Generate:
   DO
     GOSUB Lookup
     LET CurrentCharacter$ = MID$(Alternatives$(DictionaryIndex), INT(RND * LEN(Alternatives$(DictionaryIndex))) + 1, 1)
     IF CurrentCharacter$ = "" THEN
       EXIT DO
     ELSE
       LET CurrentContext$ = MID$(CurrentContext$, 2) + CurrentCharacter$
       IF CurrentCharacter$ = EndOfResponseCharacter$ THEN
         EXIT DO
       ELSE
         LET Response$ = Response$ + CurrentCharacter$
       END IF
     END IF
   LOOP
   RETURN

InsertCharacter:
  GOSUB Lookup
  IF INSTR(Alternatives$(DictionaryIndex), CurrentCharacter$) = 0 THEN
    LET Alternatives$(DictionaryIndex) = Alternatives$(DictionaryIndex) + CurrentCharacter$
  END IF
  RETURN

Lookup:
  LET Context$(EmptyRow) = CurrentContext$
  LET DictionaryIndex = 0
  DO WHILE CurrentContext$ <> Context$(DictionaryIndex)
    LET DictionaryIndex = DictionaryIndex + 1
  LOOP
  IF DictionaryIndex = EmptyRow AND DictionaryIndex < DictionarySize THEN
    LET Alternatives$(EmptyRow) = ""
    LET EmptyRow = DictionaryIndex + 1
  END IF
  RETURN

LoadData:
  OPEN DictionaryFile$ FOR APPEND AS #1
  CLOSE #1
  OPEN DictionaryFile$ FOR INPUT AS #1
  DO WHILE EmptyRow < DictionarySize AND NOT EOF(1)
    LINE INPUT #1, Context$(EmptyRow)
    LINE INPUT #1, Alternatives$(EmptyRow)
    LET EmptyRow = EmptyRow + 1
  LOOP
  CLOSE #1
  RETURN

StoreData:
  OPEN DictionaryFile$ FOR OUTPUT AS #1
  FOR DictionaryIndex = 0 TO EmptyRow - 1
    PRINT #1, Context$(DictionaryIndex)
    PRINT #1, Alternatives$(DictionaryIndex)
  NEXT
  CLOSE #1
  RETURN

Note that to begin with, this chatterbot knows nothing and therefore says nothing. However if one uses simple conversation with it, like a parrot it will begin to reply as it starts to find responses that are appropriate for the immediately preceding sentence.

WikiChat learning sessions

The following sessions show how to teach WikiChat some simple conversation. Note that sessions are started by running the WikiChat program and ended by pressing the return key without giving a response to the computer. They show WikiChat being taught a basic conversational pattern in English.

(Session 1) 
Human: hello there
Computer:
Human: hello
Computer:
Human: how are you
Computer:
Human: fine thanks how are you
Computer: fine thanks how are you
Human: fine thanks
Computer:
Human:

(Session 2) 
Human: hello
Computer: how are you
Human: fine thanks how are you
Computer: fine thanks
Human: glad to hear it
Computer:
Human:
(Session 3) 
Human: hello
Computer: how are you
Human: fine thanks
Computer: glad to hear it
Human:

The responses will be stored for the next session, so that there is no need to reteach them but it should be noted that while this example chatterbot will create "original" sentences after a little teaching, it has a very limited capacity and works best with short sentences.

See also

External links

es:Bot charlatán fr:chatterbot

Navigation

  • Art and Cultures
    • Art (https://academickids.com/encyclopedia/index.php/Art)
    • Architecture (https://academickids.com/encyclopedia/index.php/Architecture)
    • Cultures (https://www.academickids.com/encyclopedia/index.php/Cultures)
    • Music (https://www.academickids.com/encyclopedia/index.php/Music)
    • Musical Instruments (http://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
  • Biographies (http://www.academickids.com/encyclopedia/index.php/Biographies)
  • Clipart (http://www.academickids.com/encyclopedia/index.php/Clipart)
  • Geography (http://www.academickids.com/encyclopedia/index.php/Geography)
    • Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
    • Maps (http://www.academickids.com/encyclopedia/index.php/Maps)
    • Flags (http://www.academickids.com/encyclopedia/index.php/Flags)
    • Continents (http://www.academickids.com/encyclopedia/index.php/Continents)
  • History (http://www.academickids.com/encyclopedia/index.php/History)
    • Ancient Civilizations (http://www.academickids.com/encyclopedia/index.php/Ancient_Civilizations)
    • Industrial Revolution (http://www.academickids.com/encyclopedia/index.php/Industrial_Revolution)
    • Middle Ages (http://www.academickids.com/encyclopedia/index.php/Middle_Ages)
    • Prehistory (http://www.academickids.com/encyclopedia/index.php/Prehistory)
    • Renaissance (http://www.academickids.com/encyclopedia/index.php/Renaissance)
    • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
    • United States (http://www.academickids.com/encyclopedia/index.php/United_States)
    • Wars (http://www.academickids.com/encyclopedia/index.php/Wars)
    • World History (http://www.academickids.com/encyclopedia/index.php/History_of_the_world)
  • Human Body (http://www.academickids.com/encyclopedia/index.php/Human_Body)
  • Mathematics (http://www.academickids.com/encyclopedia/index.php/Mathematics)
  • Reference (http://www.academickids.com/encyclopedia/index.php/Reference)
  • Science (http://www.academickids.com/encyclopedia/index.php/Science)
    • Animals (http://www.academickids.com/encyclopedia/index.php/Animals)
    • Aviation (http://www.academickids.com/encyclopedia/index.php/Aviation)
    • Dinosaurs (http://www.academickids.com/encyclopedia/index.php/Dinosaurs)
    • Earth (http://www.academickids.com/encyclopedia/index.php/Earth)
    • Inventions (http://www.academickids.com/encyclopedia/index.php/Inventions)
    • Physical Science (http://www.academickids.com/encyclopedia/index.php/Physical_Science)
    • Plants (http://www.academickids.com/encyclopedia/index.php/Plants)
    • Scientists (http://www.academickids.com/encyclopedia/index.php/Scientists)
  • Social Studies (http://www.academickids.com/encyclopedia/index.php/Social_Studies)
    • Anthropology (http://www.academickids.com/encyclopedia/index.php/Anthropology)
    • Economics (http://www.academickids.com/encyclopedia/index.php/Economics)
    • Government (http://www.academickids.com/encyclopedia/index.php/Government)
    • Religion (http://www.academickids.com/encyclopedia/index.php/Religion)
    • Holidays (http://www.academickids.com/encyclopedia/index.php/Holidays)
  • Space and Astronomy
    • Solar System (http://www.academickids.com/encyclopedia/index.php/Solar_System)
    • Planets (http://www.academickids.com/encyclopedia/index.php/Planets)
  • Sports (http://www.academickids.com/encyclopedia/index.php/Sports)
  • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
  • Weather (http://www.academickids.com/encyclopedia/index.php/Weather)
  • US States (http://www.academickids.com/encyclopedia/index.php/US_States)

Information

  • Home Page (http://academickids.com/encyclopedia/index.php)
  • Contact Us (http://www.academickids.com/encyclopedia/index.php/Contactus)

  • Clip Art (http://classroomclipart.com)
Toolbox
Personal tools