0% found this document useful (0 votes)
51 views12 pages

Elizabeth Handout

Uploaded by

Xaad Dfd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views12 pages

Elizabeth Handout

Uploaded by

Xaad Dfd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Using the Elizabeth Conversation Program

1 2
Obtaining the Software

Using Elizabeth  The Elizabeth software can be downloaded from the


Elizabeth home page at:
www.philocomp.net/ai/elizabeth
 The system is available either as a ‘zip’ file or as a
An introduction to Chatbots ‘self-extracting zip’ file. Whichever you choose,
and Natural Language Processing unpack the files onto the machine you are using, e.g.
into the folder C:\Elizabeth on your own machine, or
C:\Temp\Elizabeth if you do not have permission to
Peter Millican, July 2018 create a new folder.
Hertford College, University of Oxford  For links to other chatbot systems (as well as to
Elizabeth), see www.simonlaven.com

1 2

3 4
Running the Software Recent Versions of Elizabeth
 The main system file is called:  The latest version of Elizabeth on the website is 2.20.
Elizabeth.exe This has been adapted (in 2018) to remove dependence
on the old Windows Help system (unavailable on
 To run it, simply identify this file within Windows Explorer,
Windows 10), so the Help documentation is now in the
and double-click.
PDF file Elizabeth.pdf. Section references in this
 Make sure that the help documentation file: presentation (e.g. “§1.4”) are to that PDF document.
Elizabeth.pdf  The previous main version, 2.07, provided significant
is in that same directory (the system also uses “My Scripts” improvements in power (thus enabling a Turing machine
and “Illustrative Scripts” subdirectories). simulator and original ELIZA clone), e.g.:
 Use the first item in Elizabeth’s Help menu to view the  Memory indirection to allow creation of arrays;
contents of the help file, and start reading – everything you  Keyword sets can be either sequential or randomised;
need to know about the system is explained there! (You can  Support for arbitrary recursion and text splitting/combining;
also use the Help menu to load various illustrative scripts.)  Trace enhancement with multiple options.

3 4

5 6
Playing Around The Illustrative Conversation
 Elizabeth’s behaviour is based on a ‘Script’ file.  Take a look at the section ‘Illustrative Script and
 Initially, Elizabeth should start up with a Script which Conversation’, §1.4 in Elizabeth.pdf. Try typing
shows the ‘Welcome’ message: inputs similar in style to what are shown in the part
headed ‘The Conversation’ (§1.4.2), e.g. type in
HELLO, I'M ELIZABETH. WHAT WOULD sentences containing words or phrases such as:
YOU LIKE TO TALK ABOUT?
 ‘mum’ or ‘dad’
If this doesn’t happen for any reason, try locating and  ‘I think …’
loading the script file Elizabeth.txt using ‘Load script  ‘… is younger than …’
file and start’ from the File menu.
 ‘I like …ing’
 To familiarise yourself with Elizabeth, just play around
a bit, typing input sentences, clicking on ‘Enter’, and  While doing this, look at the ‘Trace’ tab (just right of
the ‘Dialogue’ tab): this shows how your input is being
seeing what happens. Note that the conversation is processed to produce the system’s replies.
recorded in the ‘Dialogue’ tab.

5 6

Elizabeth 2.20, Peter Millican, July 2018 1


Using the Elizabeth Conversation Program
7 8
The Script Editor The First Illustrative Script
 From Elizabeth’s File menu, select ‘Transfer script  Try to work out how the Script that you see within
into Script Editor’ – this will start up the Script the Editor is determining Elizabeth’s conversational
Editor with the current script file loaded in. behaviour – if any of it seems puzzling, refer to
 Now make a change to the ‘Welcome’ message ‘Illustrative Script and Conversation’ (§1.4).
(appears after ‘W’ in the second line of the Script);  Try playing around with the Script (like you did
then from the Editor’s File menu, select ‘Restart already with the ‘Welcome’ message), and see what
Elizabeth after saving’ – this will save your change, effect this has on Elizabeth’s conversation.
and restart Elizabeth using this edited script file  Carry on doing this as we now explore Elizabeth’s
(with its new ‘Welcome’ message). data tables as shown in the various system ‘tabs’.
 Note that the two File menus give various options Most of what you see in the tables comes directly
for switching between Elizabeth and the Editor. from the Script file.

7 8

9 10
Simple Message Types The Main Processing Cycle
 The ‘Welcome/Quit’ tab shows Welcome and Quitting Receive user’s input Input Transformations
messages – one of each is selected respectively to start as the ‘active text’ Apply any input transforms
the conversation, and to end it (when the user selects
‘Quit’ from the File menu). Keyword Transformations
 The ‘Void/No-key’ tab shows Void Input messages – Search for a keyword; if one is found,
one of these is selected in response to any ‘null’ input – replace the active text with a response
and No-Keyword messages – for use when no from the corresponding set; if not,
‘keyword’ is identified in the input. replace it with a no-keyword response
 If there are more than one of any of these kinds of
