Name: Magpie Chatbot Lab: Student Guide. Introduction

Similar documents
AP Computer Science A Magpie Chatbot Lab Student Guide

Activity 3: Better Keyword Detection Prepare Exploration: Using the API

6.001 Notes: Section 15.1

Implementing Some Foundations for a Computer-Grounded AI

Unit 9 Tech savvy? Tech support. 1 I have no idea why... Lesson A. A Unscramble the questions. Do you know which battery I should buy?

Python Boot Camp. Day 3

Due: Tuesday 29 November by 11:00pm Worth: 8%

Digital Marketing Manager, Marketing Manager, Agency Owner. Bachelors in Marketing, Advertising, Communications, or equivalent experience

ISY00245 Principles of Programming. Module 7

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n)

Introduction to Scratch

RIS shading Series #2 Meet The Plugins

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

************ THIS PROGRAM IS NOT ELIGIBLE FOR LATE SUBMISSION. ALL SUBMISSIONS MUST BE RECEIVED BY THE DUE DATE/TIME INDICATED ABOVE HERE

The first program: Little Crab

Part 2: The Material PART 2

Have the students look at the editor on their computers. Refer to overhead projector as necessary.

Intro. Scheme Basics. scm> 5 5. scm>

Taking Control of Your . Terry Stewart Lowell Williamson AHS Computing Monday, March 20, 2006

Programming Lab 1 (JS Hwk 3) Due Thursday, April 28

Lesson Share TEACHER'S NOTES LESSON SHARE. ing by Olya Sergeeva. Overview. Preparation. Procedure

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 10: OCT. 6TH INSTRUCTOR: JIAYIN WANG

Write for your audience

Lesson 3 Transcript: Part 1 of 2 - Tools & Scripting

15 Minute Traffic Formula. Contents HOW TO GET MORE TRAFFIC IN 15 MINUTES WITH SEO... 3

Improving the crab: more sophisticated programming

Exercise 1 Using Boolean variables, incorporating JavaScript code into your HTML webpage and using the document object

CSCI 141 Computer Programming I. Filip Jagodzinski

(Refer Slide Time: 05:25)

Microsoft PowerPoint Presentations

Yup, left blank on purpose. You can use it to draw whatever you want :-)

CpSc 111 Lab 5 Conditional Statements, Loops, the Math Library, and Redirecting Input

Notes from the Boards Set BN19 Page

Expressions and Casting. Data Manipulation. Simple Program 11/5/2013

QUIZ Friends class Y;

JS Lab 1: (Due Thurs, April 27)

QUICK EXCEL TUTORIAL. The Very Basics

From video conversation 2. This is a gap fill exercise and can be used as either a quiz/test of

CHIPS Newsletter Vol 5 - Yahoo! Mail. Official Newsletter of

Endless Monetization

Expressions and Casting

Improving the Crab more sophisticated programming

COPYRIGHTED MATERIAL. Starting Strong with Visual C# 2005 Express Edition

CLIENT ONBOARDING PLAN & SCRIPT

CLIENT ONBOARDING PLAN & SCRIPT

EUROPEAN KANGOUROU LINGUISTICS ENGLISH-LEVELS 3-4. Linguistic ENGLISH. LEVEL: 3 4 (Γ - Δ Δημοτικού)

Chapter 1 Operations With Numbers

Creating objects TOPIC 3 INTRODUCTION TO PROGRAMMING. Making things to program with.

EXPERIMENTS IN COMPUTER SCIENCE

Fundamentals of Object Oriented Programming

10 Tips For Effective Content

Foundations, Reasoning About Algorithms, and Design By Contract CMPSC 122

(Refer Slide Time: 01:25)

St. Edmund Preparatory High School Brooklyn, NY

Library Website Migration and Chat Functionality/Aesthetics Study February 2013

Oracle Cloud. Content and Experience Cloud ios Mobile Help E

C++ Style Guide. 1.0 General. 2.0 Visual Layout. 3.0 Indentation and Whitespace

Lesson 1. Introduction to Programming OBJECTIVES

Introduction to Counting, Some Basic Principles

4. Java Project Design, Input Methods

(0) introduction to the course. how to learn a programming language. (0) course structure

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi.

Magical Chatbots with Cisco Spark and IBM Watson

CMPSCI 187 / Spring 2015 Implementing Sets Using Linked Lists

CS Programming Exercise:

CSE 143 Lecture 10. Recursion

2SKILL. Variables Lesson 6. Remembering numbers (and other stuff)...

Creating An Account With Outlook

Boolean Expressions. Is Equal and Is Not Equal

Website/Blog Admin Using WordPress

VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs.

Aesop QuickStart Guide for Substitutes

HOUR 4 Understanding Events

UNIT 13B AI: Natural Language Processing. Announcement (1)

First order logic (Ch. 8)

Client Code - the code that uses the classes under discussion. Coupling - code in one module depends on code in another module

Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02

