Title: Knowledge Representation
1Knowledge Representation
2Production Rules
- Widely used in expert systems (Production
Systems) - Lead to some form of pattern directed inference
- Given the detection of some pattern in the
available information, use the information to try
and solve the problem. - System has
- Rule Base
- Working Memory
- Inference Mechanism (Interpreter)
- Explanation Facility
3Rule Base
- Stores permanent (problem-independent) knowledge.
- This knowledge is stored as production
rules/condition-action rules. - E.g.
- IF condition-1
- AND condition-2
- AND
- AND condition-m
- THEN action-1
- AND action-2
- AND
- AND action-n
4- The IF-part is also called the left-hand side or
antecedent. - The THEN-part is also called the right-hand side
or consequent. - The actions in the consequent usually involve
changes to working memory. - e.g. adding, deleting or modifying working memory
elements.
5Working Memory
- Contains temporary (problem-dependent) pieces of
knowledge, called working memory elements. - In general, working memory contains
- Information derived from the application of
production rules - Information input by the user
- Usually stored as
- object-value pairs
- object attribute value triplets
- object with attribute-value pairs
6Interpreter
- The interpreter works in a recognise-act cycle.
- Decides which rules are applicable given the
current state of working memory, and applies
(executes,fires) one or more. - If more than one rule is applicable, the
interpreter engages in conflict resolution to
choose one or more of the applicable rules for
execution.
7Example
- Rule Base
- IF (?Animal length ?Length)
- AND (gt ?Length 3)
- THEN (add (?Animal size big))
- IF (?Animal size big colour
grey) - THEN (add (?Animal type elephant))
- IF (?Animal length ?Length1 type
elephant ) - AND (?Animal2 length ?Length2)
- AND (gt ?Length2 ?Length1)
- THEN (add (?Animal2 type whale))
8Example (cont)
- Working Memory
- (animal1 name jumbo length 5 colour
grey) - (animal2 name moby-dick length 10)
- Can Conclude
-
- (animal1 type elephant)
- (animal2 type whale)
9Interpreter Control Strategies
- The interpreter can perform reasoning in either
of two ways - Forward Chaining
- Reasons forwards with the information in the
working memory (WM). - Matches the information in the WM with the
left-hand-side (antecedent ) of the rules. - Builds a picture of the complete situation
gradually, as data comes in. - Data driven
- Not directed, can generate many irrelevant
conclusions - More natural for production systems
10- Backward Chaining
- Uses goal driven reasoning.
- Starts with the goal and proceeds backwards to
generate subgoals - Matches the goal state with the right-hand-side
of the rules (consequent). - If a match is found, then the left hand side
becomes the new set of subgoals. - Sub-goals are solved by
- Matching against WM elements
- Backward chaining on them
- Asking the user to validate them
- More natural to people
11Example Rule Base
- Rule 1
- If The patient has a sore throat
- And Bacterial infection
- Then Patient has strep throat
- Rule 2
- If The patients temp is gt 100
- Then The patient has a fever
- Rule 3
- If The patient has been sick over a month
- And The patient has fever
- Then Patient has bacterial infection
12Example Forward vs Backward Chaining
- Forward Chaining
- Assume WM has the followings facts supplied by
the patient - Patients temperature 102
- Patient has been sick for two months
- Patient has a sore throat
- Backward Chaining
- Does a particular patient have strep throat?
13Conflict Resolution
- Conflict Set
- The set of rules that can be executed.
- Conflict Resolution
- How do you decide on a rule in the conflict set
for execution?
14Conflict Set Example
- Rule 1
- If The patient has a Sore Throat
- And Runny Nose
- Then Patient has a Cold
- Rule 2
- If The patient has a Sore Throat
- Then The patient has Strep Throat
- Rule 3
- If The patient has been sick over a month
- Then Patient should be given Antibiotics
- WM
- John has a sore throat
- John has a runny nose
- John has been sick for 2 months
15Determining the Conflict Set
- Straightforward unification is to inefficient
(many unifications). - Rete Algorithm addresses the problem.
- Rules often share conditions, so match each
condition only once. - WM changes slowly, so match only against new WMEs
16Rule Base if A(x) if A(x) if
A(x) and B(x) and B(y)
and B(x) and C(y) and D(x)
and E(x) then add D(x) then add E(x)
then delete A(x) Working
Memory A(1), A(2), B(2), B(3), B(4), C(5)
AD
add E
D
A(1), A(2)
C
add D
A
B
AB
C5
D(2)
B(2), B(3), B(4)
A(2) B(2)
E
delete A
17Conflict Resolution Strategies
- Textual Order
- Apply the first matching rule.
- Specificity
- Apply the most specific rule e.g. the one with
the most conditions, or the one with the most
bindings. - No Duplication
- Dont apply the same rule to the same data.
- Recency
- Apply the rule that matches the most recent
working memory element (WME). - Priority
- Associate rule with a priority value.
18Improving Efficiency of Conflict Resolution
- The following techniques can be used to improve
the efficiency of conflict resolution - Make conditions more specific
- Loss of independence of rules.
- Meta-Rules
- Use separate rules to prune or re-order the
conflict set. - Example
- IF the client is over 60
- AND there are rules mentioning high risk
- AND there are rules mentioning low risk
- THEN use the former before the latter
- Blackboard Architectures
19Blackboard Architectures
- Divide and conquer
- Divide rule memory into separate parts.
- Co-operating experts communicate with each other
via a blackboard - E.g. HEARSAY-II speech understander
- included lexical, syntactic, semantic experts
- Each expert is called a knowledge source (KS).
- There is a global blackboard, possibly
partitioned. - Each knowledge source accesses some partitions on
the blackboard. - Each knowledge source has a local interpreter,
which decides when it can in principle execute.
20- Whenever a KS can execute, it signals this to a
global interpreter, which decides on which KS
executes. - Thus, the basic recognise-act cycle becomes more
complicated - Each knowledge source runs its own recognise-act
cycle. - A KS which can execute signals this to the global
interpreter. - The global interpreter chooses a KS.
- The chosen KS fires.
- Apart from efficiency advantages over flat rule
sets, also epistemological advantages rules are
organised into sets of relevant rules.
21Explanation Facility
- The rule trace can be used to generate
explanations. - Why?
- Why are you asking me this question?
- Respond by printing the rule you are trying to
apply. - How?
- How did you reach this conclusion?
- Respond by printing the rule applied to add this
working memory element.
22Example Explanation
- Rule Base
- IF (?Animal is a mammal)
- AND (?Animal has black spots)
- AND (?Animal has a long neck)
- THEN (?Animal is a giraffe)
- IF (?Animal has hair)
- THEN (?Animal is a mammal)
- Assume that we are trying to establish whether
animal-1 is a giraffe.
23- Does animal-1 have hair
- WHY
- We are trying to establish whether animal-1 is a
mammal. - RULE02
- WHY
- We are trying to establish whether animal-1 is a
giraffe - RULE01
- YES
- Does animal-1 have black spots
- YES
- Does animal-1 have a long neck
- WHY
24- We are trying to establish whether animal-1 is a
giraffe. - We have already established that
- 1. animal-1 is a mammal
- 2. animal-1 has black spots
- Therefore, RULE01
- IF animal-1 has a long neck
- THEN animal-1 is a giraffe
- HOW 1
- We used RULE02 to establish that animal-01 is a
mammal - YES
- animal-1 is a giraffe
25Advantages of Production Rules
- Naturalness
- Experts use rule of thumb
- Uncertainty is easy to incorporate
- Uncertainty measure with each WME
- Uncertainty measure with each PR
- Combine these for new WMEs
- Rules are easy to understand
- Modularity
- Separation of rule memory and working memory.
- Separation of domain knowledge from interpreter.
- Rules never call each other directly.
26- Restricted Syntax
- Natural Language Interface
- Reflective program (e.g. consistency checkers)