messages, then by default (changeable through the
Options menu) the selection is random, except that the Output the new Output Transformations
same message won’t be chosen twice in succession. ‘active text’ Apply any output transforms

9 10

11 12
Input/Output Transformations Keyword Transformations
 Input transformations are applied to the initial input;  Keywords and responses are grouped into sets, so order
their main use is to standardise words that you want to them in your script file accordingly (set 1 keys, then set
be treated similarly, e.g. 1 responses, then set 2 keys … etc). Generally it’s best
to capitalise keys and responses.
I mum => mother
 Unlike Input and Output Transformations, only one
if you want ‘mum’ to be changed to ‘mother’. Keyword Transformation is applied each time.
 Output transformations are applied to the final output;
 Note how pattern matching and substitution are used
often their main use is to change first-person to second- within the keywords and responses in the Illustrative
person and vice-versa, e.g. Script, and their effect as you ‘play’.
O i am => YOU ARE  See the help sections on ‘The Input/Keyword/Output/
 Make sure you capitalise these as illustrated above (this Final Transformation Process’ (§2.3) and ‘Pattern
will be explained a bit later). Matching’ (§3.1) if you want more details.

11 12

Elizabeth 2.20, Peter Millican, July 2018 2


Using the Elizabeth Conversation Program
13 14
Simple Keywords and Responses Keywords with Substitution
 The following script commands create a simple  The following script commands create a keyword/
keyword/response set with two keywords and three response set which pattern-matches the keyword
responses: against the active text and then makes appropriate
K MOTHER
substitutions in the response:
K FATHER K [p1] IS YOUNGER THAN [p2]
R TELL ME MORE ABOUT YOUR FAMILY. R SO [p2] IS OLDER THAN [p1]
R DO YOU HAVE ANY BROTHERS OR SISTERS?
R ARE YOU THE YOUNGEST IN YOUR FAMILY?  Any pattern of the form [p…] is a phrase wildcard,
matching any sequence of words (which can contain
 When ‘mother’ or ‘father’ is found in the active only letters, hyphens or apostrophes). [p1] is
text, one of the responses will be chosen (randomly,
treated as a separate pattern from [p2].
but avoiding immediate repetition if possible).

13 14

15 16
Pattern Matching Empty Patterns
 Any of these patterns can be used in combination (see the  [let1] and [let2] each matches one letter, so the
help file section ‘Pattern Matching’ for the complete list):
following might generate the dialogue: ‘My degree is
[w…] any single complete word (or part-word)
[t…] any single complete term (or part-term) – a term, a BSc. IS GETTING A BSC DEGREE HARD?’
unlike a word, may contain digits as well as letters K DEGREE [X] B[let1][let2]
[l…] any single letter (i.e. any character that can occur R IS GETTING A B[let1][let2] DEGREE HARD?
in a word, including hyphen/apostophe)
[p…] a phrase – any sequence of complete words  Suppose you want to do this not only for ‘BSc’ and
[X…] any text string which contains only complete ‘items’
(so it cannot contain only half a word or number). ‘BCL’ etc, but also ‘BA’. To do this, allow the
[b…] like [X…], but will only match text in which all second pattern to match nothing by adding ‘?’:
brackets – ‘(’, ‘)’, ‘<’, and ‘>’, correctly pair up.
K DEGREE [X] B[let1][let2?]
[;] any punctuation mark
R IS GETTING A B[let1][let2?] DEGREE HARD?
[] matches beginning or end of active text

15 16

17 18
Matching the Ends of the Text Capitalisation and Transformations
 The term [] is used to match the beginning, or the end, of  We have seen that different types of capitalisation are
the active text. This enables you to treat words differently if typically used for the various transformations:
they are the first, or last, word of the user’s input. We’ll see
a ‘first word test’ a bit later (with memorisation of ‘my’ I mum => mother
phrases); here’s an example of a ‘last word test’: K FATHER
O you [] => ME R TELL ME MORE ABOUT YOUR FAMILY.
O you => I O i am => YOU ARE
 These two output transformations will have the effect of  This all fits with the following rule:
changing ‘you’ into ‘ME’ if it is the very last word of the
active text, but into ‘I’ otherwise – this makes sense because A lower-case pattern can only match with a lower-case
when ‘you’ appears at the end it’s normally the object of the text, whereas an upper-case pattern can match with
sentence rather than the subject (e.g. ‘She saw you’). either a lower-case or an upper-case text.

17 18

Elizabeth 2.20, Peter Millican, July 2018 3


Using the Elizabeth Conversation Program
19 20

 Initially, the input text is converted to lower case. Putting


Modularising Your Script
all your input transformations in lower case ensures that
the text stays lower case at this stage.  As your script grows, it can be made easier to manage
by dividing it into separate files. See the ‘Turbo Eliza’
 If a keyword is found, the text usually gets replaced with a example under the Help menu (Basic script commands).
response which is already in the right form for output, so
you don’t want to apply output transformations to it. This  You will need one ‘master’ file, which can then ‘pull
is ensured by putting the responses in upper case, and the in’ sub-files using an include directive, e.g.:
left-hand side of the output transformations in lower case. #INCLUDE My Scripts\output.txt
 If an output transformation is applied, e.g. to change ‘my’  This enables you to use e.g. the same set of output
