Python Turing Test - Creating a chatting robot (Chat bot)
Chat bot tutorial
Like this lesson? Share it with your followers by clicking on the image below.
Suggested time: 60 mins
Learning Objectives:
- Understand and use sequence in an algorithm
- Understand and use iteration in an algorithm (FOR and WHILE loops)
- Understand and use selection in an algorithm (IF, Else and Else if)
- Understand why it is so difficult to create a computer that can seemingly think for itself
Curriculum Mapping:
KS2:
- Design, write and debug programs that accomplish specific goals; solve problems by breaking them into smaller parts. Select, use and combine a variety of software on a range of digital devices to design and create a range of programs.
- Use sequence, selection and repetition in programs; work with variables and various forms of input and output
- Use logical reasoning to explain how some simple algorithms work; detect and correct errors in algorithms and programs
KS3:
- Use two or more programming languages, at least one of which is textual, to solve a variety of computational problems.
STUDENT: COMPUTATIONAL THINKER:
- 5a: Students break problems into component parts, extract key information, and develop descriptive models to understand complex systems or facilitate problem-solving.
- 5c: Students break problems into component parts, extract key information, and develop descriptive models to understand complex systems or facilitate problem-solving.
- 5d: Students understand how automation works and use algorithmic thinking to develop a sequence of steps to create and test automated solutions.
EDUCATOR: COMPUTATIONAL THINKING COMPETENCIES:
- 4b: Design authentic learning activities that ask students to leverage a design process to solve problems with awareness of technical and human constraints and defend their design choices.
COMPUTER SCIENCE EDUCATORS:
- 2a: Plan and teach computer science lessons/units using effective and engaging practices and methodologies:
i. Select a variety of real-world computing problems and project-based methodologies that support active and authentic learning and provide opportunities for creative and innovative thinking and problem solving
ii. Demonstrate the use of a variety of collaborative groupings in lesson plans/units and assessments
iii. Design activities that require students to effectively describe computing artifacts and communicate results using multiple forms of media
iv. Develop lessons and methods that engage and empower learners from diverse cultural and linguistic backgrounds
v. Identify problematic concepts and constructs in computer science and appropriate strategies to address them
vi. Design and implement developmentally appropriate learning opportunities supporting the diverse needs of all learners
vii. Create and implement multiple forms of assessment and use resulting data to capture student learning, provide remediation and shape classroom instruction
CSTA K–12 CS Standards:
- 1B-AP-08: Compare and refine multiple algorithms for the same task and determine which is the most appropriate.
- 1B-AP-09: Create programs that use variables to store and modify data.
- 1B-AP-10: Create programs that include sequences, events, loops, and conditionals.
- 1B-AP-11: Decompose (break down) problems into smaller, manageable subproblems to facilitate the program development process.
- 1B-AP-13: Use an iterative process to plan the development of a program by including others' perspectives and considering user preferences.
- 1B-AP-15: Test and debug (identify and fix errors) a program or algorithm to ensure it runs as intended.
- 1B-AP-17: Describe choices made during program development using code comments, presentations, and demonstrations.
- 2-AP-11: Create clearly named variables that represent different data types and perform operations on their values
- 2-AP-12: Design and iteratively develop programs that combine control structures, including nested loops and compound conditionals.
- 2-AP-15: Seek and incorporate feedback from team members and users to refine a solution that meets user needs.
- 2-AP-16: Incorporate existing code, media, and libraries into original programs, and give attribution.
- 2-AP-17: Systematically test and refine programs using a range of test cases.
- 3A-AP-14: Use lists to simplify solutions, generalizing computational problems instead of repeatedly using simple variables.
- 3A-AP-15: Justify the selection of specific control structures when tradeoffs involve implementation, readability, and program performance, and explain the benefits and drawbacks of choices made.
AREA OF LEARNING AND EXPERIENCE: Science and Technology:
Computation is the foundation for our digital world.
Progression step 3
- I can use conditional statements to add control and decision-making to algorithms.
- I can identify repeating patterns and use loops to make my algorithms more concise.
- I can explain and debug algorithms.
Progression step 4
- I can decompose given problems and select appropriate constructs to express solutions in a variety of environments.
- I can select and use data structures that efficiently manage data in algorithms.
- I can plan and implement test strategies to identify errors in programs.
Progression step 5
- I can identify, define and decompose problems, choose appropriate constructs and express solutions in a variety of environments.
- I can use file-handling techniques to manipulate data in algorithms.
- I can test, evaluate and improve a solution in software.
Can computers think? This was a question posed by computer pioneer and artificial intelligence (AI) theorist, Alan Turing. Turing proposed that, given time, a computer with sufficient computational power would acquire the abilities to rival human intelligence. In order to test his theory, Turing devised a test.
The Turing Test was based on a Victorian parlour game in which a judge (or interrogator) asks a series of questions to a man and a woman in a separate room. By reading a series of typed answers, the judge must determine which replies were from the man and which were from the woman.
Turing adapted the test by replacing the woman with a computer - the aim being to decide whether the answers were from a man or computer thus determining if a computer was able to think for itself.
To find out more about Alan Turing and the Turing Test, click on the links below:
- http://www.turing.org.uk - Online biography about Alan Turing
- http://en.wikipedia.org/wiki/Alan_Turing - Alan Turing wikipedia page
- http://www.bbc.co.uk/history/people/alan_turing - BBC History: Alan Turing
- http://en.wikipedia.org/wiki/Turing_test - The Turing Test wikipedia page
- http://www.turing.org.uk/scrapbook/test.html - Alan Turing Scrapbook: The Turing Test
In this brief introduction to programming using Python, students are going to create a chatting robot (chat bot) designed to confuse the user into thinking that they are talking to a real person.
Starter:
Show the video “Project Natal – Milo demo”. At the end of the video explain to students that for years, science fiction writers and filmmakers have dreamed about robots that can think for themselves however, despite giant leaps in technology, this dream is still far from reality. Explain to students that to explore the reasons why it is so difficult to make a thinking robot, they are going to create their very own chatting robot (chat bot).
Direct students to one of the online chat bots listed below. Instruct students to ask the chat bots a series questions and note down any unusual or unexpected answers.
Note: Some online chat-bots learn from previous conversations. As a result, there may be some cases where what the chat bot says may be deemed as inappropriate. Use these sites at your own risk. TeachwithICT.weebly.com is not responsible for the content of external Internet sites.
Online chat bots:
- Evie (recommended!) - http://www.existor.com
- Jabberwacky - http://www.jabberwacky.com
- Brain Bot - http://www.botlibre.com/chat.jsp
- SkyNet Ai - http://home.comcast.net/~chatterbot/bots/AI/SkynetV5/
- Clever Bot - http://www.cleverbot.com
After a few minutes, stop the class and ask them to feedback their findings to the rest of the class.
Note down some of the students’ findings and ask the students why they think the chat bot could not answer all of their questions.
Ask the students why you think it is so hard to make a computer appear as if it able to think like a human. Try to draw out answers such as “Computers can only follow a given sequence of instructions” or “Computers can only respond to questions they have been programmed to answer” – give students prompts where necessary.
Explain to students about the Turing Test (insert link to wikipedia) and discuss the concept of Artificial Intelligence (AI). Finally, inform students that they are going to create a chatting robot (chat bot) and that there will be a prize for the most convincing robot (the prize is optional).
In order for the chat bot to work, the students will need to import the time and random libraries. Instruct students to type in the following code:
import time
import random |
name = input("Hello, what is your name? ")
|
time.sleep(2)
|
print("Hello " + name)
|
feeling = input("How are you today? ")
time.sleep(2) |
if "good" in feeling:
print("I'm feeling good too!") else: print("I'm sorry to hear that!") |
First, ask students to add an input() asking the user to enter their favourite colour (remembering to add a natural pause):
time.sleep(2)
favcolour = input("What is your favourite colour? ") |
colours = ["Red","Green","Blue"]
|
time.sleep(2)
print("My favourite colour is " + random.choice(colours)) |
- There is a problem with the code. The code in Python is case sensitive therefore, if we were to type in "Good" (Uppercase G) instead of "good" in response to the question "How are you feeling?" Python will not find a match and will therefore reply with "I'm sorry to hear that!". In order to get around this problem, we can convert the users reply to lower case using the `lower()` command. Instruct students to modify their code as follows:
if "good" in feeling.lower():
print("I'm feeling good too!") |
- At the moment, we only have two responses to the question "How are you feeling?" Challenge students to add some more responses to make the chat bot appear more realistic. For example:
feeling = input("How are you today? ")
if "good" in feeling: print("I'm feeling good too!") elif "awesome" in feeling: print("I'm feeling awesome too!") else: print("I'm sorry to hear that!") |
- Add some more questions and responses
- Comment their code explaining how it works.
- Add a random pause between each question and answer:
time.sleep(random.randrange(5))
|
Direct students to swap places with a partner or person next to them and try out their chat bot. Instruct the students to leave a comment in their partner’s code suggesting at least one improvement. After a few minutes, ask the students to return to their seats and make any suggested improvements.
As an extra incentive, you could offer a prize for the most convincing chat bot (almost like a mini Loebner Prize - http://en.wikipedia.org/wiki/Loebner_Prize) However, rather than rewarding the students with $6,000 for creating the most convincing chat bot, I suggest some chocolate instead!
Homework:
Students can continue to work on their chat bot and publish their script when they have finished.
Example solution
|
|
New Tutorial
Unless otherwise specified, everything in this repository is covered by the following licence:
Based on a work at https://github.com/raspberrypilearning/turing-test-lessons