Java Programming Fundamentals - Day Instructor: Jason Yoon Website:

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

Let them check their answers against a complete version of the worksheet or by listening to you reading it all out.

Game keystrokes or Calculates how fast and moves a cartoon Joystick movements how far to move a cartoon figure on screen figure on screen

Helping the Compiler Help You. Thomas Dy

Oracle Cloud. Content and Experience Cloud Android Mobile Help E

Project 2: Eliza Due: 7:00 PM, Nov 3, 2017

Grade 6 Math Circles Fall Oct. 21/22 Algebra - Solving Equations

Crowdfunding Templates Samples (customize to fit your own project)

Where The Objects Roam

Very simple programming, limited exposure to assignment and variables minutes, or a full lesson with extension exercises

MITOCW watch?v=se4p7ivcune

Try typing the following in the Python shell and press return after each calculation. Write the answer the program displays next to the sums below.

Using Search Connectors

LABORATORY. 16 Databases OBJECTIVE REFERENCES. Write simple SQL queries using the Simple SQL app.

Exercise 6 - Addressing a Message

CSCI 355 Lab #2 Spring 2007

EL Civics Obj 48 (Online Communication) Level: Intermediate High - Advanced Task 1: Identify Internet Uses & Communication Techniques

Outline. Turtles. Creating objects. Turtles. Turtles in Java 1/27/2011 TOPIC 3 INTRODUCTION TO PROGRAMMING. Making things to program with.

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Introduction to Programming

Hey there, I m (name) and today I m gonna talk to you about rate of change and slope.

Transcription:

Magpie Chatbot Lab: Student Guide Introduction From Eliza in the 1960s to Siri and Watson today, the idea of talking to computers in natural language has fascinated people. More and more, computer programs allow people to interact with them by typing English sentences. The field of computer science that addresses how computers can understand human language is called Natural Language Processing (NLP). NLP is a field that attempts to have computers understand natural (i.e., human) language. There are many exciting breakthroughs in the field. While NLP is a complicated field, it is fairly easy to create a simple program to respond to English sentences. For this lab, you will explore some of the basics of NLP. As you explore this, you will work with a variety of methods of the String class and practice using the if statement. You will trace a complicated method to find words in user input. 1

Activity 1: Getting Acquainted with Chatbots Chatbots are programs that are designed to respond like humans to natural language input. Before you write code to create your own chatbot, you will explore some existing chatbots. Start Go to http://sites.google.com/site/webtoolsbox/bots. Try out several of the chatbots and find one to use for this activity. Exploration Have several conversations with your chatbot and answer the following questions: How does it respond to where do you come from? What is the most interesting response? What is the most peculiar response? How does it respond to asdfghjkl;? Exercises 1. Work with your partner and have two different chatbots converse with each other. Questions Simple chatbots act by looking for key words or phrases and responding to them. 1. Can you identify keywords to which your chatbot responds? 2. Think of several keywords and the responses they might cause. 2

Activity 2: Introduction to the Magpie Class In this activity, you will work Magpie, with a simple implementation of a chatbot. You will see how it works with some keywords and add keywords of your own. Start Get to know the Magpie class. Run it, using the instructions provided by your teacher. How does it respond to: My mother and I talked last night. I said no! The weather is nice. Do you know my brother? Exploration Look at the code. See how the if statement assigns a value to the response and returns that response. The method getrandomresponse picks a response from a group of String objects. Exercises Alter the code: 1. Have it respond Tell me more about your pets when the statement contains the word dog or cat. For example, a possible statement and response would be: Statement: I like my cat Mittens. Response: Tell me more about your pets. 3

2. Have it respond favorably when it sees the name of your teacher. Be sure to use appropriate pronouns! For example, a possible statement and response would be: Statement: Ms. McDowell is telling us about Strings. Response: She sounds like an awesome teacher. 3. Have the code check that the statement has at least one character. You can do this by using the trim method to remove spaces from the beginning and end, and then checking the length of the trimmed string. If there are no characters, the response should tell the user to enter something. For example, a possible statement and response would be: Statement: Response: Say something, please. 4. Add two more noncommittal responses to the possible random responses. 5. Pick three more keywords, such as no and brother and edit the getresponse method to respond to each of these. Enter the three keywords and responses below. Questions 1. What happens when more than one keyword appears in a string? Consider the string My mother has a dog but no cat. Explain how to prioritize responses in the reply method. 2. What happens when a keyword is included in another word? Consider statements like I know all the state capitals and I like vegetables smothered in cheese. Explain the problem with the responses to these statements. 4

Activity 3: Better Keyword Detection In the previous activity, you discovered that simply searching for collections of letters in a string does not always work as intended. For example, the word cat is in the string Let s play catch!, but the string has nothing to do with the animal. In this activity, you will trace a method that searches for a full word in the string. It will check the substring before and after the string to ensure that the keyword is actually found. You will use some more complex String methods in this activity. The String class has many useful methods, not all of which are included in the AP Computer Science Java Subset. But they can be helpful in certain cases, so you will learn how to use the API to explore all of the methods that are built into Java. Brainstorm: (Individual, Pair, Class) Keyword Method 5

