Intro to Knowledge Based Systems CS 343 Elaine Rich.

Post on 11-Jan-2016

221 views 3 download

Tags:

transcript

Intro to Knowledge Based Systems

CS 343

Elaine Rich

The Key Issues

•What knowledge do we need?

•How can it be represented?

•How can we reason with it?

•Where does it come from?

Our sandbox:

•Question answering

Stating the Facts

Painter(Leonardo)Composer(Palistrina)Country(Italy)

Question: Name a painter

?Painter(x)Leonardo/x Bind x to Leonardo and we have an answer

Adding More Facts

Painter(Leonardo)Composer(Palistrina)Country(Italy)Lived-In(Leonardo, Italy)Painter(Rubens)Lived-In(Rubens, Europe)

Question: Name an Italian painter.

Adding More Facts

Painter(Leonardo)Composer(Palistrina)Country(Italy)Lived-In(Leonardo, Italy)Painter(Rubens)Lived-In(Rubens, Europe)

Question: Name an Italian painter.

?Painter(x) Lived-In(x, Italy)

Adding More Facts

Painter(Leonardo)Composer(Palistrina)Country(Italy)Lived-In(Leonardo, Italy)In(Italy,Europe)Climate(Europe, moderate)

Question: Name a painter who lived in a moderate climate.

Adding More Facts

Painter(Leonardo)Composer(Palistrina)Country(Italy)Lived-In(Leonardo, Italy)In(Italy,Europe)Climate(Europe, moderate)

Question: Name a painter who lived in a moderate climate.

?Painter(x) Lived-In(x,y) Climate(y, moderate)

Adding More Facts

Painter(Leonardo)Composer(Palistrina)Country(Italy)Lived-In(Leonardo, Italy)In(Italy,Europe)Climate(Europe, moderate)

Question: Name a painter who lived in a moderate climate.

?Painter(x) Lived-In(x,y) In(y, z) Climate(z, moderate)

Adding More Facts

Composer(Palistrina)Country(Italy)Lived-In(Leonardo, Italy)In(Italy,Europe)Climate(Europe, moderate)Painter(Rubens)Lived-In(Rubens, Europe)

Question: Name a painter who lived in a moderate climate.

?Painter(x) Lived-In(x,y) In(y, z) Climate(z, moderate)

Making the KB More Flexible

Painter(Leonardo)Composer(Palistrina)Country(Italy)Lived-In(Leonardo, Italy)In(Italy,Europe)Climate(Europe, moderate)Painter(Rubens)Lived-In(Rubens, Europe)x,y ((In(x, y) Climate(y, moderate)) Climate(x, moderate))

Question: Name a painter who lived in a moderate climate.

?Painter(x) Lived-In(x,y) Climate(y, moderate)

Another Way to Do It

Painter(Leonardo)Composer(Palistrina)Country(Italy)Lived-In(Leonardo, Italy)In(Italy,Europe)Climate(Europe, moderate)Painter(Rubens)Lived-In(Rubens, Europe)x,y,z ((Lived-In(x, y) In(y, z)) Lived-In(x, z))

Question: Name a painter who lived in a moderate climate.

?Painter(x) Lived-In(x,y) Climate(y, moderate)

But We Still Haven’t Said it All

Painter(Leonardo)Town(Anchiano)Country(Italy)Born-In(Leonardo, Anchiano)In(Anchiano, Italy)In(Italy, Europe)x,y,z ((Born-In(x, y) In(y, z)) Born-In(x, z))

Question: Was Leonardo born in Europe?

?Born-In(Leonardo, Europe)

Describing “in” More Generally

Painter(Leonardo)Town(Anchiano)Country(Italy)Born-In(Leonardo, Anchiano)In(Anchiano, Italy)In(Italy,Europe)x,y,z ((Born-In(x, y) In(y, z)) Born-In(x, z))

Question: Is Anchiano in Europe?

?In(Anchiano, Europe)

Describing “in” More Generally

Painter(Leonardo)Town(Anchiano)Country(Italy)Born-In(Leonardo, Anchiano)In(Anchiano, Italy)In(Italy,Europe)x,y,z ((Born-In(x, y) In(y, z)) Born-In(x, z)) x,y,z ((In(x, y) In(y, z)) In(x, z))

