Skip to content
Tutorials Center
My learning

Topics

Lesson 23 of 36 ยท Knowledge Representation

Knowledge Representation: Facts, Rules and Structures

Understand what knowledge is in expert systems, the main kinds of knowledge, and the main representation schemes, with runnable Python examples using triples and rules.

An expert system is only as good as the knowledge inside it, and that knowledge has to be written down in a form a program can use. Knowledge representation (KR) is the study of how to do that: which structures to use, what they can express, and how a program can reason over them.

Data says "the patient's temperature is 39.2". Knowledge says "a temperature above 38 means fever, and fever plus a stiff neck is dangerous". In this lesson you will separate the kinds of knowledge, learn what makes a representation good, and try three schemes in Python.

Kinds of knowledge

Kind Describes Example
Declarative What is true "A sparrow is a bird."
Procedural How to do something "To restart the pump: close valve A, then press reset."
Heuristic Rules of thumb from experience "If the engine misfires only when cold, check the choke first."
Structural How things are built or related "A computer has a CPU, memory and a disk."
Meta-knowledge Knowledge about knowledge "Check the cheapest test before the expensive one."
Uncertain / vague Imprecise or probabilistic facts "The patient is quite feverish." (fuzzy)

Expert systems lean heavily on heuristic knowledge, the practical shortcuts experts use and that textbooks leave out. Fuzzy logic is a tool for the last row: it represents vague statements with degrees of truth.

What makes a representation good

A representation scheme is judged on four things:

  • Representational adequacy: can it express everything the domain needs?
  • Inferential adequacy: can new knowledge be derived from it?
  • Inferential efficiency: can the derivation run fast enough?
  • Acquisitional efficiency: can experts add knowledge easily, and can others read and fix it?

No scheme wins everywhere. Logic is expressive but can be slow, frames are quick for lookups but weaker at inference, rules are easy to write but become tangled when there are thousands.

Main representation schemes

Rules IF condition THEN action
Semantic nets Nodes and labeled links
Frames Slots with defaults
Logic Formulas and proofs

Pick by what you need to express

1 / 2

Scheme 1: facts as triples

The simplest declarative structure is the triple: (subject, relation, object). A list of triples is a tiny knowledge base you can query by pattern.

Python A triple store with pattern queries

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The store answers lookup questions, but it does not know that a sparrow has feathers because a sparrow is a bird and birds have feathers. To get that, we need an inference mechanism.

Scheme 2: rules over the facts

A rule says "if these things are known, then conclude that". Here is a small forward pass that applies two general rules (inheritance of is_a and inheritance of has) until nothing new appears.

Python Deriving new facts with rules

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Now ("sparrow", "has", "feathers") and ("sparrow", "is_a", "animal") are known without anybody typing them. That is the value of representing knowledge in a structured way: the program can extend what it was told.

Scheme 3: the same knowledge, three ways

The sentence "A bird has feathers" can be stored in different shapes. Compare them:

Scheme Representation
Rule IF x is_a bird THEN x has feathers
Semantic net node bird --has--> node feathers; node sparrow --is_a--> node bird
Frame Bird {has: feathers, can: fly (default)} with Sparrow inheriting from it
Logic for all x: Bird(x) -> HasFeathers(x)

The next two lessons look at semantic networks and frames, then at logic and production rules in more detail.

Closed-world and open-world thinking

When the knowledge base does not contain a fact, can we conclude that it is false? A database says yes (closed-world assumption): if there is no row for the customer, the customer does not exist. Logic-based systems often say "unknown" (open-world assumption). Expert systems usually use the closed-world view for practicality, but you should know which one you chose, because a missing fact will mean different things.

Representing vagueness

None of the crisp schemes above can say "the patient is somewhat feverish". Fuzzy sets can: a membership value of 0.7 in the set Fever. A fuzzy rule such as IF temperature is high AND cough is severe THEN risk is high is one more kind of production rule, one whose conditions are degrees instead of booleans. Later lessons combine the two ideas.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which kind of knowledge is a rule of thumb gained from experience?

    Heuristics are experience-based shortcuts. Expert systems rely on them heavily.
  2. 2. What does inferential adequacy mean for a representation scheme?

    A scheme with inferential adequacy supports deriving conclusions from existing knowledge.
  3. 3. Under the closed-world assumption, what does a missing fact mean?

    The closed-world assumption treats anything not stored (or derivable) as false.
  4. 4. Why is fuzzy logic useful for knowledge representation?

    Fuzzy sets can represent statements such as 'somewhat feverish' that crisp true/false cannot.

Summary

  • Knowledge can be declarative, procedural, heuristic, structural, meta or uncertain.
  • Judge a scheme by representational adequacy, inferential adequacy, inferential efficiency and acquisitional efficiency.
  • Triples store facts; rules derive new facts from them; the same knowledge can be written as rules, nets, frames or logic.
  • Decide whether missing facts mean "false" (closed world) or "unknown" (open world).
  • Fuzzy sets add degrees of truth to the toolbox.

Next: Semantic Networks and Frames