artificial intelligence – lecture 8130.243.105.49/~mbl/ai/lectures.2010/ai-8.pdf · 2011. 12....
TRANSCRIPT
Artificial Intelligence – Lecture 8
2
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Lecture plan
• AI in general (ch. 1)
• Search based AI (ch. 4)
• search, games, planning, optimization
• Agents (ch. 8)
• applied AI techniques in robots, software agents, ...
• Knowledge representation (ch. 2)
• semantic networks, frames, logic, resolution
• Expert systems (ch. 3)
• forward/backward chaining, uncertainty, baysian networks
• Natural language processing (ch. 5)
• Machine learning (ch. 7)
• version spaces, decision trees, classification, neural networks
3
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Structured knowledge representation
• How can we represent knowledge as data in our programs?• Semantic networks
• Frames
• Propositional logic
• Predicate logic
• ...
4
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Semantic networks
• Directed graph where: • nodes correspond to classes, instances or values.
• edges correspond to instance, subclass or attributes.
• Object oriented programming build on semantic networks!
5
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Common semantic relations
• No “official” standard exists.
• Common relations:• instance vs. isa: Often these two are differentiated
• haspart
6
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Reasoning on Semantic networks
• Assumption: general attributes (eg. livesin, has, ...) is closed under inheritance attributes (eg. isa, subclass, ...)
• Examples: • cat has vertebra since: cat isa mammal and mammal has vertebra
• mathias has vertebra since: ...
• There exists a path from X to Y consisting of zero or more isa steps and the has step as the last step.
7
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Semantic networks in python
• List of nodes
Nodes=[“Mathias”, “Bobby”, “Human”, “Cat”, ...]
• List of edges aka. “relations”
Edges=[(“isa”,”cat”,”mammal”),(“has”,”mammal”,”vertebra”) ... ]
• Propagating relations
def reason():
Facts, NewFacts, i = Edges, list(Edges), 1
while True:
for E in Facts:
if E[0] in Inheritable:
R,A,B = E
for N in Nodes:
if ("isa",N,A) in Facts and (R,N,B) not in Facts:
NewFacts.append((R,N,B))
print("%d: %s %s %s"%(i,N,R,B))
if Facts == NewFacts:
break;
Facts=NewFacts ; i=i+1
8
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Semantic networks in python
>>> reason()
1: cat has vertebra
1: human has vertebra
1: whale has vertebra
1: Bobby has fur
1: Bijou has fur
2: Bobby has vertebra
2: Bijou has vertebra
2: Mathias has vertebra
9
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Nonbinary relations in semantic networks
• Nonbinary relations: convert the relation into an object• Called reification in logics
• eg. “Mathias gave cat food to Bobby”
10
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Nonbinary relations in semantic networks
• Reasoning over reified relations, example rule:• If [object,X,R1] and [isa,X,Y] then:
• create new node R2
• add [object,Y,R2]
• for each [P,W,R1] where W != X and W != Y: add [P,W,R2]
• Same isa path(s), shows that Mathias gave food to Bobby, or to a cat, or that bobby was given food by a human.
11
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Semantic networks
• Semantic networks allows us to represent relationships between entities
• Semantic networks allows us to propagate relationships between entities (reason)
12
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Inference by association
• What is the common factor between sk1047 and rusty?• Both haspart wing, and both cando fly
• If two entities X,Y have the same relation R to an entity Z, ie. if X R Z and Y R Z then they are associated.
13
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Default values
• Inheritance of properites through isa can be contradicted by direct links.
• Only treat inheritance as default values
14
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Wordnet
• Lexical database over English language• Nouns, verbs, adjectives and adverbs
• Grouped into cognitive synonyms (synsets)
• Relations (eg. hyponym's and hypernym's) between words
Synsets
HyponymsHypernyms
15
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Wordnet
• Wordnet is a semantic network
• Freely available, download online
• 150.000 words organised in 115.000 synsets (meanings)
• Relations
• hypernyms:
• Nouns: Y is a hypernym of X if every X is a (kind of) Y
• Verbs: the verb Y is a hypernym of the verb X if the activity X is a kind of Y (cf. troponym)
• hyponyms: Y is a hyponym of X if every Y is a (kind of) X
• coordinate terms: Y is a coordinate term of X if X and Y share a hypernym
• holonym: Y is a holonym of X if X is a part of Y
• meronym: Y is a meronym of X if Y is a part of X
• entailment: the verb Y is entailed by X if by doing X you must be doing Y
• adjectives: related nouns, similar to, participle of verb
• adverbs: root adjectives
16
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Frames
• More advanced than semantic networks
• A frame is a collection of attributes (slots) and values that describe some entity
• Constraints on attributes
• Procedural attachments: Associated function to slots
• Generic frames (eg. classes) vs. instances (eg. objects)
Team;
* hasmember: Human
Hockeyteam;
isa: Team
Largeteam;
isa: Team
(> 10) hasmember: Human
LHC;
instanceof: {Largeteam, Hockeyteam}
hasmember: { .... }
17
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Frames : inheritance
• Proper inheritance• Slots and values inherited by subclass and instances
• Inheritance with exceptions• Overriding values given from superclass
• Multiple inheritance• Inheriting from multiple parents
• Problem with order of inheritance
18
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Frames : example
Animal:
Flies: False
Alive: True
Mammal:
isa: Animal
Legs: 4
Cats:
isa: Mammal
Bird:
isa: Animal
Flies: True
Wings: True
Penguin:
isa: Birds
Flies: False
Bill:
instanceof: {Cat}
Friends: {Opus}
Opus:
instanceof: {Penguin}
Friends: {Bill}
19
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Frames : metaslots
• Frames that describe other slots
• Example
Spotty:
instanceof: dog
owner: mathias
Owner:
value: person
inverse: owns
Conclusions:
person(mathias)
owns(mathias,spotty)
20
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Frames : Procedural attachments
• Functions attached to metaslots• trigger when adding/removing/replacing slots
• trigger when needing (but not having) a slot
• ...
21
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Cyc
• Cyc
• Large AI project to create “complete” database of common sense knowledge
• Goal: enable human like reasoning
• Technologies
• Representation language
• Knowledge base
• Inference mechanism
• Natural language processing
• Developer tools
22
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
OpenCyc
• OpenCyc• Free subset of knowledge base
• Free subset of tools, inference mechanism ...
• Uses same representational (CycL) language
• Links with WordNet• Which Cyc concept correspond to which word?
• Links with Wikipedia• Link concepts with articles, browse Wikipedia with OpenCyc
tools (find common concepts etc)
• ...
23
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Lecture plan
• AI in general (ch. 1)
• Search based AI (ch. 4)
• search, games, planning, optimization
• Agents (ch. 8)
• applied AI techniques in robots, software agents, ...
• Knowledge representation (ch. 2)
• semantic networks, frames, logic, resolution
• Expert systems (ch. 3)
• forward/backward chaining, uncertainty, baysian networks
• Natural language processing (ch. 5)
• Machine learning (ch. 7)
• version spaces, decision trees, classification, neural networks
24
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Logic
• What is logic?• The study of inference – how new assertions can be
produced from already established ones
• Requirements• Representation (syntax) and interpretation (semantics)
• Basic axioms (something to start reasoning with)• cf. René Descartes (cogito ergo sum)
• An inference mechanism• Soundness (truthpreserving)
• Complete
25
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Logic – the AI dream of the 60's
• Logic allows us to express everything “formally”
• Logic also allows us to prove theorems based on given information• Can we exploit this to build the ultimate automated
reasoning systems?
• Different logics allow different representation and inference mechanisms• Reasoning about propositions
• Reasonings about predicates, quantifiers, ...
• Representing time, and changes over time
• ...
26
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Example:
The following knowledge is given :
1. Marcus was a man.
2. Marcus was a Pompeian.
3. All Pompeians were Romans.
4. Caesar was a ruler.
5. All Romans were either loyal to Caesar or hated him.
6. Everyone is loyal to someone.
7. People only try to assassinate rulers to whom they are not loyal.
8. Marcus tried to assassinate Caesar.
Can we automatically answer the following questions? Was Marcus loyal to Caesar?
Did Marcus hate Caesar?
27
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Conversion to the First Order Logic:
Representation of facts:
1. Marcus was a man.man(Marcus)
2. Marcus was a Pompeian.Pompeian(Marcus)
4. Caesar was a ruler.ruler(Caesar)
8. Marcus tried to assassinate Caesar.try_assassinate(Marcus, Caesar)
28
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
5. All Romans were either loyal to Caesar or hated him.
Conversion to the First Order Logic (2):
General representation (representation of rules):
3. All Pompeians were Romans.∀∀x Pompeian(x)x Pompeian(x) →→ Roman(x) Roman(x)
6. Everyone is loyal to someone.∀∀xx ∃∃yy loyal_to(x,y)loyal_to(x,y)
7. People only try to assassinate rulers to whom they are not loyal.
∀∀xx∀∀y person(x)y person(x) ∧∧ ruler(y)ruler(y) ∧∧ try_assassinate(x,y)try_assassinate(x,y) →→ ~loyal_to(x,y)~loyal_to(x,y)
∀∀x Roman(x) x Roman(x) →→ loyal_to(x,Caesar) loyal_to(x,Caesar) ∨∨ hates(x,Caesar)hates(x,Caesar)
29
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Prove that he did:Prove that he did:
The “theorem” ?
Was Marcus loyal to Caesar?Was Marcus loyal to Caesar?
Did Marcus hate Caesar?Did Marcus hate Caesar?
hates(Marcus,Caesar)hates(Marcus,Caesar)
Try, for example, to prove that he was not Try, for example, to prove that he was not :: ~loyal_to(Marcus,Caesar)~loyal_to(Marcus,Caesar)
30
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Logic
• Interpretation
• Truth assignments to propositions “a possible world”
• Not neccessarily the world
• Valid sentence
• True in every interpretation
• Satisfiable sentence
• True in some interpretation
• Unsatisfiable sentence
• True in no interpretation
31
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Propositional logic (sv. satslogik)
• Syntax
32
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Propositional logic: Well formed formulas
33
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Propositional logic: interpretation
• Interpretation• An assignment of true / false to each propositional
variable
• Indirectly gives true / false to all other formulas
34
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Interpretation:
pp qq ~p~p p p ∧∧ q q p p ∨∨ q q p p →→ q q p p ↔↔ q qTT TTTT FFFF TTFF FF
FF TT TT TT TTFF FF TT FF FFTT FF TT TT FFTT FF FF TT TT
Truth tableTruth table
• A function that assigns truth value to each “atomic” formula• Also provides (indirectly) truth values for each wff
35
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Model
p p →→ ~ q ~ q
ppq q ∨∨ r r
SSExample:Example:
p p →→ ~q ~q q q ∨∨ r rTT TT TT
pppp qq rrTT FF TT
Model:Model:
• Given a set of formulas S• A model of S, is an interpretation that makes all
formulas of S true
36
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Logical entailment:
p p →→ ~ q ~ q
ppq q ∨∨ r r
SSExample:Example:
F:F:
r r →→ p ppp qq rrTT FF TT
(the only) Model:(the only) Model:
r r →→ p pTT
• Given a set of formulas S and a formula F:• F is logically entailed by S ( S |= F ), if all models of S
also make F true.
37
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Propositional logic: Example 1
• Use a truth table to figure out in which interpretations the following formula is true
• Thus, that formula is a valid statement (since it is always true)
38
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Inference rules for prop. logic
39
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Propositional logic: Example 2
40
● KnowledgeRepresentation
● Semantic Networks
● Prop. Logic
Examples
• 1.Given X (Y (¬X ⇒ ⇒ ∧ Z) and Y, prove ¬X
• 2. Given A (B⇒ ∨C) and C ¬A, prove ¬A⇒ ∨B