Question: Is Anchiano in Europe?

?In(Anchiano, Europe)

But We Still Haven’t Said Everything about “in”

Country(Italy)Person(Mike)Visited(Mike, Italy)In(Italy, Europe)

Question: Name someone who visited Europe.

?Person(x) Visited(x, Europe)

But We Still Haven’t Said Everything about “in”

Country(Italy)Person(Mike)KnowsThePopulationOf(Mike, Italy)In(Italy, Europe)

Question: Name someone who knows the population of Europe.

?Person(x) KnowsThePopulationOf(x, Europe)

Predicate Names

Painter(Leonardo)Composer(Palistrina)Country(Italy)Lived-In(Leonardo, Italy)In(Italy,Europe)Climate(Europe, moderate)

Question: Name a painter who once lived.

?Painter(x) Lived(x)

The Perils of Long Predicate Names

BearOfVerySmallBrain(Pooh)

The Perils of Long Predicate Names

BearOfVerySmallBrain(Pooh) Name a bear.Is Pooh silly?

The Perils of Long Predicate Names

BearOfVerySmallBrain(Pooh)

b (BearOfVerySmallBrain(b) silly(b))

Name a bear.Is Pooh silly?

Doing it Right1. Pooh is a bear; Bears are animals; animals are objects, etc.                 

Bear(Pooh)                  b (Bear(b) Animal(b) )                 a (Animal(a) Object(a))

2. Pooh has a very small brain.                  size(Brain(Pooh)) = very(small)

3. Brains are parts of animals; an animal has only one.         a, b (Brain(a) = b animal(a) brain(b) haspart(a,b))

4. Animals with brains that are small (or below) are silly.                 a (Size(Brain(a)) small silly(a))

5. Every object has a size.  Sizes are on a scale from Tiny to Huge. x (object(x) s (size(x) = s))                

Tiny < Small < Medium < Large < Huge                  -2  <  -1   <    0   <   1   <  2

6. The function Very maps a point on a scale to a more extreme value: either positive or negative.       

x (magnitude(Very(x)) > x sign(Very(x)) = sign(x) )

Implementing The Reasoning Engine

•Building a theorem prover

•Unification

•Representing the facts so they are easy to use

•An inference procedure that is sound and complete

•Search algorithm

•Adding other structure to support common operations

Reasoning Forward(1) Painter(Leonardo)(2) Lived-In(Leonardo, Italy)(3) In(Italy,Europe)(4) Climate(Europe, moderate)

(5) x,y ((In(x, y) Climate(y, moderate) ) Climate(x, moderate))

(6) x (Climate(x, moderate) GrowsIn(x, boxwood))

Question: ?Painter(x) Lived-In(x,y) GrowsIn(y, boxwood)

Reasoning forward:Italy/x, Europe/y in (5):

(7) (In(Italy, Europe) Climate(Europe, moderate)) Climate(Italy, moderate)

Italy/x in (6):

(8) Climate(Italy, moderate) GrowsIn(Italy, boxwood)

Leonardo/x, Italy/y in (the question):Painter(Leonardo) Lived-In(Leonardo, Italy) GrowsIn(Italy, boxwood)

Reasoning Backward

Painter(x) Lived-In(x,y) GrowsIn(y, boxwood)

Leonardo/x

Lived-In(Leonardo,y) GrowsIn(y, boxwood)

Rivera/x

Lived-In(Rivera,y) GrowsIn(y, boxwood)

Painter(Napolean) GrowsIn(France,boxwood)

Napolean/x,France/y

GrowsIn(Italy, boxwood)

Italy/y

Climate(Italy, moderate)

In(Italy, Europe) Climate(Europe, moderate)

Unification

A fundamental operation in both of these processes is matching. In propositional logic, matching is trivial:

Example: Prove Q W given: PP QW

Q W

Q

P

True

Unification

But in FOL, it is not so trivial. What should we do about:

x, y (Lived-In(x, y))Lived-In(Leonardo, Italy)