to ‘YOUR’, then capitalisation on the right-hand side transformations within several scripts.
ensures that no further transformations will be applied to
text that’s already been converted.  Sub-files can contain further include directives, so you
can organise your script into sub-sections, etc.
 See §5.1 for more detail, and worked examples.

19 20

21 22
Dynamic Commands Memorising and Recalling Phrases
 Script commands can be applied dynamically, and  Note from the previous example:
can be ‘triggered’ by almost any kind of process  ‘& {…}’ is used to specify an action, in this case one
(see the help file on ‘Dynamic Script Processing’ that is triggered by the matching of a keyword and the
for details and a variety of examples). selection of a corresponding response;
 ‘{M [phrase]}’ memorises whatever text was
 The most important use of this is for memorisation matched against [phrase];
of phrases, which can then be recalled later, e.g.:
 [M] can then be used to recall the latest remembered
K MY NAME IS [phrase] text, within any kind of transformation or response;
& {M [phrase]}  Here a no-keyword response is created, which when
R NICE TO MEET YOU [phrase]! invoked will make use of the latest memory ([M]).
N WHAT DO YOU LIKE DOING, [M]?  [M-1], [M-2] etc. can be used to recall earlier
memories (the last but 1, last but 2, etc.).

21 22

23 24
Returning to a Previous Topic Index Codes
 The most common use of memorisation in the original  Every transformation, response, memory etc. that Elizabeth
ELIZA program is to deal with the situation where no accepts is assigned an index code. Unless you specify an
keyword is found, to give an impression of continuity index code yourself, these are automatically created for you,
by returning to a previous topic. starting with ‘001’, ‘002’, ‘003’ etc.
 A good way of recognising likely topics is to look for  You can see what index codes have been assigned by
user input starting with ‘my’, e.g. ‘my dog is ill’. Note inspecting the relevant tables.
the use of [] to match the beginning of the text:  Index codes enable you to pick out specific transformations/
K [] MY [phrase]
responses/memories for dynamic modification, recall etc.
& {M [phrase]}  We’ll be using index codes only for memories – enabling us
R YOUR [phrase]? to handle many memories, and not just the latest one. (See
N DOES THAT HAVE ANYTHING TO DO WITH THE help on ‘Control of Scripts using Command Index Codes’
FACT THAT YOUR [M]? and ‘Command Syntax Reference Guide’ for other uses.)

23 24

Elizabeth 2.20, Peter Millican, July 2018 4


Using the Elizabeth Conversation Program
25 26
Memorising Pronoun References Using Multiple Memories
 One simple use of index-coded memories is to keep track of  This script will keep track of some of your favourites,
what’s been referred to by a recent output, so that pronouns (‘it’, tell you what they are, and then go on repeating them.
‘she’ etc.) can be dealt with appropriately. The following might
W WHAT ARE YOUR FAVOURITE GAME, TEAM AND PLAYER?
yield ‘I watch football. WHAT DO YOU THINK OF
K GAME [X?] IS [phrase]
ARSENAL? They’re good. I LIKE THEIR STYLE …’: here & {Mgame [phrase]}
the input transformations replace ‘They’re’ in the last input with K TEAM [X?] IS [phrase]
‘ARSENAL ARE’, enabling an appropriate response to be found. & {Mteam [phrase]}
K PLAYER [X?] IS [phrase]
I THEY’RE => THEY ARE & {Mplayer [phrase]}
I THEY => [Mthey] R THANK YOU - SAY "OK" WHEN YOU'VE FINISHED
K FOOTBALL K OK
R WHAT DO YOU THINK OF ARSENAL? R YOUR FAVOURITE GAME IS [Mgame], TEAM IS [Mteam],
& {Mthey ARSENAL} AND PLAYER IS [Mplayer]
K ARSENAL & {I [word] => OK}
R I LIKE THEIR STYLE, BUT NOT THEIR RESULTS! N PLEASE CARRY ON TELLING ME YOUR FAVOURITES

25 26

27 28
 Note from the previous example: Timing of Dynamic Commands (i)
 ‘K GAME [X?] IS [phrase]’ matches any text containing the  In the last example, instead of using ‘OK’ as a prompt,
word ‘GAME’ and then at some later point ‘IS’ followed by a you might try outputting the three memories, as soon as
phrase (recall that a ‘phrase’ here just means one or more they exist, using a catch-all output transformation …
words in sequence);
 ‘& {Mgame [phrase]}’ then memorises the relevant phrase W WHAT ARE YOUR FAVOURITE GAME, TEAM AND PLAYER?
under the index code ‘game’; K GAME [X?] IS [phrase]
& {Mgame [phrase]}
 ‘R YOUR FAVOURITE GAME IS [Mgame], TEAM IS
