Nexus Learn

Lecture 5: Knowledge Representation

Lecture Notes CS-511 Artificial Intelligence 9 min read Updated 8 Nov 2026

↓ Download notes (Word)

On this page
  1. Learning Outcomes
  2. 1. Knowledge
  3. 2. What Makes a Good Representation?
  4. 3. Semantic Networks
  5. 4. Frames and Production Rules
  6. 5. Common Mistakes
  7. Word Bank
  8. Summary
  9. Self-Check Questions

Learning Outcomes

SLO

After this lecture you will be able to...

CLO

Bloom

SLO 5.1

Differentiate data, information and knowledge, and describe a knowledge-based agent (TELL / ASK)

CLO2

C2 Understand

SLO 5.2

Classify knowledge as declarative, procedural, meta, heuristic or structural

CLO2

C2 Understand

SLO 5.3

Judge a representation using the four properties of a good KR system

CLO2

C2 Understand

SLO 5.4

Represent knowledge as a semantic network and use inheritance with exceptions

CLO2

C3 Apply

SLO 5.5

Represent knowledge as frames and production rules, and trace forward chaining

CLO2

C3 Apply

CLO2: Demonstrate first-order predicate calculus, logical reasoning and problem-solving using Prolog language.

1. Knowledge

§1.1 Data, information and knowledge

Slide L05-S06

Level

Meaning

Example

Data

Raw facts or numbers without context

38

Information

Data with context and meaning

The patient's temperature is 38 °C

Knowledge

Information combined with rules or experience so it can be used to decide

38 °C fever + body ache in October in Punjab → test for dengue

§1.2 Why intelligence needs knowledge

Slide L05-S07

Thirty years of AI research taught one clear lesson: intelligence requires knowledge. Knowledge is hard to handle because it is voluminous (very large), hard to describe exactly ('a little fever', 'good soil'), and constantly changing (new crop varieties, new virus strains, new tariffs). An AI system must represent objects, events, performance (how to do things), facts and meta-knowledge (knowledge about knowledge).

§1.3 Knowledge-based agents

Slide L05-S08

A knowledge base (KB) is a set of sentences written in a knowledge representation language. A knowledge-based agent uses two operations: TELL (add a sentence to the KB) and ASK (query the KB; the answer is inferred from what was told). In each cycle the agent TELLs the KB what it perceives, ASKs what action to take, and TELLs the KB which action it took. This is the declarative approach: we tell the agent what is true and let inference decide what to do.

Example: A crop advisor is TOLD 'leaves have yellow stripes' and 'the weather is cool'. ASKed 'which disease?', it infers 'yellow (stripe) rust of wheat' from its rules.

§1.4 Types of knowledge

Slide L05-S09

Type

Meaning

Example

Declarative

Knowing THAT - facts about objects and concepts

Wheat is sown in November.

Procedural

Knowing HOW - steps, rules, strategies

How to mix a pesticide spray.

Meta-knowledge

Knowledge ABOUT knowledge

Advice from the agriculture department is more reliable than a WhatsApp forward.

Heuristic

Rules of thumb from experts; usually right, not guaranteed

If cotton leaves curl early, expect a lower yield.

Structural

How concepts are related (is-a, part-of)

Cotton is a Kharif crop; a leaf is part of a plant.

2. What Makes a Good Representation?

§2.1 Four properties

Slide L05-S11

Property

Question

Example

Representational adequacy

Can it express all the knowledge needed?

An Excel table cannot easily say 'every crop needs water'.

Inferential adequacy

Can it derive new knowledge from old?

Cotton is a crop + crops need water → cotton needs water.

Inferential efficiency

Can it derive answers quickly?

An IS-A hierarchy finds inherited facts fast.

Acquisitional efficiency

Can new knowledge be added easily?

Add a new crop with one IS-A link.

No single method is best at all four, so AI uses several representations: logic, semantic networks, frames and production rules (slide L05-S12). Logic is covered in Lectures 6-9.

3. Semantic Networks

§3.1 Nodes and links

Slide L05-S14

A semantic network represents knowledge as a graph. Nodes are concepts or objects; labelled links (arcs) are relations such as IS-A (a kind of), HAS / PART-OF, and property links such as CAN or NEEDS. An IS-A link always points from the specific concept to the general one.

From

Link

To

Sparrow

IS-A

Bird

Ostrich

IS-A

Bird

Bird

IS-A

Animal

Bird

HAS

feathers

Bird

CAN

fly

Animal

DOES

breathe