Or: x (P(x, x))P(Leonardo, Leonardo)P(Leonardo, Rubens)

Or: x (P(x, FatherOf(x)))P(Leonardo, Rubens)

Unification

The term unification is used for a variety of matching processes:

Typically two expressions “unify” if they can be about the same individual. In other words they are consistent.

x, y (Lived-In(x, y))Lived-In(Leonardo, Italy)

Or: x (P(x, x))P(Leonardo, Leonardo)P(Leonardo, Rubens)

Unification Is Used With Other Representational Systems, e.g., Grammars

John likes Coke.* John like Coke.* I likes Coke.

[NUMBER SG] [NUMBER SG] = [NUMBER SG]

[NUMBER SG] [NUMBER PL] Fails

[NUMBER SG] [NUMBER [] ] = [NUMBER SG]

[NUMBER SG] [PERSON 3 ] = NUMBER SG

PERSON 3

Two feature structures can be unified if there is no conflict between them.

Adding Unification to Grammar RulesThe rule S NP VP

[CAT S HEAD [1] STRUCT [SUBJECT [A1]

VP [A2] ] ]

A1: [CAT NP AGREEMENT [2]: [] ]

A2: [CAT VP HEAD [1] AGREEMENT [2] ]

Note: The STRUCT feature is used here to record the tree structure of the constituents as they are produced.

Applying the Grammar Rule

This rule says that we can build an S from two components, A1 and A2. To apply this rule to two candidate components X and Y, the parser must:

Copy the rule structure to create a new instance of S. (Unification is destructive and we’ll need to be able to reuse the rule.)

Unify the feature structure of X with the specification for A1 on the right side of the rule. This will succeed if the CAT of X unifies with NP, and if it succeeds, it will bind [2] to the AGREEMENT structure of X and A1 to X.

Unify the feature structure of Y with the specification for A2 on the right side of the rule. This will succeed if the CAT of Y unifies with VP and if the AGREEMENT structure of Y unifies with [2], namely the agreement structure of X. If it succeeds, it will bind [1] to the HEAD feature of Y and A2 to Y.

Example of Applying the RuleA1: [CAT NP HEAD dogs

STRUCT [NOM dogs] AGREEMENT [NBR PL

PERS 3] ]A2: [CAT VP

HEAD ran STRUCT [V ran]

AGREEMENT [] ]

[CAT S HEAD [ran] STRUCT [SUBJECT [CAT NP HEAD dogs

STRUCT [NOM dogs] AGREEMENT [2]: [NBR PL

PERS 3] ] VP [CAT VP

HEAD ran STRUCT [V ran]

AGREEMENT [2] ] ] ]

Search

Painter(x) Lived-In(x,y) Climate(y, moderate)

Leonardo/x Rubens/x Sargent/x America/y Europe/y Italy/y Japan/y

Europe/y Italy/y Japan/y

Which search algorithm should we use?

Object-Oriented Representations

We can constrain the search by:

• Organizing the facts in ways that reflect how they are likely to be used.

• Taking advantage of the fact that some specific kinds of inference are very powerful. It may be possible to limit the kinds of facts that can be expressed and still retain enough power while, at the same time, increasing efficiency.

Alternatives to a Flat List of FactsPainter(Leonardo)Composer(Palistrina)x (Painter(x) Artist(x))x (Composer(x) Artist(x))x (Artist(x) Temperamental(x))x (Person(x) y Mother-Of(x, y))x (Person(x) Likes(x, x))Country(Italy)Lived-In(Leonardo, Italy)In(Italy, Europe)Climate(Europe, moderate)x,y ((In(x, y) Climate(y, moderate)) Climate(x, moderate))

We present the facts as a flat list. There’s no built in grouping, as, for example, all the things we know about Palistrina.

Frame Systems

Organize the facts around the objects in the KB.

(*Leonardo instance-of Painter)(*Leonardo has (lived-in (*Italy)))

(showme *Leonardo)(*Leonardo has (instance-of (Painter))

(lived-in (*Italy)))

Classes, Instances, and Slots

In a frame system, there are three fundamental kinds of objects:

•Instances, e.g., Palistrina, Italy

•Classes, e.g., Artist, Person, Country, Thing, Event

•Slots, which capture the relationships among instances and classes. Examples: instance-of, lived-in, superclasses, parts

Classes

The backbone of any frame system is a hierarchy of classes, from which properties can be inherited. Most modern frame systems support multiple inheritance.

Thing

Person

Artist Italian

Painter

*Leonardo

Living-thing

Ontologies

Ontology is the study of what exists. An ontology, as used in AI, is a definition of a set of classes of things that exist, typically augmented with relationships among them.

Ontologies

Thing

Entity Event State

ChickenNoodleSoup

The top part is often called an “upper ontology”.

Tweety

All robins are birdsAll birds have two wings

All birds lay eggsAll robins have red breastsTweety is a robin

x ((robin(x) bird(x))x (bird(x) yz (haspart (x, y)

wing(y) wing (z) haspart(x,z) y z))

x (bird (x) birthmode(x, eggs))x (robin (x) color(breast (x), red))robin (Tweety)

Facts about individuals and categories represented in FOL:

Other kinds of facts represented in FOL:

Red breasted birds are easily visible

x bird(x) color(breast(x), red) visible(x)

The Facts in a Frame System

eggs birds has-part wings birthmode has-part IS-A IS-A

IS-A wing1 wing2

robins

instance-of

Tweety

Early representation systems like this were called semantic nets. They evolved into frame systems that allow richer representations that may be harder to view graphically.

Why are Classes and Instances Special?

Logically, they are not. (At least not yet.)

But it may be useful to represent them differently because:

•Indexing facts by classes may help the inference engine find useful facts quickly.

•Organizing facts by classes may make it easier for people to enter knowledge.

•Some facts apply to the classes themselves.

•Some kinds of reasoning arise naturally from class membership.

Inheritance

Some specific kinds of reasoning are especially useful.

Painter(Leonardo)x Artist(x) Temperamental(x)

Inheritance

Some specific kinds of reasoning are especially useful.

Painter(Leonardo)x Artist(x) Temperamental(x)

x Painter(x) Artist(x)

Inheritance

Some specific kinds of reasoning are especially useful.

Painter(Leonardo)x Artist(x) Temperamental(x)

x Painter(x) Artist(x)

Person

is-a

Artist

is-a

Painter

instance-of

Leonardo

What About Slots and Their Values?

•When frames are a just way of indexing FOL expressions to improve efficiency.

•Localizing the search

•Specifying forward vs. backward reasoning

(Country (Climate x (IF-NEEDED

((In SELF y) (Climate y z) (x := z)))))

(Continent (Climate x (IF-ADDED

((IN y SELF) Climate(y, x)))))

What About Slots and Their Values?

•When frames are a just way of indexing FOL expressions to improve efficiency.

•Localizing the search

•Specify forward vs. backward reasoning

•When frames are a way of indexing procedures.

•Arbitrary procedures

•A procedural implementation of inheritance

(Continent (Population x (IF-NEEDED

(Sum-Pops-of-Countries))))

We can’t reason about what goes on inside the procedure.

How Inheritance is Implemented Can Matter

Reasoning in FOL is monotonic.

But inheritance may not be:

•Tweety is a bird.

•Birds fly.

•Does Tweety fly?

Implementing Inheritance

birds canfly T

ISA ISA

robins ostriches canfly F Instance-of Instance-of

Tweety Richy

More on nonmonotonic reasoning later.

Multiple Inheritance

Person

Republican

Person

Quaker

instanceinstance

subclasssubclass

pacifistTRUE pacifist FALSE

Slots as Full Fledged Objects•IF-NEEDED and IF-ADDED rules.

•Every person has exactly one mother. But a person may like many things.

•If x is a subclass of y then y is a superclass of x.

•If something is blue at time t then it is also blue at time t+1 unless something specific happens to change its color.

These are properties of slots (i.e., relations). We encode them by treating a slot as an object that, in turn, has slots (properties). For example:

(personality has(instance-of (Slot))(domain (Animal))(range (PersonalityTypes)(inverse (InstancesOfPersonalityType)(cardinality (N-to-1)))

Facts about Classes vs. Facts about Instances

All robins are birdsAll birds have two wings

All birds lay eggsAll robins have red breastsTweety is a robin

Robins are found throughout the US

x (Robin(x) Bird(x))x (Bird(x) yz (Haspart(x, y)

Wing(x) Wing(y) Haspart(x,z) y z))

x (Bird(x) Birthmode(x, Eggs))x (Robin(x) Color(Breast(x), Red))Robin(Tweety)

Representing the Two Kinds of Facts

eggs Birthmode birds Has-part wings Has-part Instance-of Instance-of

IS-A wing1 wing2US Habitat

robins

Instance-of

Tweety

Representing the Difference in KM

Inference rules attached to classes describe how to compute values for instances of the class:

x Person(x) y Mother-Of(x, y)

(Every Person has (mother (a person)))

(showme Person)(Person has (superclasses (Living-Thing))

(subclasses (Artist Italian)) about the class

(instances (Leonardo))) (Every Person has (mother (a person)) about individuals

Slots Correspond to Binary Predicates

Lived-in(Leonardo, Italy)

Climate(Italy, moderate)

Converting Unary Predicates to Properties

So what do we do with logical expressions that don’t look like that:

Temperamental(Leonardo)

We want to attach this property to Leonardo. To do that we need a slot. A natural way to view a slot is as a binary predicate:

Lived-In(Leonardo, Italy) becomes (*Leonardo has (lived-in (*Italy)))

So we need to create a slot, for example personality: (*Leonardo has (personality (*Temperamental)))Or, more generally:

(Every Artist has (personality (*Temperamental)))

What About Consistent Variable Substitution?

This one is easy:

x (Person(x) Likes(x, chocolate))

(Every Person has (likes (*chocolate)))

But what about:

x (Person(x) Likes(x, x))

The way to do this in KM:

(Every Person has (likes (self)))

Rules with Multiple Antecedents

x Artist(x) Personality(x, temperamental)

(every Artist has (Personality (*Temperamental)))

x Artist(x) Famous(x) Personality(x, temperamental)

(every Artist has ((Personality ((if (Self isa FamousPerson) then

*Temperamental))))

So we’ve got if-then rules but they’re indexed first by one term of the antecedent (e.g., Artist) and then by the property mentioned in the conclusion (e.g., Personality).

Multiple Antecedents and Multiple Variables

x,y Artist(x) Geek(y) NotCommunicate(x, y)

(every Artist has (notCommunicate ((the all-instances of Geek))))

(every Geek has (notCommunicate ((the all-instances of Artist))))

What About Axioms that Aren’t Obviously About Particular Things?

x,y ((In(x, y) Climate(y, moderate)) Climate(x, moderate))

Or, more generally:

x,y,z ((In(x, y) Climate(y, z)) Climate(x, z))

What About Axioms that Aren’t Obviously About Particular Things?

x,y ((In(x, y) Climate(y, moderate)) Climate(x, moderate))

Or, more generally:x,y,z ((In(x, y) Climate(y,z)) Climate(x, z))

In fact, it’s about places:x,y,z ((Place(x) Place (y) In(x, y) Climate(y, z))

Climate(x, z))

So now we know where to hang it:

(every Place has (climate ((the climate of (the Place is-in of Self)))))

Can We Axiomatize Some Things Once and For All?

•Physical objects have mass. Ideas don’t.

•Containers are physical objects that have insides and walls.

•Places cover area on the globe. Some places cover subareas of others.

•If you’re “in” a place, you’re “in”all places that overlap it.

•If you’re “in” a place, you’re not “in” all places that don’t overlap it.

•People are physical objects.

•Etc.

Are There Limits to FOL?

Most x Artist(x) Temperamental(x)

x Artist(x) Temperamental(x) Unless Calm(x)

x Painter(x) VeryTemperamental(x)

x Sculptor(x) SemiTemperamental(x)

x,t Painter(x, t) Painter(x, t+1)

x,t Hungry(x, t) ? Hungry(x, t+1)

Inside(x)