Exploration: Understand the new method This version of the Magpie class has a method named findkeyword to detect keywords. This method will only find exact matches of the keyword, instead of cases where the keyword is embedded in a longer word. Read through the findkeyword method. Example: findkeyword("yesterday is today's day before.", "day", 0); Iteration psn before after 6

Partner Exercise: To ensure that you understand it, trace the following method calls with your partner. Write the value of each of the variable psn, before, and after each time the program control reaches the point in the method indicated by the comment. 1. findkeyword("she's my sister", "sister", 0); Iteration psn before after 2. findkeyword("brother Tom is helpful", "brother", 0); Iteration psn before after 3. findkeyword("i can't catch wild cats.", "cat", 0); Iteration psn before after 4. findkeyword("i know nothing about snow.", "no", 0); Iteration psn before after 7

Assignment: Write a detailed explanation below of what happens when you call the findkeyword() method. Include two examples of your choosing (they can be examples that you traced with your partner). Walk through the steps that lead to values for psn, before, after. Exercise (for the following day ): Use the new method Repeat the changes you made to the program in Activity 2, using this new method to detect keywords. 8

Activity 4: Responses that Transform Statements Single keywords are interesting, but better chatbots look for groups of words. Statements like I like cats, I like math class, and I like Spain all have the form I like something. The response could be What do you like about something? This activity will respond to groupings of words. Exploration Get to know the revised Magpie class. How does it respond to: I want to build a robot. I want to understand French. Do you like me? You confuse me. Tracing Exercises Look at the code. See how it handles I want to and you/me statements. Part a: Analyzing the I want to method Record comments in the spaces provided. What is the purpose? 9

Part b: Tracing the you/me method. Record comments in the spaces provided. What is the purpose? Writing Code Exercises 1. The I Want method: Have it respond to I want something statements with Would you really be happy if you had something? In doing this, you need to be careful about where you place the method. Be sure you understand why. For example: Statement: I want fried chicken. Response: Would you really be happy if you had fried chicken? Test the following and record the responses: I want to go the movies. I want peas. Marni wants to ride with us. 2. The I something you method: Have it respond to statements of the form I something you with the restructuring Why do you something me? For example: Statement: I like you. Response: Why do you like me? Find and record an example of when this structure does not work well. 10

Activity 5: Arrays and the Magpie When you last worked with the Magpie, default responses were handled with a nested if statement. This certainly worked, and you could add more responses, but it was a bit awkward. An easier way to keep track of default responses is with an array. In this activity, you will see how an array makes handling default responses much easier. Exercise 1. In your Magpie Activity 4 code for the Magpie Class, declare and initialize a private instance variable for an array of Strings that will store your Magpie s random responses. *Remember, you can fill an array the short way, as demonstrated below: private String[] flowers = { Tulip, Rose, Daisy }; 2. Write a method with the following header that will return a random response from your array: private String getrandomresponse() { // fill in code here } Hint 1: You will need Math.random(). Hint 2: Use.length in your method so that you don t have to change the method when you add or take away random responses in your array. 3. Alter the array to add four additional random responses. Notice that, because the getrandomresponse method uses the length attribute of the array, you do not need to change anything else. 4. Compile and run your code. You should run it until you see all of your new responses. By The Way You should see no difference in the outward behavior of your code when you use the array. Instead, it has been changed so that its internal structure is different. This is called code refactoring. That s one of the big benefits of dealing with methods as black boxes. As long as they perform the action required, the user does not care about how they perform the action. 11

Current Work in the NLP There is much work going on with Natural Language Processing in a variety of areas: Spam filtering uses NLP to determine whether an email message is spam. Many businesses use virtual agents to provide assistance to customers on Web sites. Information retrieval parses text, such as email messages, and tries to extract relevant information from it. For example, some email programs will suggest additions to online calendars based on text in the message. Sentiment analysis takes information retrieval further. Rather than extract information from a single source, it goes to a variety of online resources and accumulates information about a particular topic. For example, sentiment analysis might follow Twitter to see how people are reacting to a particular movie. Question answering systems search a large body of knowledge to respond to questions from users. The best known question answering system is IBM s Watson. General information http://www.nlp-class.org. A free online NLP class from Stanford. The first video does a good job of explaining the problems and promises of NLP, although much of the material is at a much higher level. http://nsf.gov/cise/csbytes/newsletter/vol1i4.html. An issue of the NSF Bits and Bytes Newsletter dedicated to NLP. Professor Mari Ostendorf of the University of Washington is featured in the newsletter. Some chatbots http://www-03.ibm.com/innovation/us/watson/what-is-watson/science-behindan-answer.html. Numerous videos about the creation of Watson. http://nlp-addiction.com/chatbot. Versions of the Eliza program, the first widespread chatbot. 12