Cotton

IS-A

Kharif crop

Wheat

IS-A

Rabi crop

Kharif crop

IS-A

Crop

Rabi crop

IS-A

Crop

Crop

NEEDS

water

§3.2 Inheritance and exceptions

Slide L05-S15

Inheritance: a node receives the properties of the nodes above it through IS-A links, so each fact is stored once, at the most general level. Does a sparrow have feathers? Sparrow → Bird (has feathers): yes. Exceptions: birds can fly by default, but the Ostrich node stores 'can fly = no'. The most specific value wins.

§3.3 Python demo: inheritance

Slide L05-S16

The program below is the one run in class; the output is its real run.

# A small semantic network with IS-A inheritance and exceptions

isa = {"Sparrow": "Bird", "Ostrich": "Bird", "Bird": "Animal",

"Cotton": "Kharif crop", "Wheat": "Rabi crop",

"Kharif crop": "Crop", "Rabi crop": "Crop"}

props = {

"Animal": {"breathes": True},

"Bird": {"has_feathers": True, "can_fly": True},

"Ostrich": {"can_fly": False}, # exception overrides the default

"Crop": {"needs_water": True},

"Kharif crop": {"sown_in": "summer (Apr-Jun)"},

"Rabi crop": {"sown_in": "winter (Nov-Dec)"},

"Cotton": {"product": "fibre"},

}

def lookup(node, prop):

"""Climb the IS-A links until the property is found (inheritance)."""

path = [node]

while node is not None:

if prop in props.get(node, {}):

return props[node][prop], ">".join(path)

node = isa.get(node)

if node: path.append(node)

return None, ">".join(path)

for node, prop in [("Sparrow", "can_fly"), ("Ostrich", "can_fly"), ("Ostrich", "breathes"),

("Cotton", "sown_in"), ("Cotton", "needs_water"), ("Wheat", "product")]:

value, path = lookup(node, prop)

print(f"{node} {prop} = {value} [{path}]")

Sparrow can_fly = True [Sparrow>Bird]

Ostrich can_fly = False [Ostrich]

Ostrich breathes = True [Ostrich>Bird>Animal]

Cotton sown_in = summer (Apr-Jun) [Cotton>Kharif crop]

Cotton needs_water = True [Cotton>Kharif crop>Crop]

Wheat product = None [Wheat>Rabi crop>Crop]

Notice 'Wheat product = None': the knowledge base only knows what it has been told.

§3.4 Strengths and weaknesses

Slide L05-S17

Strengths

Weaknesses

Easy to draw and understand

Link meanings are not standard (kind-of vs instance-of)

Inheritance stores facts once

Hard to express NOT, OR, ALL, SOME

Shows relations clearly

Large networks become slow and confusing

Basis of modern knowledge graphs (Google, Wikidata)

Multiple inheritance can create conflicts

4. Frames and Production Rules

§4.1 Frames

Slide L05-S19

A frame (Marvin Minsky, 1974) is a record for a typical (stereotyped) object or situation. It has slots (attributes) and fillers (values). A filler may be a value, a default (used unless something else is known), a range, or an attached procedure that computes the value when needed.

Slot

Filler

Kind of filler

Frame name

Dengue-Patient

-

IS-A

Patient

Link to a more general frame

Name

Ali Raza

Value

Age

21

Value (range 0-120)

Temperature

39 °C

Value

Platelets

85,000 per µL

Value

Ward

Medical ward

Default

Risk level

IF platelets < 100,000 THEN 'high'

Attached procedure (if-needed)

§4.2 Frame hierarchy and instances

Slide L05-S20

Generic frames are linked by IS-A, so slots and defaults are inherited; an instance frame describes one real object. Student (university UAF, degree BSCS by default) → BSCS-5th (semester 5, courses include CS-511, campus Burewala by default) → instance Hira (roll number, CGPA 3.4; university and campus inherited). In object-oriented programming a generic frame is like a class and an instance frame is like an object.

§4.3 Production rules and forward chaining

Slide L05-S21

A production system has three parts: rules (IF conditions THEN conclusion), a working memory of known facts, and an inference engine that repeatedly fires every rule whose conditions are all in working memory and adds its conclusion. Starting from facts and moving towards conclusions is called forward chaining (data-driven). Starting from a goal and working backwards is backward chaining (Lectures 8, 9 and 19).

# Forward chaining with production rules (IF conditions THEN conclusion)

