Elizabeth Handout
Elizabeth Handout
1 2
Obtaining the Software
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
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
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
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
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
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
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
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
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
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]
59 60
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
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