K TEAM [X?] IS [phrase]
[Mteam], AND PLAYER IS [Mplayer]’ outputs the three
& {Mteam [phrase]}
memories, but this response cannot be used until something K PLAYER [X?] IS [phrase]
has been memorised under each of the three index codes (you & {Mplayer [phrase]}
can check this by inputting ‘OK’); R THANK YOU - DO GO ON ...
 ‘& {I [word] => OK}’ creates an input transformation which O [X] => YOUR FAVOURITE GAME IS [Mgame], TEAM IS
[Mteam], AND PLAYER IS [Mplayer]
changes all words to ‘OK’ – this simply ensures that from then
N PLEASE CARRY ON TELLING ME YOUR FAVOURITES
on, any input will be treated as though it was just ‘OK OK …’.

27 28

29 30
Timing of Dynamic Commands (ii) Using Null Memories to Keep Track
 You might now expect that as soon as the three memories  Recall that responses (etc.) containing memory
have been saved, the catch-all output transformation references like ‘[Mthey]’ cannot be used until
([X] => YOUR FAVOURITE …) will automatically become
those references succeed (i.e. until something has
operative no matter what the active text is, won’t it?
been memorised under the relevant code).
 But doing this won’t work until you type in another input
… if you look at the trace tab just after you’ve typed in your  However the ‘something’ saved can be the null
three favourites, you should see why. string (i.e. nothing!) – so saving a null memory
 The problem is that each new memory isn’t saved until after provides a way of ‘keeping track’, and controlling
the corresponding response processing has all been done. which responses (etc.) are used and which are not.
But the action will work immediately if you insert a ‘!’, e.g.:  The advantage of using a null memory is that this
K GAME [X?] IS [phrase] can be inserted into any response without affecting
& {!Mgame [phrase]} what gets output (because, after all, it’s the null
string: it contains no characters at all).

29 30

Elizabeth 2.20, Peter Millican, July 2018 5


Using the Elizabeth Conversation Program
31 32
Changing Mood Conditional Commands
 The following script fragment makes Elizabeth get  Using null memories to keep track of the ‘state’ of the
