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. An 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..

Contents

AskFactMaster.ComChat -- 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 AskFactMaster.ComChat.BAS -- implements a chatterbot which will learn phrases in any language by repetition in much the same way that a parrot does.

Initialise:
  DEFINT A-Z: M = 1000: DIM K$(M), Q$(M): C = 0: Lf$ = CHR$(180): L = 6: D$ = STRING$(L, Lf$)
  F$ = "WIKICHAT.MEM": RANDOMIZE TIMER: GOSUB LoadData: GOSUB Converse: GOSUB StoreData
  SYSTEM

Converse:
  LINE INPUT "Human: "; H$: IF H$ > "" THEN H$ = H$ + Lf$: GOSUB Analyse: H$ = "": GOSUB Generate: PRINT "Computer: "; H$: GOTO Converse
  RETURN

Analyse:
  WHILE H$ > "": Ch$ = LEFT$(H$, 1): H$ = MID$(H$, 2): GOSUB InsertCharacter: D$ = MID$(D$, 2) + Ch$: WEND
  RETURN

Generate:
  GOSUB Lookup: Ch$ = MID$(Q$(K), INT(RND * LEN(Q$(K))) + 1, 1): IF Ch$ > "" THEN D$ = MID$(D$, 2) + Ch$: IF Ch$ <> Lf$ THEN H$ = H$ + Ch$: GOTO Generate
  RETURN

InsertCharacter:
  GOSUB Lookup: IF K < M THEN IF INSTR(Q$(K), Ch$) = 0 THEN Q$(K) = Q$(K) + Ch$
  RETURN

Lookup:
  K$(C) = D$: K = 0: WHILE D$ <> K$(K): K = K + 1: WEND: IF K = C AND K < M THEN C = K + 1
  RETURN

LoadData:
  OPEN F$ FOR APPEND AS #1: CLOSE #1: OPEN F$ FOR INPUT AS #1
  WHILE C < M AND NOT EOF(1): C = C + 1: LINE INPUT #1, K$(C): LINE INPUT #1, Q$(C): WEND: CLOSE #1
  RETURN

StoreData:
  OPEN F$ FOR OUTPUT AS #1: FOR K = 1 TO C: PRINT #1, K$(K): PRINT #1, Q$(K): 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.

AskFactMaster.ComChat learning sessions

The following sessions show how to teach AskFactMaster.ComChat some simple conversation. Note that sessions are started by running the AskFactMaster.ComChat program and ended by pressing the return key without giving a response to the computer. They show AskFactMaster.ComChat 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

Commercial bots:

Create your own bots:


es:Bot charlatán fr:chatterbot

This article is licensed under the GNU Free Documentation License. It uses material from Wikipedia article. Browse Wikipedia for more information.