# How Symbolic AI and Knowledge Representation Are Implemented in the Microsoft AI-for-Beginners Curriculum

> Learn how Microsoft AI-for-Beginners implements symbolic AI and knowledge representation using OAV triplets, inference engines, Experta, and RDF/OWL ontologies in Jupyter notebooks.

- Repository: [Microsoft/AI-For-Beginners](https://github.com/microsoft/AI-For-Beginners)
- Tags: deep-dive
- Published: 2026-08-06

---

**The Microsoft AI-for-Beginners curriculum teaches symbolic AI and knowledge representation through a progressive stack of object-attribute-value triplets, custom backward-inference engines, forward-chaining with Experta, and RDF/OWL ontologies, all executable in Jupyter notebooks.**

The `microsoft/AI-For-Beginners` repository dedicates Lesson 2 to symbolic AI, bridging classical knowledge representation theory with practical Python implementations. This module demonstrates how abstract concepts like semantic networks and production rules translate into working code through incremental notebook exercises. Learners progress from theoretical models to executable systems that perform automated reasoning over structured knowledge bases.

## Conceptual Foundations: From Data to Wisdom

The curriculum establishes theoretical grounding before diving into code. According to the source materials in [`lessons/2-Symbolic/README.md`](https://github.com/microsoft/AI-For-Beginners/blob/main/lessons/2-Symbolic/README.md) (lines 22-28), the lesson introduces a hierarchy of representation styles including **object-attribute-value (OAV) triplets**, **frames**, **procedural rules**, and **formal logic**. These abstraction layers map directly onto computer-usable data structures.

The curriculum utilizes the **DIKW pyramid** (Data, Information, Knowledge, Wisdom) and **semantic network** diagrams to illustrate how raw data transforms into actionable wisdom through structured relationships. This conceptual framework ensures learners understand *why* specific encoding schemes are chosen before implementing them.

## Building a Custom Expert System with Backward Inference

At the core of the hands-on instruction is a minimal expert-system shell built from scratch in `lessons/2-Symbolic/Animals.ipynb` (lines 24-42). This implementation demonstrates **backward inference** (goal-driven reasoning) through three fundamental Python classes:

- **`Ask`** – Prompts the user interactively for missing attribute values when the system cannot derive them from existing rules.
- **`If`, `AND`, `OR`** – Encode production-rule conditions as composable tree nodes, allowing complex logical expressions.
- **`KnowledgeBase`** – Maintains a rule dictionary and working memory, recursively evaluating the condition tree until a goal attribute is satisfied.

The system stores knowledge as nested dictionaries where OAV triplets trigger logical deductions. When `kb.get('animal')` is called, the engine works backward through the rule hierarchy, asking clarifying questions only when necessary.

```python

# Rule dictionary – OAV triplets encode knowledge

rules = {
    'mammal'   : If(OR(['hair', 'gives milk'])),
    'carnivor' : If(OR([AND(['sharp teeth','claws','forward-looking eyes']),
                       'eats meat'])),
    'animal:tiger' : If(['mammal','carnivor',
                         'color:red-brown','pattern:dark stripes'])
}
kb = KnowledgeBase(rules)
print(kb.get('animal'))   # → 'tiger' (after interactive asks)

```

## Forward Chaining with Experta and the Rete Algorithm

The same animal classification domain is re-implemented using **Experta**, a Python wrapper around the classic CLIPS engine, as shown in `lessons/2-Symbolic/Animals.ipynb` (lines 32-70). This section introduces **forward inference** (data-driven reasoning) where facts trigger rules iteratively until no new conclusions can be drawn.

Rules are declared using the `@Rule` decorator, binding Python methods to logical preconditions. Facts are asserted into a `KnowledgeEngine` instance, and the underlying **Rete algorithm** performs efficient pattern matching to determine which rules fire. This demonstrates industrial-strength production-rule systems compared to the educational backward-chaining implementation.

```python
from experta import *

class Animals(KnowledgeEngine):
    @Rule(OR(AND(Fact('sharp teeth'), Fact('claws'), Fact('forward looking eyes')),
            Fact('eats meat')))
    def carnivor(self):
        self.declare(Fact('carnivor'))

    @Rule(Fact('carnivor'), Fact('mammal'), Fact(color='red-brown'),
          Fact(pattern='dark stripes'))
    def tiger(self):
        self.declare(Fact(animal='tiger'))

ex = Animals()
ex.reset()
ex.declare(Fact('hair'), Fact('sharp teeth'), Fact('claws'), Fact('forward looking eyes'))
ex.run()        # prints: Animal is tiger

```

## Ontologies and the Semantic Web

The curriculum extends beyond production rules to formal ontologies using RDF/OWL standards. The [`lessons/2-Symbolic/README.md`](https://github.com/microsoft/AI-For-Beginners/blob/main/lessons/2-Symbolic/README.md) (lines 61-74) explains **URI-based triplet formats** where knowledge graphs express relationships as subject-predicate-object statements. For example, repository metadata appears as:

```turtle
@prefix dct: <http://purl.org/dc/elements/1.1/> .

<https://github.com/microsoft/AI-For-Beginners>
    dct:creator <http://soshnikov.com> ;
    dct:created "2022-01-01" .

```

The practical application appears in `lessons/2-Symbolic/FamilyOntology.ipynb`, where learners load a GEDCOM file (`data/tsars.ged`), construct a graph of familial relationships, and perform reasoning over the resulting ontology. This exercise connects historical data formats to modern semantic web technologies, demonstrating how symbolic AI handles real-world genealogical reasoning.

## Large-Scale Knowledge Bases: The Microsoft Concept Graph

The module concludes by connecting classroom concepts to industrial-scale implementations. As documented in [`lessons/2-Symbolic/README.md`](https://github.com/microsoft/AI-For-Beginners/blob/main/lessons/2-Symbolic/README.md) (lines 13-22), the curriculum integrates the **Microsoft Concept Graph**—a publicly available ontology containing millions of conceptual relationships. Learners can query this resource via REST API or download the complete dataset as a TSV file, exposing them to the challenges of scale, noise, and entity disambiguation present in production knowledge bases.

## Summary

- **Symbolic AI** in the curriculum progresses from abstract OAV triplets to executable inference engines.
- **Backward inference** is taught through a custom `KnowledgeBase` class that recursively evaluates rule trees in `Animals.ipynb`.
- **Forward chaining** leverages the Experta library's Rete algorithm for efficient production-rule execution.
- **Ontologies** are explored through RDF/OWL formats and practical genealogy exercises using GEDCOM data.
- **Scale** is demonstrated via integration with the Microsoft Concept Graph API.

## Frequently Asked Questions

### What is the difference between backward and forward chaining in the curriculum?

**Backward chaining** (goal-driven) starts with a hypothesis and works backward to verify supporting facts, implemented in the custom `KnowledgeBase` class that asks users for missing data. **Forward chaining** (data-driven) starts with known facts and derives new conclusions through rule firing, implemented using the Experta library's `KnowledgeEngine` and Rete algorithm.

### How does the curriculum explain the DIKW pyramid?

The curriculum maps the DIKW pyramid (Data, Information, Knowledge, Wisdom) onto specific representation formats in [`lessons/2-Symbolic/README.md`](https://github.com/microsoft/AI-For-Beginners/blob/main/lessons/2-Symbolic/README.md) (lines 22-28), showing how raw data becomes structured information through OAV triplets, evolves into knowledge via semantic networks, and culminates in wisdom through automated inference systems.

### What Python libraries are used for symbolic AI implementation?

The curriculum uses pure Python for the educational backward-inference engine, the **Experta** library (a CLIPS wrapper) for production-rule systems, and standard RDF libraries for ontology processing in the `FamilyOntology.ipynb` notebook.

### Can the custom expert system handle complex logical combinations?

Yes. The `If`, `AND`, and `OR` classes in `lessons/2-Symbolic/Animals.ipynb` (lines 24-42) allow arbitrary nesting of logical conditions, enabling rules that require multiple concurrent attributes or alternative pathways to satisfy a goal.