Skip to content
Tutorials Center
My learning

Topics

Lesson 24 of 36 ยท Knowledge Representation

Semantic Networks and Frames

Learn semantic networks and frames: nodes, labeled links, inheritance, default values and exceptions, if-needed procedures, with runnable Python implementations you can edit.

Rules are good at "if this, then that". But much of what we know is about things and how they relate: a canary is a bird, a bird has wings, a wing is part of a body. Two classic structures capture this kind of knowledge: semantic networks, which draw it as a graph, and frames, which group the properties of one thing into a record with inheritance.

Both are older than modern databases, and you will recognize them in today's knowledge graphs and in object-oriented programming.

Semantic networks

A semantic network is a directed graph. Nodes are concepts or individuals; labeled edges are relations. The most important relations are is_a (a class link) and instance_of/has_part/color-style property links.

flowchart TD
  Tweety["Tweety"] -->|instance_of| Canary["Canary"]
  Canary -->|is_a| Bird["Bird"]
  Penguin["Penguin"] -->|is_a| Bird
  Bird -->|is_a| Animal["Animal"]
  Bird -->|has_part| Wings["Wings"]
  Bird -->|can| Fly["Fly"]
  Canary -->|color| Yellow["Yellow"]
  Penguin -->|can_not| Fly

A small semantic network. Reading a path from a node upward through is_a links is the basis of inheritance.

The strength of the network is inheritance: Tweety is a canary, a canary is a bird, so Tweety has wings. We did not store that fact on Tweety; we reached it by walking up the is_a chain. The weakness is that edges have no formal meaning beyond what the program does with them, which is why networks need discipline.

Python Property lookup through is_a links

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.

Two things to notice. First, the search returns the nearest value, so Penguin.can = False on the Penguin node overrides Bird.can = True. This is how semantic networks handle exceptions. Second, we did not need a separate rule for each fact.

Which questions a network answers well

  • Is X a kind of Y? Follow is_a links.
  • What properties does X have? Collect properties up the chain.
  • How are X and Y related? Find a path between the two nodes. Breadth-first search finds the shortest one.
Python How are two concepts related? Breadth-first path

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.

Frames

A frame (introduced by Marvin Minsky) represents a stereotyped object or situation as a record of slots. Each slot has a value and optionally extra information called facets:

  • a default value used when nothing more specific is known,
  • a type or range the value must satisfy,
  • an if-needed procedure that computes the value when asked,
  • an if-added procedure (a "demon") that runs when the value is set.

Frames connect through is_a (class to superclass) and instance_of links, so slots are inherited like fields in object-oriented classes. You can think of a frame system as an object system with first-class defaults and attached procedures.

Python A tiny frame system with defaults and demons

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 range_km slot is not stored; it is computed from the battery size when asked. Setting the battery fires a demon that reports the change. Frames let you attach these small behaviors right where the knowledge lives.

Networks versus frames

Semantic network Frame
Shape Graph of nodes and links Records of slots
Best at Relationships and paths Describing one object in depth
Inheritance Along is_a links Along is_a / instance_of, per slot
Defaults/procedures Awkward Built in
Modern relatives Knowledge graphs, RDF Classes, OWL descriptions

Pitfalls

  • Multiple inheritance. If a node has two parents with different values for the same slot, you must choose a rule (order of parents, or flag the conflict).
  • Meaning of links. An edge named has can mean "owns", "contains" or "is made of". Name your relations precisely and keep a list.
  • Exceptions. Overriding is convenient, but too many exceptions mean the hierarchy is wrong.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In a semantic network, how does Tweety inherit the property has_part wings?

    Inheritance follows the class links upward; the nearest definition wins.
  2. 2. What is the role of a default value in a frame slot?

    Defaults describe the typical case and can be overridden by more specific frames.
  3. 3. What is an if-needed facet?

    If-needed procedures compute values lazily; if-added procedures (demons) run on assignment.
  4. 4. Penguin has can: false while Bird has can: true. Which value does a lookup on Penguin return?

    Nearest-wins lookup handles exceptions: the more specific node overrides the general one.

Summary

  • A semantic network is a graph of concepts and labeled relations; inheritance follows is_a links.
  • Nearest-wins lookup supports defaults and exceptions.
  • Frames group an object's slots, with defaults, if-needed and if-added procedures, and inherit through class links.
  • Choose networks for relationships and paths, frames for rich descriptions of individual things.
  • Watch for multiple inheritance conflicts and vague relation names.

Next: Logic and Production Rules for Knowledge