Lab 8 Artificial Intelligence
© Dmitriy Shironosov/ShutterStock, Inc.
LABORATORY
■■ Learn■how■semantic■networks■and■rule-based■natural■language■systems■can■simulate■ intelligent■behavior.
■Software■needed: ■ 1)■ Apps■from■the■Lab■Manual■website: a)■ Semantic■Networks■(Semantic■Networks.jar) b)■ Eliza■Therapist■(Eliza.jar)
17
OBJECTIVE
REFERENCES
Artificial Intelligence
© Jones & Bartlett Learning, LLC NOT FOR SALE OR DISTRIBUTION
184 | Laboratory 17
BACKGROUND Artificial intelligence (AI) is a major field in computer science. Review these topics from your textbook, lecture notes, or online resources:
■ Knowledge representation, semantic networks ■ Expert systems; knowledge-based, rule-based, and expert systems; inference engines
ACTIVITY ❯ Part 1
Knowledge is an essential part of acting intelligently, as is having a method for using that knowledge. Computers running AI programs use information to make decisions, filter inputs, and generate new knowledge. The structure of information inside the computer’s memory is called a “knowledge representation technique.” Semantic networks are one kind of knowledge representation technique. They are often depicted as graphs of linked nodes. However, the graph can be represented textually by statements, and of course computers are much more comfortable with text than with pictures.
The Semantic Networks app allows you to enter rules in English statements and then ask a question called a “query.” Applying the rules using a process known as “deduction,” the app tries to answer the query. If it can positively answer the question, the app says, “This is true.” If it can’t, it says the statement is false or cannot be answered. Some logical deduction systems, such as the Prolog language, use the closed- world assumption, meaning that all information that is true is included in the rule base, and anything that is not in the rule base is false. Other AI systems do not make such a grand assumption and merely state that they cannot prove a statement is true if it’s not in the rule base. The statement might be false, or the rule base might be incomplete.
Start the Semantic Networks app and click on the Example button. Then rev up the logic inference engine by clicking on Is this true? Here’s what you will see:
© Jones & Bartlett Learning, LLC NOT FOR SALE OR DISTRIBUTION
Artificial Intelligence | 185
Experiment with some other queries, such as a woman eats food or a man is an animal. The app requires that you use no punctuation or capital letters.
Type in the query a woman is a man. What does the app say? If we type Mary has blood, we also get “This is false or can’t be answered.” While we know this statement is true, our very small rule base doesn’t cover that topic, so deduction is impossible.
Obviously, it would take a very large rule base to create a robust, “real-world” logical deduction system. Just how large the rule base would have to be is a hotly debated issue in AI. Computer scientist Doug Lenat has been building a gigantic system named CYC for over 10 years. (CYC is pronounced “sike” and is short for enCYClopedia.) He believes that if about 10 million common-sense facts are stored in CYC, it can begin to function like a human. Perhaps you’d like to try typing 10 million facts into the app to see if it’s able to function like a human.
As you’re typing in your 10 million rules, be aware that the app is very limited in terms of the kinds of phrases it can process (we won’t use the loaded word “understand” anymore). Here are the patterns the app processes:
noun isa noun noun verb noun verb object noun’s noun verb object
The only “keyword” (meaning a word that must appear exactly as it is, without substitutions) is isa. English words can be substituted for all the others. The ’s that is tagged onto the end of the first noun is optional.
You might be wondering about this keyword isa, since you can see that the rules contain regular English statements like Mary is a woman. The reason you can use regular English in the rules is because of the clever way the app processes rules and queries. First, it combs through the rules and queries, replacing phrases like is a and is an with our keyword isa, as you can see in the Deduced facts column. Also, notice that articles such as a, an, and the are totally eliminated. This kind of preprocessing is very common in computer systems because it simplifies the programmer’s task.
The logical deduction system inside this app matches patterns. If a query matches a rule exactly, it is true. If not, the app tries to replace the first noun with a second one that appears in an isa rule. For instance, we know that the statements woman isa human and human isa animal and animal eats food are all true. By making two replacements, we find out that woman eats food. Since Mary isa woman, we can safely conclude that Mary eats food. The same happens for possessive nouns; they can also be replaced by their “superclasses.” (human is a superclass of woman, and animal is a superclass of human.)
TIP The Semantic Networks app can load and save your rules to make it easier to pick up where you left off.
© Jones & Bartlett Learning, LLC NOT FOR SALE OR DISTRIBUTION
186 | Laboratory 17
❯ Part 2 One of the classic, early AI programs is ELIZA, written by Joseph Weizenbaum in 1963. An example of a famous ELIZA conversation with a human appears in the Wikipedia article about ELIZA. ELIZA appears to be a therapist who responds to a patient’s statements by cleverly rewording them and turning them into questions. Though ELIZA’s method sounds pretty simple, and though no one could persuasively argue that the computer is really thinking when it is running ELIZA, the program’s effect on people was surprisingly powerful. In fact, Dr. Weizenbaum, shocked by people’s reactions and fearing the potential for misuse of AI, turned against the field!
To begin, start the Eliza Therapist app and type a question or statement into the top text area, pressing Enter when you’re done. ELIZA responds in the text area below. A running transcript of your inputs and the computer’s responses is kept in the larger area below that. After you type for a while, click on the Show rules button.
The original ELIZA used only a few simple rules. ELIZA turned the client’s statement into a question merely by appending a question mark to the statement and switching the pronouns, as shown below:
ELIZA didn’t even use the complicated English question construct “Did your mother make you come here?” This is more difficult because the verb has to be changed and a form of the verb “to do” has to be inserted.
© Jones & Bartlett Learning, LLC NOT FOR SALE OR DISTRIBUTION
Artificial Intelligence | 187
Our version of ELIZA uses a different approach. Instead of one or two simple transformation rules, the app allows the user to enter any number of rules. ELIZA then tries to match the input statements with the rules, mixing up the order by starting at a random spot in the list each time.
The rules have the form
pattern=>response
Inside both the pattern and the response, variables can appear. They are marked with a question mark and are followed by the numbers 0, 1, 2, etc. For example:
My $0 made me come here *=>Why did your $0 make you come here?
In this pattern, $0 is matched against a single word that appears between the words My and made. The asterisk at the end of the pattern means that none, a few, or many words may appear here. They are ignored. The words that must match are My, made, me, come, and here, in that order, with a word between My and made, symbolized by $0.
If ELIZA can’t find a rule that matches the statement, it moves on to the next rule. If no rules match any of the statements, ELIZA picks a standard response such as “Let’s move on” or “Tell me more.”
If you want to match one or more words, surround the variable with an asterisk and parentheses, as in the following rule:
*($0)=>$0 ?
This rule merely spits back the statement as a question, although it doesn’t do pronoun switching like the original ELIZA. You can see pronoun switching in some of the other rules.
Another thing that you can put in a rule is an instruction to forbid the matching of some words, as in the following rule:
$0/You are $1=>Do you really believe that $0 are $1 ?
This rule tries to match a sentence that has “are” as the second word, but the first word cannot be You. Also, as shown in the rule above, if your rule ends with a variable followed by punctuation, leave a space between the variable and the punctuation mark.
Unfortunately, this ELIZA app has many limitations. Some of the purely mechanical ones include the inability to recognize uppercase and lowercase words as essentially the same word. It also doesn’t know about English grammar rules, such as the rule that only plural nouns may precede the verb are. Thus, Water are wet would be accepted by the above rule—which is clearly wrong!
ELIZA’s use of keywords when matching rules to client inputs can result in inept responses. The following is a classic example:
Client: Necessity is the mother of invention. ELIZA: Tell me more about your mother.
ELIZA knows nothing about metaphors, hyperbole, or similes. In short, ELIZA flunked high school English!
© Jones & Bartlett Learning, LLC NOT FOR SALE OR DISTRIBUTION
188 | Laboratory 17
In addition, of course, ELIZA cannot be said to understand the client’s input. Thus, it converses without thinking, as happens far too often at cocktail parties and political rallies. There are other AI systems that actually attempt to tease out the meanings of the words and phrases, but they are still largely experimental. Natural-language understanding is a long way from the chatty computers on Star Trek!
TIP ELIZA can load and save the transformation rules. Saving your progress will help you greatly when you come back to the app later.
© Jones & Bartlett Learning, LLC NOT FOR SALE OR DISTRIBUTION