progressively more angry at the user’s swearing (starting off conversation is the simplest kind of conditional processing.
in the ‘calm’ state, then progressing to ‘cross’ and ‘enough’;
note how ‘M\’ is used to delete all memories, and that more  You can also define conditional commands explicitly, using
than one command can be put inside the curly brackets. angle brackets to specify the relevant condition:
<[Mcalm]>: R DON’T SWEAR, PLEASE
K DAMN
K BLOODY
makes this keyword response available for use only if the
R [Mcalm] I'D RATHER YOU DIDN'T SWEAR, PLEASE memory [Mcalm] is defined
& {M\
<[Mtemper]==CALM>: R DON’T SWEAR, PLEASE
Mcross}
R [Mcross] LOOK, JUST STOP SWEARING WILL YOU! makes this keyword response available for use only if the
& {M\ memory [Mtemper] has the value ‘CALM’ (note that ‘!=’
Menough}
R [Menough] THAT'S IT! I'VE HAD ENOUGH - GO AWAY! instead of ‘==’ would check inequality rather than equality)
& {M\
O [X] => JUST GO AWAY}  For more on this, see the help sections on ‘Giving Direction to a
Mcalm Conversation’ and ‘Defining and Using Conditional Commands’.

31 32

33 34
More on Dynamic Commands Examples of Deletion Commands
 Almost any script command can be used dynamically, and  See the ‘Command Syntax Reference Guide’ (§6.1) for full
virtually all of them act identically in either case (an details of deletion commands, and for the treatment of index
codes and keyword sets as mentioned on the next slide.
exception is when you add a keyword that already exists).
V\ DON'T YOU WANT TO TALK?
 However for dynamic uses, you will need some commands  deletes this specific void input response
that you are very unlikely to use directly in a script – for N\
example the commands that delete transformations or  deletes all no-keyword responses
memories etc. (as we’ve already used above). I\ dad => father
 deletes this specific input transformation
 To test what effect a particular command will have when I\ dad
triggered dynamically, you can type it into the input box,  deletes the first input transformation whose left-hand side is ‘dad’
and then press F1 instead of Enter. K\ MOTHER
 deletes the keyword ‘MOTHER’
 For full details of all available commands, see ‘Command
K\ or K/\
Syntax Reference Guide’ (§6.1 and its subsections).  delete all keywords; ‘K/\’ deletes all the keyword sets too.

33 34

35 36
Index Codes and Keyword Sets Commands Within Commands
 One of the above examples deletes the ‘first’ input
transformation of a particular kind – when you use any such  Dynamic script commands can be ‘nested’ like this
command, the ordering is alphabetical by index code. (note how indentation is used to show the structure):
 Almost any script command can be assigned an index code when I my sister => my sister
it is created, and this will determine the order in which they are & {K MOTHER
applied and searched for, e.g.: & {N TELL ME MORE ABOUT YOUR MOTHER}
R HOW WELL DO YOUR MOTHER AND SISTER GET ON?}
I$first one => two
 defines the input transformation ‘one => two’ with index code  When the phrase ‘my sister’ is identified in the input,
‘$first’ – ‘$’ comes alphabetically before ‘0’, so this transform-
ation will be done even before the transformation coded ‘001’.
this adds a new keyword ‘MOTHER’ together with the
See the help section on ‘Alphabets’ for details of ordering. response ‘HOW WELL …’. But the keyword is also
 Keyword/response sets have index codes, and the keywords/
defined in such a way that when it is recognised and the
responses also have their own index codes. Within keyword and response given, this will trigger another action, creating
response commands, ‘@’ can be used to refer to the current a no-keyword response ‘TELL ME MORE …’ which
keyword/response set (i.e. usually, the latest to be modified). might then be invoked later in the conversation.

35 36

Elizabeth 2.20, Peter Millican, July 2018 6


Using the Elizabeth Conversation Program
37 38
Iteration, Cycling, and Recursion The Concept of Iteration
 Having now covered most of Elizabeth’s specific  The Oxford Dictionary of Computing has this to say
commands, it is time to look at the higher-level about iteration:
structures that it provides for handling repeated [Iteration is] the repetition of a numerical or non-
operations and flow of control. numerical process where the results from one or
 Three important concepts here are iteration, more stages are used to form the input to the next.
cycling, and (the most significant) recursion. Generally the recycling of the process continues until
some preset bound is achieved, or the process result
 Within Elizabeth, iteration and cycling apply only is constantly repeated.
to input and output transformations (the latter
include also ‘final’ transformations, which are  Within Elizabeth, iteration of input/output/final
explained later); recursion can apply to any kind of transformations is automatically halted when they
transformation, and is usually most powerful and cease to have any effect on the active text (i.e. where
flexible when used with keyword/response pairs. ‘the process result is constantly repeated’).

37 38

39 40
Enabling Iteration within Elizabeth Controlling Loops – the Match Limit
 To enable iteration of input transformations, open  When iteration is enabled for input transformations, this
means that every input transformation will be applied to the
the Control menu dialog box and click on the active text repeatedly until either:
‘Permit unlimited iteration’ radio button under the  the transformation stops having any effect (either because it
‘Input Transformation Control’ heading. ceases to apply to the active text, or makes no difference);
 Now create a script containing only the single input  iteration is terminated for some reason.
transformation:  Iteration will always be terminated eventually, to prevent the
system ‘hanging’. The ultimate barrier here is a match
 I TICK => TICK TOCK
algorithm limit, which keeps count of how many times the
and type as input: ‘TICK’. There will be a delay matching algorithm has been called, and prevents further
while this is processed, and the easiest way to see iteration after a certain limit (5,000 by default).
the output is to look at the ‘Dialogue’ tab.  This limiting value is set through the Control menu dialog.

39 40

41 42
The Automatic Undo Facility The Concept of Cycling
 An alternative method of controlling iteration is an  The Oxford Dictionary of Computing provides this
automatic undo facility, which works on the basis: definition of the relevant sense of the word ‘cycle’:
 that any transformation which iterates 10 or more [A cycle is] any set of operations that is repeated
times is ‘non-terminating’; regularly and in the same sequence. The operations
 that any non-terminating transformation should be may be subject to variations on each repetition.
applied once only.
 Within Elizabeth, cycling of input/output/final
 To enable the automatic undo facility, un-check the transformations is subject to the same sorts of limits
‘Permit Recursion, Text Splitting and …’ box in the that apply to iteration; so for example cycling is
Control menu dialog. This is necessary because (to automatically halted when the cycle of operations
avoid control flow conflicts) the automatic undo is ceases to have any effect on the active text.
not available when recursion is enabled.

41 42

Elizabeth 2.20, Peter Millican, July 2018 7


Using the Elizabeth Conversation Program
43 44
Iteration and Cycling Enabling Cycling within Elizabeth
 To appreciate the difference between iteration and  To enable cycling of input transformations, open
cycling, first create a script containing only the two the Control menu dialog box and click on the
input transformations: ‘Permit unlimited cycling’ radio button under the
 I TICK => TOCK ‘Input Transformation Cycling’ heading.
 I TOCK => TICK TACK
 If you do this and then again give the input ‘TICK’
and type as input: ‘TICK’.
to the transformations:
 With iteration enabled but not cycling, the output will  I TICK => TOCK
be ‘TICK TACK’, each transformation having been
 I TOCK => TICK TACK
applied once. Note that the left-hand side of each does
not match its right-hand side, so neither of them can be you will find that the output is much longer, like the
repeatedly applied to its own output. output you got earlier with unlimited iteration.

43 44

45 46
Controlling Cycling Recursion
 Exactly as with iteration, there are two different ways  Recursion is a hugely important concept in
of preventing infinite loops arising from cycling: Computing generally, and especially in Artificial
Intelligence. The Oxford Dictionary of Computing
 Further cycling will always be prevented eventually,
provides defines recursion as:
once the match algorithm limit is exceeded.
The process of defining or expressing a function,
 If recursion is disabled, it is possible to select the procedure, language construct, or the solution to a
automatic undo facility, which works on the basis: problem in terms of itself, so producing a recursive
 that any set of transformations which cycles 10 or more times function, a recursive procedure etc.
(this number is adjustable) is ‘non-terminating’;
 that any non-terminating set of transformations should be  Within Elizabeth, the ‘problem’ is the generation of
applied once only, so further applications should be ‘undone’. appropriate output, and a recursive solution is one in
 As in the case of iteration, the automatic undo facility for which the overall solution is created by ‘feeding
cycling is accessible through the Control menu dialog. back’ partial solutions into the system.

45 46

47 48
Recursion in Elizabeth Recursion and Final Transformations
 Any text in curly braces on the right-hand side of an input/  In the previous example, the input is split into
output/final transformation rule, or in a keyword response, individual words, and each word is then processed
will be recursed – fed back into Elizabeth as if it was input:
separately – through the full input/keyword/output
K [word1] [phrase1] Input of: sequence – before the results of this individual
R {[word1]} {[phrase1]}
K 1 1 2 2 1 2 processing are recombined in the output.
R ONE will yield output of
K 2
ONE TWO TWO ONE TWO
 Final transformations are a special kind of output
R TWO
transformation, differing from the standard kind in
being applied after recombining has taken place.
 Here the first word in each input is separated from the
remainder, and both are recursed in turn. Each single word  To explore recursion further, with more complex
fails to match with the first keyword, and so ‘falls through’ examples, see ‘Recursion and Text Splitting’
to be caught by one of the other keywords and replaced. (§3.2) and ‘The Power of Recursion’ (§3.3).

47 48

Elizabeth 2.20, Peter Millican, July 2018 8


Using the Elizabeth Conversation Program
49 50
APPENDIX 1: Syntactic Analysis A Testbed: Simple Transformations
 The ELIZA method of simple pattern-matching and  A good testbed for Elizabeth’s potential for
pre-formed responses may sometimes be able to handling syntactic structure is the attempt to
generate the illusion of ‘intelligent’ language generate simple grammatical transformations.
processing, and even in some cases (e.g. a computer  A transformation is a change in structure which
help system) provide the basis for a useful tool. alters the ‘surface’ form of the sentence (so the
 However to get anywhere near genuine NLP words are different, or in a different order), but
(natural language processing), Elizabeth needs to do without significantly altering its ‘propositional
more than pattern-match – it must be responsive to content’ (i.e. what ‘facts’ are in question; what the
the structure of sentences, and react not just sentence ‘says’ about what or whom).
according to the literal word strings they contain,  Transformations played a major and controversial
but how these words are put together – their syntax. role in the rise of Chomskyan linguistics, but their
value as a useful testbed is independent of all that.

49 50

51 52
Our Starting Point: Some Types of Transformation (1):
Active Declarative Sentences Active to Passive
 We start from straightforward active declarative
sentences, such as:  Most types of transformation are easier to grasp by
 John chases the cat example than explanation:
 The white rabbits bit a black dog  Active to Passive
 You like her  ‘John chases the cat’ becomes
 Declarative simply means that these sentences ‘The cat is chased by John’
purport to state (‘declare’) facts – they are not  ‘The white rabbits bit a black dog’ becomes
questions or commands, for example. ‘A black dog was bitten by the white rabbits’
 Here we shall stick to very simple word categories  ‘You like her’ becomes
and grammatical constructs. ‘She is liked by you’

51 52

53 54
(2): Yes/No Questions (3): Tag Questions
 These transform the sentence into a question with a  A Tag Question is appended to the end of a sentence, to ask
simple yes/no answer: for confirmation or to give emphasis to what was said:
 ‘John chases the cat’ becomes  ‘John chases the cat’ becomes
‘Does John chase the cat?’ ‘John chases the cat, doesn’t he?’
 ‘You like her’ becomes  ‘The white rabbits bit a black dog’ becomes
‘The white rabbits bit a black dog, didn’t they?’
‘Do you like her?’
 ‘You like her’ becomes
 They can also be applied to passive sentences, ‘You like her, don’t you?’
though here they’re a bit more complicated:
 These provide an excellent test case, because a tag question
 ‘A black dog was bitten by the white rabbits’ becomes must agree with the sentence in number (singular or plural),
‘Was a black dog bitten by the white rabbits?’ person (first person, second, third), gender (masculine,
feminine, neuter), and tense (past, present, future).

53 54

Elizabeth 2.20, Peter Millican, July 2018 9


Using the Elizabeth Conversation Program
55 56
Phrase Structure Grammar (1) Phrase Structure Grammar (2)
 A common method of syntactic analysis is to break  The rule that a sentence can be made up of a noun
down a sentence into hierarchical components using phrase followed by a verb phrase is represented as:
a phrase structure grammar. (Note that here we S  NP VP
shall be looking at only a tiny and highly simplified  In the examples we’ve seen, a noun phrase can be
fragment of English, so don’t take the rules used made up in three ways: (a) a single noun or
here to be absolutely correct or complete!) pronoun (e.g. ‘John’, ‘it’); (b) a determiner (or
 All of the basic sentences we shall be examining ‘article’) followed by a noun (e.g. ‘the rabbits’, ‘a
consist of a noun phrase followed by a verb phrase. dog’); (c) a determiner followed by an adjective
Crudely, the noun phrase specifies the subject of the followed by a noun (e.g. ‘the white rabbits’). So:
sentence, e.g. ‘John’, ‘the white rabbits’, ‘you’. The NP  N
verb phrase specifies what the subject does (or did, NP  D N
or will do), e.g. ‘chases the cat’, ‘like her’. NP  D ADJ N

55 56

57 58
Phrase Structure Grammar (3) Phrase Structure Rules in Elizabeth
 Finally, a verb phrase typically consists of a verb followed by  The phrase structure rules above can be reversed and then
a noun phrase, e.g. ‘chases …’, ‘bit …’, where the ‘…’ is translated into Elizabeth input transformations suitable for
some noun phrase. So we have: analysing a sentence into its structural constituents:
VP  V NP NP  D N
(We assume here that the verb is a transitive verb: one that has an I (d:[b1]) (n:[b2]) => (np:(D:[b1]) (N:[b2]))
object as well as a subject. Where a verb is intransitive, the verb VP  V NP
phrase can consist of just the verb, e.g. ‘sleeps’, while many verbs I (v:[b1]) (np:[b2]) => (vp:(V:[b1]) (NP:[b2]))
can be either transitive or intransitive, e.g. ‘eats’.)
S  NP VP
 As we shall see, a set of rules like this can provide a powerful I (np:[b1]) (vp:[b2]) => (s: (NP:[b1]) (VP:[b2]))
technique for analysing a sentence into its structural
components, and Elizabeth can help here.  Note here that a ‘[b…]’ pattern can match anything at all,
as long as it contains matching brackets. This ensures that
 See the Elizabeth help on ‘Implementing Grammatical Rules’
the sentence structure is recorded by the ‘nested’ brackets,
for more discussion and examples of these techniques.
and that the processing respects this structure.

57 58

59 60

 Obviously we also need to specify the categories (noun,  Having used the input transformations to analyse the sentence into
verb etc) for the various words. We might end up with a set its constituent structure, we can then apply keyword
transformations to alter that structure, e.g. from active to passive:
of input transformations like this: K (s:(NP:[b1]) (VP:[b2]))
I the => (d:THE) R (s:(VP:[b2] passive) (NP:[b1]))

I dog => (n:DOG)  Then output transformations can be used to decompose the
I cat => (n:CAT) sentence structure back into its parts:
O (s:(VP:[b1] passive) (NP:[b2])) => (vp:[b1] passive)(np:[b2])
I chases => (v:CHASES)
O (vp:(V:[b1]) (NP:[b2]) passive) => (np:[b2])(v:[b1] passive)
I (d:[b1]) (n:[b2]) => (np:(D:[b1]) (N:[b2])) O (np:(D:[b1]) (N:[b2])) => (d:[b1]) (n:[b2])
O (v:CHASES passive) => IS CHASED BY
I (v:[b1]) (np:[b2]) => (vp:(V:[b1]) (NP:[b2]))
O (d:[b1]) => [b1]
I (np:[b1]) (vp:[b2]) => (s: (NP:[b1]) (VP:[b2])) O (n:[b1]) => [b1]

 If we then input the sentence:  If we then input the sentence:


the dog chases the cat the dog chases the cat
the input transformations will convert this into: the output will have been ‘translated’ into the passive form:
(s: (NP:(D:THE)(N:DOG)) (VP:(V:CHASES) (NP:(D:THE)(N:CAT))))
the cat is chased by the dog

59 60

Elizabeth 2.20, Peter Millican, July 2018 10


Using the Elizabeth Conversation Program
61 62
APPENDIX 2: Propositional Logic Binary Propositional Connectives
 A proposition is a statement that some determinate  A binary propositional connective joins two proposi-
state of affairs is (or is not) the case, e.g. ‘Grass is tions together to make a third (complex) proposition.
not white’, ‘Politicians are always liars’, ‘1+1=23’,  Such connectives in English include ‘and’, ‘because’,
or ‘Pigs can fly’. Questions and exclamations are ‘but’, ‘if’, ‘implies’, ‘nevertheless’, ‘only if’, ‘or’,
not propositions, and it is convenient to restrict our ‘suggests that’, ‘unless’.
attention to statements that avoid any ambiguity.  ‘Snow is white’ and ‘the moon is cheese’ are atomic
 Propositional logic deals with reasoning whose logic propositions (i.e. they’re not themselves made up of
is analysable entirely in terms of whole propositions. other propositions). Using the connectives, we get:
This does not include reasoning that depends on  Snow is white and the moon is cheese
propositions’ internal structure, e.g. ‘Socrates is a  Snow is white because the moon is cheese
man. All men are mortal. Therefore Socrates is  Snow is white but the moon is cheese
mortal.’ (This argument requires Predicate Logic.)  Snow is white if the moon is cheese (etc.)

61 62

63 64
Truth-Functionality Translating English Connectives
 A connective # is truth-functional if knowing the
 Testing arguments using propositional logic requires
truth or falsity of P and Q always gives you enough
information to know the truth of falsity of (P # Q). that all connectives be interpreted truth-functionally:
 Translate ‘but’, ‘nevertheless’, ‘because’ as and.
 ‘And’, ‘or’ are usually treated truth-functionally:
 Translate ‘unless’ as or.
(P and Q) (P or Q)
 Translate ‘if P then Q’, ‘Q if P’, ‘only if Q then P’, ‘P
P true Q true true true
P true Q false false true only if Q’ as implies, interpreted like this:
P false Q true false true (P implies Q)
P false Q false false false P true Q true true
 But real English isn’t so simple, e.g. ‘He hit me and P true Q false false
I swore at him’ gives a different impression from ‘I P false Q true true
swore at him and he hit me’. P false Q false true

63 64

65 66
Negating a Proposition Consistency and Inconsistency
 The negation (or contradictory) of a proposition is  A set of propositions is consistent if it is logically
that proposition which denies exactly what the first possible for all of them to be true together, e.g.
asserts (and therefore asserts exactly what the first { The moon is inhabited by spiders ,
denies). So if P is true, its negation – not(P) – must Some man can jump over 100 metres ,
be false, and if P is false, not(P) must be true, e.g.: Examinations are tremendous fun }
P: Snow is white
 A set of propositions is inconsistent if it is not logic-
not(P): Snow is not white (not ‘Snow is green’)
ally possible for them all to be true together, e.g.
Q: All cows eat grass
{ No cow eats aubergines ,
not(Q): Some cow (or cows) doesn’t eat grass
Daisy is a cow ,
(not ‘No cows eat grass’)
Daisy eats aubergines }
 Thus not is a unary truth-functional connective.

65 66

Elizabeth 2.20, Peter Millican, July 2018 11


Using the Elizabeth Conversation Program
67 68
Arguments and Validity The Resolution Rule
 An argument, as the man in Monty Python’s Argument  Suppose these premisses are known to be true:
Sketch says, is ‘a connected series of statements P or Q not(P) or R
intended to establish a proposition’. The ‘statements’ P must of course be either true or false. If P is false,
[propositions] from which it starts are called its then Q must be true (from the first premiss), but if P is
premisses, and the proposition which it is intended to true, then R must be true (from the second premiss).
establish is called its conclusion. So from these two premisses we can conclude:
 An argument is valid if the truth of the premisses Q or R
guarantees the truth of the conclusion – that is, if the
 This is an application of the rule of resolution. In
premisses are true, the conclusion must be true too.
general, this rule lets us move from:
 This is the same as saying that an argument is valid if
[A] or P or [B] [C] or not(P) or [D]
the set consisting of the premisses, together with the
negation of the conclusion, is an inconsistent set. to [A] or [B] or [C] or [D]

67 68

69 70
Clausal Form Testing Validity by Resolution Refutation
 A literal is either an atomic proposition – a simple  To test an argument for validity using resolution:
proposition we can represent as ‘P’ – or else the 1. Formalise the propositions of the argument as atomic
negation of an atomic proposition, e.g. ‘not(P)’. propositions linked by truth-functional connectives;
2. Take the (formalised) premisses of the argument
 Resolution works on clauses: formulae consisting together with the negation of the conclusion – we
of sequences of literals joined by ‘or’. We can aim to test whether this set of propositions is
simplify the representation of such formulae, e.g. inconsistent (if it is inconsistent, then the argument is
by using ‘<P>’ (with angle brackets) to mean valid);
‘not(P)’, and using commas instead of ‘or’s. 3. Convert all of the propositions in the set into clausal
form (we’ll see how to do this soon);
 Treated like this, ‘not(P) or Q or R’ 4. Apply the resolution rule again and again until either
becomes: ‘<P>, Q, R’ you can resolve P against not(P) to get ‘NIL’ (i.e. a
contradiction – the argument’s valid) or you give up.

69 70

71 72
Converting Formulae into Clausal Form  If any ‘and’ remains, it should lie between
independent clauses which we can list separately, so
 Remove all ‘implies’ using the equivalence:
we finish up with a straightforward list of such
A implies B  (not(A) or B)
clauses, each consisting purely of ‘ored’ literals.
 If at any stage a ‘double negation’ is produced,
replace it with an unnegated formula:  The help file section ‘Implementing Propositional
not(not(A))  A
Logic’ provides an argument to illustrate all this:
 ‘Push the nots inwards’ using the identities: G implies (O and B) not(G) or O
not(G) or B
not(A or B)  (not(A) and not(B))
B implies T not(B) or T
not(A and B)  (not(A) or not(B))
(O and T) implies not(E) not(O) or not(T) or not(E)
 If any ‘and’ is left within the scope of an ‘or’,
E E
remove it using the identity: ____________________
A or (B and C)  (A or B) and (A or C) therefore not(G) G (negated conclusion)

71 72

Elizabeth 2.20, Peter Millican, July 2018 12

You might also like