rules = [

({"fever", "body_ache"}, "viral_infection_possible"),

({"viral_infection_possible", "dengue_season"}, "test_for_dengue"),

({"test_for_dengue", "low_platelets"}, "dengue_suspected"),

({"dengue_suspected"}, "refer_to_hospital"),

]

facts = {"fever", "body_ache", "dengue_season", "low_platelets"} # working memory

print("Start facts:", sorted(facts))

cycle = 0

while True:

fired = False

for conditions, conclusion in rules:

if conditions <= facts and conclusion not in facts:

cycle += 1

facts.add(conclusion)

print(f"Cycle {cycle}: IF {' AND '.join(sorted(conditions))} THEN {conclusion}")

fired = True

if not fired:

break

print("Facts in memory now:", len(facts))

print("Final conclusion:", "refer_to_hospital" in facts and "refer_to_hospital")

Start facts: ['body_ache', 'dengue_season', 'fever', 'low_platelets']

Cycle 1: IF body_ache AND fever THEN viral_infection_possible

Cycle 2: IF dengue_season AND viral_infection_possible THEN test_for_dengue

Cycle 3: IF low_platelets AND test_for_dengue THEN dengue_suspected

Cycle 4: IF dengue_suspected THEN refer_to_hospital

Facts in memory now: 8

Final conclusion: refer_to_hospital

§4.4 Comparing the methods

Slide L05-S22

Method

Structure

Best for

Weakness

Example

Semantic network

Nodes + labelled links

Relations, inheritance

Vague links; no NOT/ALL

Family tree, Knowledge Graph

Frames

Slots + fillers + defaults

Typical objects, records

Awkward for reasoning rules

Patient record

Production rules

IF ... THEN ...

Expert advice, diagnosis

Many rules interact

Crop-disease advisor

Logic

Exact sentences

Precise reasoning and proof

Hard for uncertain knowledge

Prolog (Lecture 9)

5. Common Mistakes

Slide L05-S24

Wrong idea

Correct idea

Data and knowledge are the same.

Knowledge = information + rules/experience that can be used to decide.

IS-A arrows point from general to specific.

IS-A points from the specific (Sparrow) to the general (Bird).

Every fact must be stored at every node.

Store it once at the most general level; inheritance passes it down.

A default value can never change.

A default is used only until a specific value overrides it.

Forward chaining starts from the goal.

Forward chaining starts from facts; backward chaining from the goal.

Word Bank

Word

Simple meaning

Example

Knowledge base (KB)

A store of facts and rules in a formal language

A crop-disease KB

Representation

A way of writing knowledge so a computer can use it

Semantic network, frame

Inference

Working out new facts from known ones

Cotton needs water

Inheritance

Getting properties from a more general concept

Sparrow inherits 'has feathers'

Exception

A specific value that overrides an inherited default

Ostrich cannot fly

Slot / filler

An attribute of a frame / its value

Age / 21

Default

A value assumed unless told otherwise

Ward = medical ward

Working memory

The facts currently known by a rule system

fever, body_ache

Forward chaining

Firing rules from facts towards conclusions

Symptoms → refer to hospital

Summary

  • Knowledge = information + rules/experience; a KB agent uses TELL and ASK.
  • Types: declarative, procedural, meta, heuristic, structural.
  • Judge a KR by representational and inferential adequacy, inferential and acquisitional efficiency.
  • Semantic networks: nodes + labelled links; inheritance with exceptions (most specific wins).
  • Frames: slots, fillers, defaults, procedures; hierarchy of generic and instance frames.
  • Production rules: IF-THEN rules + working memory + inference engine; forward chaining starts from facts.

Self-Check Questions

  1. Differentiate data, information and knowledge with one example. (see §1.1)
  2. What are TELL and ASK in a knowledge-based agent? (see §1.3)
  3. Classify: 'Bt cotton resists bollworm'; 'how to calibrate a sprayer'; 'if leaves curl early, expect low yield'. (see §1.4)
  4. Explain the four properties of a good KR system. (see §2.1)
  5. Draw a semantic network for Sparrow, Ostrich, Bird, Animal with one exception. (see §3.1-3.2)
  6. Why does the demo print 'Wheat product = None'? (see §3.3)
  7. Write a frame for a student with one default slot. (see §4.1-4.2)
  8. Trace forward chaining for the dengue rules when only fever and body ache are known. (see §4.3)
  9. Which representation would you use for a family tree, a patient record and a crop-disease advisor? (see §4.4)

Reading: Kaplan (2016) Chapter 2; Luger (2009) Chapter 7.

← All CS-511 material