Lesson · 40 min · Free
Knowledge Representation & Expert Systems
Knowledge Representation & Expert Systems Before deep learning dominated AI, the dominant paradigm was symbolic AI : encoding human knowledge in explicit, machine-readable structures that a program could inspect, rea
Knowledge Representation & Expert Systems
Before deep learning dominated AI, the dominant paradigm was symbolic AI : encoding human knowledge in explicit, machine-readable structures that a program could inspect, reason over, and explain. This lesson covers the two foundational ideas of that era — knowledge representation (how facts and relationships are stored) and expert systems (programs that apply that knowledge to make decisions). Both remain highly relevant in pharmacy and biotech, where regulatory and clinical decisions demand transparency that a black-box neural network often cannot provide. Knowledge representation comes in several classical forms. Production rules capture heuristic knowledge as IF–THEN statements (e.g., "IF eGFR < 30 AND patient takes metformin THEN reduce dose"). Frames and semantic networks organize entities into typed hierarchies with attributes and relations — the conceptual ancestors of today's biomedical ontologies such as SNOMED CT, RxNorm, the UMLS, ChEBI, and the Gene Ontology. These ontologies underpin drug interaction checkers, terminology mapping in electronic health records, and target-disease linkage in drug discovery databases. An expert system separates what is known from how it is used . Its architecture has four components: a knowledge base (rules and facts supplied by domain experts), a working memory (facts about the current case, e.g., a specific patient), an inference engine that applies rules to facts, and an explanation facility that traces which rules fired and why. Inference proceeds by forward chaining (data-driven: derive all conclusions supported by the facts) or backward chaining (goal-driven: work backward from a hypothesis to see if the facts support it). The landmark clinical system MYCIN (1970s) used backward chaining over ~600 rules to recommend antibiotic therapy and, critically, could justify every recommendation — a property modern deep models still struggle to match. The first example below shows a minimal semantic network — the simplest form of ontology. Facts are stored as subject–predicate–object triples, and a transitive lookup walks the is_a hierarchy to classify drugs. This is exactly the pattern scaled up in systems like RxNorm, where "metformin → biguanide → hypoglycemic agent" chains support automated coding and retrieval. # A lightweight biomedical ontology: facts as (subject, predicate, object) triples knowledge_graph = [ ("Metformin", "is_a", "Biguanide"), ("Biguanide", "is_a", "Antidiabetic"), ("Metformin", "treats", "Type2Diabetes"), ("Metformin", "contraindicated_in", "SevereRenalImpairment"), ("Warfarin", "is_a", "Anticoagulant"), ("NSAID", "is_a", "Analgesic"), ("Warfarin", "interacts_with", "NSAID"), ] def is_a(entity, category, graph): """Transitive classification: walk up the is_a hierarchy.""" for s, p, o in graph: if s == entity and p == "is_a": if o == category or is_a(o, category, graph): return True return False print(is_a("Metformin", "Antidiabetic")) # True (Metformin -> Biguanide -> Antidiabetic) print(is_a("Metformin", "Anticoagulant")) # False print(is_a("Warfarin", "Anticoagulant")) # True The second example implements a miniature rule-based expert system with forward chaining . Rules fire whenever their conditions are satisfied; newly derived facts are added to working memory and can trigger further rules, continuing until a fixed point is reached. Notice how the explanation log doubles as the system's justification — every conclusion is traceable to specific rules. # Mini expert system with forward chaining for clinical decision support class ExpertSystem: def __init__(self): self.facts = set() self.rules = [] self.log = [] def add_rule(self, conditions, conclusion, message): self.rules.append((conditions, conclusion, message)) def infer(self, patient_facts): self.facts = set(patient_facts) changed = True while changed: # repeat until no new facts are derived changed = False for conds, conclusion, msg in self.rules: if conclusion not in self.facts and conds.issubset(self.facts): self.facts.add(conclusion) self.log.append(msg) changed = True # new fact may enable more rules return self.log es = ExpertSystem() es.add_rule({"egfr_below_30", "on_metformin"}, "reduce_metformin", "eGFR < 30 with metformin: reduce dose or avoid (lactic acidosis risk).") es.add_rule({"on_warfarin", "on_nsaid"}, "ble
Watch the full lesson — free
This topic is part of Deep Generative Models: GANs, VAEs & Diffusion, a complete AI-narrated video course. Press play once and watch the entire lecture like a movie.
Start the course free →