1 / 47

KM: The Knowledge Machine A knowledge representation and reasoning system

KM: The Knowledge Machine A knowledge representation and reasoning system. Peter Clark Knowledge Systems Boeing Math and Computing Technology. Characteristics of KM. Inference-capable Expressive Intuitive to express knowledge in: ideosyncratic syntax

zeroun
Download Presentation

KM: The Knowledge Machine A knowledge representation and reasoning system

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. KM: The Knowledge MachineA knowledge representation and reasoning system Peter Clark Knowledge Systems Boeing Math and Computing Technology

  2. Characteristics of KM • Inference-capable • Expressive • Intuitive to express knowledge in: • ideosyncratic syntax • but very similar to other frame languages (esp KRL) • substantially more than a “simple” frame system • Formal semantics • Deals with value sets and unification • Lazy evaluation • Reasoning with situations • Mature • Free • Reasoning: backward chaining, plus automatic classification

  3. Preview • An example of a frame in KM, for the “Buy” class KM English (Buy has (superclasses (Event))) (every Buy has (buyer ((a Agent))) (seller ((a Agent))) (object ((a Thing))) (money ((the cost of (the object of Self)))) (subevent ( (a Give with (agent ((the buyer of Self))) (object ((the money of Self))) (recipient ((the seller of Self)))))) (a Give with (agent ((the seller of Self))) (object ((the object of Self))) (recipient ((the buyer of Self))))))) "All buy events have - a buyer and a seller (both of type agent) - an object which is bought - some money equal to the cost of the object - two `give' subevents, in which: 1. The buyer gives the money to the seller 2. The seller gives the object to the buyer.''

  4. KIF syntax for same knowledge:

  5. This Tutorial • Overview of the KM language and inference • based on a detailed script of using KM • the examples are “toy” • Not a tutorial in how to do knowledge representation! • KM Manuals give the full reference* • details of the syntax • logical semantics for the expressions • Tutorial works best if you ask lots of questions!! * http://www.cs.utexas.edu/users/mfkb/km.html

  6. Interaction with KM • Interaction with KM: read-eval-print • User gives KM an expression (assertion/query) • KM evaluates it and returns the result USER: (km) KM> (reset-kb) Resetting KM... (t) KM> 123 (123)

  7. Instances • Two key types of objects: instances, and classes • an instance denotes some object in the world • a class is a collection of instances* • An instance (individual) evaluates to itself ;;; --- instances --- ;;; "Fred" KM> *Fred ; (* has no special meaning, is just a (*Fred) ; convenient character to visually distinguish ; from classes) ;;; "1" KM> 1 (1) *: or more precisely, has a collection of instances associated with it (the classes extension)

  8. “Creating instances”(existential quantification) • We can “create” (assert the existence of) an instance of a particular class by the expression • (a <class>) ;;; "A cat." KM> (a Cat) (_Cat0) ; _Cat0 is a Skolem individual denoting that cat ;;; “A black cat.” KM> (a Cat with (color (*Black)) (parts ((a Head) (a Tail)))

  9. Slots • Slots relate instances together • Slots are themselves frames • can specify properties of the slot on these frames ;;; --- slot declarations (optional) --- ;;; "`age' is a slot relating physical objects (Physobj) to Numbers. ;;; A physical object has at most one age." KM> (age has (instance-of (Slot)) (domain (Physobj)) (range (Number)) (inverse (is-age-of)) ; name of the inverse slot (cardinality (N-to-1))) ; one age per thing

  10. Instance Frames and Simple Queries • Frames describe objects in the world • list its properties, and relationships to other objects • Queries: Form is (the <slot> of <object>) ;;; "Fred is a person." KM> (*Fred has (instance-of (Person))) ;;; "Fred's age is 32." KM> (*Fred has (age (32))) ;;; "Show me the frame representing Fred." KM> (showme *Fred) (*Fred has (instance-of (Person)) (age (32))) ;;; "What is the age of Fred?" KM> (the age of *Fred) (32)

  11. Instance Frames and Queries (cont) • Values may themselves be expressions • KM keeps track of inverse relations also ;;; "Fred owns a car." KM> (*Fred has (owns ((a Car)))) ;;; "What does Fred own?" KM> (the owns of *Fred) (_Car1) ; (Skolem _Car1 created, denoting that car) ;;; "Show me the frame representing that last car." KM> (showme (thelast Car)) (_Car1 has (instance-of (Car)) (owns-of (*Fred))) ; note the inverse slot (default name is "<slot>-of")

  12. Embedded Units and Access Paths • Frames can be embedded within frames • A query path may be embedded in a query path ;;; --- embedded units --- ;;; "Joe is a person, and owns a red car." KM> (*Joe has (instance-of (Person)) (owns ((a Car with (color (*Red)))))) ;;; --- access paths --- ;;; "What are the color(s) of the thing(s) which Joe owns?" KM> (the color of (the owns of *Joe)) (*Red)

  13. Embedded Units and Access Paths (cont) • A path will select all values on a slot. • To select a subset, can • give a class name in the query • (the Leg parts of (a Person)) • add a filter (“generate and test”), described later • (allof (the parts of (a Person)) where (It isa Leg)) ;;; "Joe is a person, and owns a red car." KM> (*Joe has (instance-of (Person)) (owns ((a Car) (a Teddy-Bear)))) ;;; "What vehicles does Joe own?" KM> (the Vehicle owns of *Joe)) (_Car1)

  14. Class Frames and Inheritance • Can state properties for all members of a class • Each instance of that class acquires those properties ;;; "People are physical objects" (property of the class) KM> (Person has (superclasses (Physobj))) ;;; "Every person lives in a house." (property of class members) KM> (every Person has (lives-in ((a House)))) ;;; "Every house has a door and a roof." KM> (every House has (parts ((a Door) (a Roof)))) ;;; "What does Joe live in?" KM> (the lives-in of *Joe) (_House3) ;;; "What are the parts of the thing which Joe lives in?" KM> (the parts of (the lives-in of *Joe)) (_Door4 _Roof5)

  15. Exercises ;; "All professors have (at least) one car which is old, is ;; their favorite color, and was made in USA." (Professor has (superclasses (Person))) (every Professor has (owned-vehicle ( (a Car with (age (*Old)) (color ((the favorite-color of Self))) (made-by ((a Manufacturer with (location (*USA))))))))) 1. Write the KM queries to find: - the vehicle which a professor owns - the age of a professor’s vehicle - the location of the manufacturer of the professor’s vehicle 2. Create a KM frame describing the concept of a Car: (every Car has …)

  16. (every Electrophoresis has (sample ((a Chemical))) (equipment ((a Separation-unit) (a Syringe))) (subevents ( (a Remove with (object ((the sample of Self))) (location ((the delivery-medium of (the sample of Self))))) (a Insert with (object ((the sample of Self))) (destination ((the Separation-unit equipment of Self))) (equipment ((the Syringe equipment of Self))))) (Albumin has (superclasses (Chemical))) (every Albumin has (delivery-medium ((a Bottle))) (storage-medium ((a Fridge)))) Exercise 3. What is the result of the query: KM> (the location of (the Remove subevents of (a Electrophoresis with (sample ((a Albumin))))

  17. Answers to Exercises 1a. (the owned-vehicle of (a Professor)) 1b. (the age of (the owned-vehicle of (a Professor))) 1c. (the location of (the made-by of (the owned-vehicle of (a Professor)))) 2. For example... (every Car has (color ((a Color))) (parts ((a Chassis) (a Engine) (a Fuel-Tank with (supplies ((the Engine parts of Self))))))) 3. _Bottle1 (i.e., a Skolem instance of Bottle). Explanation: The location of the Remove is the delivery-medium of the sample. In this case, the sample is an instance of Albumin. From the Albumin frame, the delivery-medium would be an instance of Bottle.

  18. Tracing Inference KM> (trace) ;;; "What are the parts of the thing which Joe lives in?" KM> (the parts of (the lives-in of *Joe)) 1 -> (the parts of (the lives-in of *Joe)) 2 -> (the lives-in of *Joe) 2 (1) Local value(s): _House3 2 (2) From inheritance: (a House) 2 (1-2) Combine 1-2 together 3 -> ((_House3) && ((a House))) 3 <- (_House3) "((_House3) && ((a House)))" 2 <- (_House3) "(the lives-in of *Joe)" 2 -> (the parts of _House3) 2 (1) Local value(s): (:set _Door4 _Roof5) 3 -> (:set _Door4 _Roof5) 3 <- (_Door4 _Roof5) "(:set _Door4 _Roof5)" 2 (2) From inheritance: (:set (a Door) (a Roof)) 2 (1-2) Combine 1-2 together 3 -> ((_Door4 _Roof5) && ((a Door) (a Roof))) 3 <- (_Door4 _Roof5) "((_Door4 _Roof5) && ((a Door) (a Roof)))" 2 <- (_Door4 _Roof5) "(the parts of _House3)" 1 <- (_Door4 _Roof5) "(the parts of (the lives-in of *Joe))" (_Door4 _Roof5) KM> (untrace)

  19. Thing Physobj Number Car Person …. The Taxonomy (Inheritance Hierarchy) • Classes can themselves be subclasses of (multiple) other classes • (taxonomy) shows the entire taxonomy KM> (*Fred has (instance-of (Person))) KM> (Person has (superclasses (Physobj))) KM> (Physobj has (superclasses (Thing))) ;;; "Show me the concept taxonomy." KM> (taxonomy) Thing Number Physobj Car Cat House Person I *Fred I *Joe …. etc…..

  20. Rules • The expression for a slot-value may be a rule • The rule is evaluated when the slot-value is queried • The tests and result of the rule are themselves KM expressions ;;; "A person is a voter if he/she is older than 18." KM> (every Person has (is-voter ((if ((the age of Self) >= 18) then *Yes else (if ((the age of Self) < 18) then *No))))) ;;; "Is Fred a voter?" [Fred is 32, asserted earlier] KM> (the is-voter of *Fred) (*Yes) ;;; "Joe is 12 years old." KM> (*Joe has (age (12))) (*Joe) ;;; "Is Joe a voter?" KM> (the is-voter of *Joe) (*No)

  21. Self • For inherited information, ‘Self’ refers to the instance inheriting the information. ;;; --- Self --- ;;; "Every person likes their favorite color(s)." KM> (every Person has (likes-color ((the favorite-color of Self)))) (Person) ;;; "Fred's favorite color is blue." KM> (*Fred has (favorite-color (*Blue))) (*Fred) ;;; "What color(s) does Fred like?" KM> (the likes-color of *Fred) (*Blue)

  22. Exercise 4. Complete the expression on the “brightness” slot for the concept of a Light, so that the result depends on the light’s switch position. (every Light has (switch ((a Switch with (position ((a Position))))) (brightness (…..))) (*Up has (instance-of (Position))) (*Down has (instance-of (Position))) (*Bright has (instance-of (Brightness))) (*Dark has (instance-of (Brightness))))

  23. Answers to Exercises 4. (every Light has (switch ((a Switch with (position ((a Position)))))) (brightness ( (if ((the position of (the switch of Self)) = *Up) then *Bright else (if ((the position of (the switch of Self)) = *Down) then *Dark))))) Note that if the position is unknown, then the brightness will be unknown also (which is what we want).

  24. Arithmetic • KM has infix operators +, -, *, /, ^ • Also has arithmetic slots: (the sum of ….), etc. • sum, difference, product, quotient, and others ;;; --- arithmetic --- ;;; "What is 1 + 1?" KM> (1 + 1) (2) ;;; "A person's age in days is their age [in years] times 365." KM> (every Person has (age-in-days (((the age of Self) * 365)))) (Person) ;;; "What is Fred's age in days?" KM> (the age-in-days of *Fred) (11680)

  25. Set Expressions • Procedurally, KM iterates over a set of values • Keyword “It” denotes the value in each iteration ;;; --- set expressions --- ;;; "Show me every person [in the KB so far]?" KM> (every Person) (*Joe *Fred) ;;; "Which people are over 18?" KM> (allof (the all-instances of Person) where ((the age of It) > 18)) (*Fred) ;;; "What is the favorite color(s) of the people over 18?" KM> (forall (the all-instances of Person) where ((the age of It) > 18) (the favorite-color of It)) (*Blue)

  26. Multiple Inheritance and Unification • If several frames contribute to a slot’s values, KM will unify the different sets of values together • set unification is heuristic, not deductive • goal is to assess which objects are the same (coreferential) • The set unification operator is “&&” • Also, “&” unifies two individuals together ;;; Unify these two sets together KM> (((a Cat) (a Dog)) && ((a Cat) (a Rabbit))) (_Cat1 _Dog2 _Rabbit3) ;;; Unify these two objects together KM> ((a Pet) & (a Fish)) (_Pet1) KM> (showme _Pet1) (_Pet1 has (instance-of (Pet Fish)))

  27. Inheritance and Unification: Example ;;; "Every big car has a large engine." KM> (every Big-Car has (parts ((a Engine with (size (*Large)))))) ;;; "Every powerful car has a powerful engine." KM> (every Powerful-Car has (parts ((a Engine with (power (*Lots)))))) ;;; "Suburbans are both big and powerful cars." KM> (Suburban has (superclasses (Big-Car Powerful-Car))) ;;; "What are the parts of a Suburban?" KM> (the parts of (a Suburban)) (COMMENT: (_Engine7 && _Engine8) unified to be _Engine7) (_Engine7) KM> (showme (thelast Engine)) (_Engine7 has (size (*Large)) (instance-of (Engine)) (power (*Lots)) (parts-of (_Suburban6))) Here KM decides the 2 engines are coreferential as (i) same class (or one’s classes subsumes the others’) (ii) unification doesn’t violate constraints Note result of unification: Engine is both large and has lots of power.

  28. Inheritance & Unification: Another Example • Again, the different contributing value sets are unified together. ;;; "Every person has two legs and a head." KM> (every Person has (parts ((a Head) (a Leg) (a Leg)))) (Person) ;;; "Fred has a leg." KM> (*Fred has (parts ((a Leg)))) (*Fred) ;;; "What are the parts of Fred?" ;;; [Note: two legs -- KM unifies one of the two legs on Person with the leg on Fred] KM> (the parts of *Fred) (_Leg9 _Head10 _Leg11)

  29. Constraints • Can attach constraints to a slot • constrains the allowed values on that slot • checked when that slot is queried • Two types: • value constraints: applies to each value in turn • (must-be-a Cat with (color (*Black))) • (mustnt-be-a Dog) • (<> 3) • (constraint ((the color of TheValue) = *Black)) • set constraints: applies to the set of values • (at-least 2 Leg) • (at-most 2 Leg) • (exactly 2 Leg) • (set-constraint ((the number of TheValues) = 3))

  30. Value Constraints • Checks each value in turn, when the slot is queried • keyword ‘TheValue’ denotes the value being tested • must-be-a constraints are enforced (not just checked) ;;; "A person's friends must all be of class Person." KM> (every Person has (friends ((must-be-a Person)))) ;;; "A person cannot marry him/herself." (<> means "cannot equal") KM> (every Person has (spouse ((<> Self)))) ;;; "Fred's spouse is himself." KM> (*Fred has (spouse (*Fred))) ;;; "Who is Fred's spouse?" [The constraint violation is detected at query time] KM> (the spouse of *Fred) ERROR! Constraint violation! Discarding value *Fred (conflicts with (<> *Fred))

  31. Set Constraints • Checks the entire set of values on a slot • Keyword ‘TheValues’ denotes the set being tested • Useful for at most / at least constraints ;;; "Every Airplane has exactly two wings." KM> (every Airplane has (parts ((exactly 2 Wing)))) (Airplane) ;;; General value constraints: TheValue denotes the value being checked. KM> (every Person has (leg-parts ((constraint (TheValue isa Leg)))) ;;; General set constraints: TheValues denotes the set of values being checked. KM> (every Person has (leg-parts ((set-constraint ((the number of TheValues) <= 2))))

  32. Defined Classes and Automatic Classification • Defining properties of a class: • IF object has these properties THEN it is in that class • If new info found about an instance, its classes are re-checked ;;; "A Mexican is a person who lives in Mexico, ;;; AND every person living in Mexico is a Mexican." KM> (every Mexican has-definition (instance-of (Person)) (lives-in (*Mexico))) ;;; "Every Mexican is happy." KM> (every Mexican has (mood (*Happy))) ;;; "Fred lives in Mexico.” [Note Fred is thus classified as a Mexican] KM> (*Fred has (lives-in (*Mexico))) (COMMENT: *Fred satisfies definition of Mexican,) (COMMENT: so changing *Fred's classes from (Person) to (Mexican)) (*Fred)

  33. Exercise 5. Create KM frames defining • the concept of a RedWine (a red wine) • a bachelor • a square

  34. Answers to Exercise 5a. (every RedWine has-definition (instance-of (Wine)) (color (*Red))) 5b. (every Bachelor has-definition (instance-of (Man)) (spouse ((exactly 0 Thing)))) 5c. (every Square has-definition (instance-of (Rectangle)) (length ((the width of Self))) (width ((the length of Self))))

  35. Text Generation • A special type of instance is a sequence • (:seq v1 … vn) • Text strings can be built up as a sequence of fragments KM> (every Remove has (text ((:seq "Remove" (the object of Self) "from" (the location of Self))))) ;;; "What is are the text for a remove of a sample from a box?” KM> (the text of (a Remove with (object ((a Sample))) (location ((a Box))))) ((:seq "Remove" _Sample14 "from" _Box15)) ;;; "Make a sentence from these fragments." KM> (make-sentence (the text of (a Remove with (object ((a Sample))) (location ((a Box)))))) ("Remove the sample from the box.")

  36. Slot Hierarchies • Slots can have subslots • Values of subslots are also values of the superslot • values “propogate up”) ;;; --- slot hierarchies --- ;;; "parts has subslots mechanical-parts." KM> (parts has (instance-of (Slot)) (subslots (mechanical-parts))) (parts) ;;; "Every airplane has a jet engine as one of its mechanical parts." KM> (every Airplane has (mechanical-parts ((a Jet-Engine)))) (Airplane) ;;; "What are the parts of an airplane?" KM> (the parts of (a Airplane)) (_Jet-Engine23)

  37. Situations • A situation is a partition of the knowledge base • Mainly to represent “snapshots” of the world at different times • Facts can differ in each situation • But each situation acquires all the facts of the global situation • Situations can be temporally ordered • Can define actions which change a situation, and thus perform simulation

  38. Situations: Fluents and Non-Fluents • Non-fluent: Fact is universally true • Inertial-fluent: Fact can propogate from one situation to the next • (Non-inertial) fluent: Fact does not propogate ;;; --- situations --- ;;; "Mike was born in 1963." KM> (*Mike has (birthdate (1963))) (*Mike) ;;; "birthdate is a constant (`non-fluent')" KM> (birthdate has (instance-of (Slot)) (fluent-status (*Non-Fluent))) ;;; "age may vary, but by default will remain unchanged." KM> (age has (instance-of (Slot)) (fluent-status (*Inertial-Fluent)))

  39. Situations: Projection (example) ;;; "Create a new situation." KM> (new-situation) (COMMENT: Changing to situation _Situation24) ;;; "In this situation, Mike is 27 years old." [_Situation24] KM> (*Mike has (age (27))) ;;; "What is Mike's age [in this situation]?" [_Situation24] KM> (the age of *Mike) (27) ;;; "Create and goto a new situation, which is the temporal successor of this one.” [_Situation24] KM> (next-situation) (COMMENT: Changing to situation _Situation25) ;;; "What is Mike's age [in this situation]?" [_Situation25] KM> (the age of *Mike) (COMMENT: Projected *Mike age = (27) from _Situation24 to _Situation25) (27)

  40. Situations: Projection (cont) • For “inertial fluents”, facts only propogate from one situation to the next if it is consistent to do so. [_Situation25] KM> (next-situation) (COMMENT: Changing to situation _Situation26) (_Situation26) ;;; "In this situation, Mike is 28 years old." [_Situation26] KM> (*Mike has (age (28))) (*Mike) ;;; "What is Mike's age [in this situation]?" ;;; [Note `27' is not projected, as `28' overrides it and this slot cannot ;;; have multiple values.] [_Situation26] KM> (the age of *Mike) (28)

  41. Querying Situations from the Global Situation • Can also query one situation from another • (in-situation <situation> query) • KM remembers each situation (so can query over them all) ;;; "Exit this situation, and return to the `global situation'." [_Situation26] KM> (global-situation) (COMMENT: Changing to situation *Global) (t) ;;; "In the last situation created, what was Mike's age?" KM> (in-situation (thelast Situation) (the age of *Mike)) (28) ;;; "In which situations was Mike 27?" KM> (allof (the all-instances of Situation) where (in-situation It ((the age of *Mike) = 27))) (_Situation25 _Situation24)

  42. Specifying Actions • Actions define how a event changes the world • They specify • preconditions: facts which must be true for the action to be performable • add-list, del-list: facts which become true/false as a result of the action • Facts are stated as “triples” (frame-slot-value structures) ;;; "Every switching on is an Action." KM> (Switching-On has (superclasses (Action))) (Switching-On) ;;; "Every switching on changes a switch's position from down to up." KM> (every Switching-On has (object ((a Switch))) (del-list ((:triple (the object of Self) position *Down))) (add-list ((:triple (the object of Self) position *Up)))) (Switching-On)

  43. Simulation • do-and-next will ‘execute’ an action in a situation • creates a new situation • updates the facts in it, according to the action ;;; "Create a new situation." KM> (new-situation) ;;; "There is a switch whose position [in this situation] is down." [_Situation27] KM> (*MySwitch == (a Switch with (position (*Down)))) (*MySwitch) ;;; "Create and enter the situation resulting from switching that switch on." [_Situation27] KM> (do-and-next (a Switching-On with (object (*MySwitch)))) (_Situation30) ;;; "What is the position [in this new situation] of that switch?" [_Situation30] KM> (the position of *MySwitch) (*Up)

  44. Simulation (cont) • again, previous situations can be queried and quantified over ;;; --- previous situations are preserved --- ;;; "In the previous situation, what was the position of the switch?" [_Situation30] KM> (in-situation (the prev-situation of (curr-situation)) (the position of *MySwitch)) (*Down) ;;; "In which situations was the switch down?" [_Situation30] KM> (allof (the all-instances of Situation) where (in-situation It ((the position of *MySwitch) = *Down))) (_Situation27)

  45. parts parts _ProtoFuselage07 connects _ProtoTwin-Jet-Airplane01 _ProtoWing03 _ProtoWing04 propulsion parts parts _ProtoEngine05 _ProtoEngine06 Prototypes • From a KM frame, we can compute a “graph” of objects and relationships which that frame asserts (i.e., a representative example of that frame) • Prototypes: Use that graph as the representation itself! (Twin-Jet-Airplane has (superclasses (Airplane))) (every Twin-Jet-Airplane has (parts ((a Fuselage) (a Wing with (parts ((a Engine))) (connects ((the Fuselage parts of Self)))) (a Wing with (parts ((a Engine))) (connects ((the Fuselage parts of Self)))) (propulsion ((the Engine parts of (the Wing parts of Self)))))

  46. _Twin-Jet-Airplane31 _ProtoTwin-Jet-Airplane01 parts parts propulsion parts parts _Fuselage37 propulsion connects _ProtoFuselage07 _Wing33 _Wing34 connects _ProtoWing03 _ProtoWing04 parts parts parts parts _Engine35 _Engine36 _ProtoEngine05 _ProtoEngine06 2. Unify clone with instance 1. Clone the prototype parts parts propulsion _Fuselage37 connects _Wing33 _Wing34 parts parts _Engine35 _Engine36 Reasoning with Prototypes • Inheritance is replace with “clone and unify” KB: (Twin-Jet-Airplane has (prototypes (_ProtoTwin-Jet-Airplane01))) Query: parts = ? _Twin-Jet-Airplane31

  47. KM: Some Outstanding Issues • Reasoning can get complex, and hard to debug • No full truth maintenance • Need for “defaults” – added during RKF • Heuristic unification can sometimes get it wrong • Knowledge engineer can provide guidance • Use of prototypes important for KM in Shaken • Explanations: • store which rule derived which fact • being extended to store the “proof tree” for a fact

More Related