Ling/CSE 472 Assignment 1:
Regular expressions
Elizalike
This assignment asks you to create a program that behaves like
Weizenbaum's ELIZA (see Ch 2 of J&M).
We have provided a skeleton of a
script that handles input and output, and provides an example of the Python
syntax for using regular expressions to modify strings.
Each student should develop their own program, although you are welcome to ask
each other questions (in person, over email, or on the Canvas discussion area).
You will need to find a partner for this project, as one of the tasks is to
test each other's programs (see below).
Specifications:
The basic approach is to read in a string of input from the user, modifying it
successively (sometimes subtly, sometimes drastically, depending on the input
string), and print out the result. To maintain the illusion of a competent conversational partner, it is
crucial that elizalike print out grammatical strings. (You may assume that it
is given grammatical input.) Furthermore, elizalike should be able to handle
person deixis, referring to itself in the first person and to the user in the
second person.
Before you start, look at the list of items to turn in
below, so you know what you'll need to save.
Your tasks:
- Develop a list of sentences that you will use to test your program to make sure
it handles the person deixis correctly.
- This list must illustrate all ways in which
1st and 2nd person are marked in English. To be clear, this means that you must include
all 1st and 2nd person pronouns, all 1st and 2nd person subject-verb pairs with the
verb be and all possible forms of the verb.
- Optionally, properly capitalize and punctuate
your test sentences. You can also just output all lower- or all uppercase. (Do not output randomly capitalized things though).
-
The thoroughness of the coverage of these sentences will be a significant part
of the grade for this assignment.
- You need to add these sentences, the expected
responses, and a comment indicating what is being tested, to the
file sentences.txt. Carefully follow the format
described in the file.
- Modify the elizalike script to implement the handling of
person deixis.
- Here's the starting version of the python script
- The basic strategy is to first replace any second person
reference in the input with some string that's unlikely to show up otherwise.
(The sample expression in the script we've given you
replaces it with third-person reference to Eliza). Then replace
any first person reference in the input with second person reference. Finally,
replace your otherwise unlikely string (from the first step) with first person
reference. Each of these steps will take several lines as you handle pronouns and
verbs and upper and lower case letters (i.e., if the user types "My friend..."
Elizalike's output should be "Your friend..." and not "your friend...").
- Be sure to read all of the comments in the file (lines starting with #, which
are for human consumption and ignored by Python). You should probably test each
line as you add it, by running the program again and using an appropriate
sentence from your test file. Note that before you make any changes, the
program runs, just in a boring way: It repeats whatever the user types in,
except that it changes all occurrences of "you are" to "---Eliza-is---".
-
Add at least two statements that find one keyword in the input and change the
whole string to something different. (See the third and fourth examples at the bottom of page
10 of JM Ch2 for a model, but don't copy them exactly!)
-
Add at least two statements that find some keyword in the input, and return a
significantly changed output that noneless contains some part of the input that
may vary from time to time. (See the first and second examples on page 10, but
feel free to get fancier than that!)
- This is the first version of your program. It should be turned in as elizalike1.py (others).
-
Find a partner and exchange programs. Looking at the code for your partner's
program, try to find at least 2 interestingly different inputs that cause their
program to produce ungrammatical output. (Keep your inputs grammatical!) We're
pretty sure you'll be able to find these, but if your partner's program is too
perfect, you can get full credit for this part of the assignment by turning in
an explanation of 5 pitfalls you looked for and how they were avoided.
-
Optional: Modify your program to avoid the ungrammatical outputs your partner found (if
any). Document and explain the changes you made at the end of your write-up file.
- Write up Part I: In ~5 paragraphs, discuss:
- What did you learn about English morphosyntax or what knowledge of English morphosyntax did you apply in this assignment?
- In what ways does English morphosyntax make this program relatively straightforward to implement and how might this process be more complicated with another language?
- What did you learn about regular expressions? What are some pros and cons of using regular expressions to model and/or process language?
- Write up Part II: In ~2 paragraphs, answer:
- Describe of a use case for chatbots in the real world (this
could be a real instance you've already encountered or something
you make up).
- What are the beneficial aspects of deploying chatbots in this way, and who
receives the benefits of such use?
- Imagine that a person is fooled by the chatbot into thinking they're interacting
with a real person rather than a computer. What are some potential consequences if this happens?
Turn in instructions
Turn in the following via Canvas. Submit these files, with these names:
File | Contents |
sentences.txt |
Your list of test sentences |
elizalike1.py |
The first version of your program |
elizalike2.py |
The second version of your program. |
eliza_discussion.pdf |
Your discussion of English and other language morphology and syntax --- see the
last task above. |
partner.pdf |
1. The name of your partner and the problems you found with their program, or an
explanation of how they avoided 5 pitfalls you thought up.
2. Optional: What you changed in your own program to address the issues your partner brought up. |
chatbots.pdf |
Your answers to Write up Part II |
Note: We will be executing your code, so make sure it runs on Patas.