首页 理论 架构 工程 文档 白皮书 著作 研究 案例 下载 博客 关于 开始使用 →

第71章 LearningEngine

第二十三篇 Learning Engine

第71章 LearningEngine

1. 学习任务

LearningEngine 的第一职责,是接收并建立一个明确的学习任务(Learning Task)

学习不是简单地把输入信息保存下来,而是围绕一个目标,对信息、经验、反馈和已有知识进行处理。

基本结构:

LearningTask
{
    id
    type
    target
    input
    goal
    condition
    source
    state
    created_at
    updated_at
}

例如:

LearningTask
{
    id: "LT001",
    type: "KNOWLEDGE_UPDATE",
    target: "DeliveryService",
    input: "深圳到香港家具送货上门",
    goal: "获取服务相关知识",
    condition: "当前知识需要补充",
    source: "user",
    state: "NEW"
}

学习任务可以包括:

INFORMATION_LEARNING
FACT_LEARNING
RELATION_LEARNING
RULE_LEARNING
EXPERIENCE_LEARNING
KNOWLEDGE_UPDATE
ABILITY_UPDATE
MEMORY_UPDATE

学习任务的基本生命周期:

NEW
 ↓
READY
 ↓
PROCESSING
 ↓
ANALYZING
 ↓
EXTRACTING
 ↓
UPDATING
 ↓
COMPLETED

如果条件不足、信息冲突或无法确认,则可以进入:

UNCERTAIN
CONFLICT
FAILED

因此:

LearningTask ≠ Information
LearningTask ≠ Knowledge
LearningTask = 对学习过程的任务定义

2. 学习条件

LearningEngine 不能看到任何信息都直接进行学习。

首先需要判断学习条件(Learning Condition)

学习条件决定:

  • 是否允许学习
  • 学习什么
  • 为什么学习
  • 当前知识是否已经存在
  • 是否存在变化
  • 是否存在冲突
  • 是否需要更新

基本结构:

LearningCondition
{
    object
    property
    relation
    state
    condition
    source
    validity
}

例如:

LearningCondition
{
    object: "DeliveryService",
    property: "destination",
    condition: "new_value_exists",
    source: "user",
    validity: "valid"
}

可以形成:

输入信息
   ↓
学习条件检查
   ↓
满足?
 ┌───┴───┐
是       否
↓        ↓
继续学习  NO_CHANGE

学习条件状态:

TRUE
FALSE
UNKNOWN
CONFLICT

特别需要区分:

FALSE ≠ UNKNOWN
UNKNOWN ≠ NO_CHANGE
CONFLICT ≠ FALSE

例如:

条件:是否存在新的家具配送目的地?

FALSE

表示已经确定没有。

而:

UNKNOWN

表示当前信息不足以判断。


3. 经验分析

LearningEngine 的重要输入之一是 Experience

前面第69章已经定义:

Experience
=
Condition
+
Action
+
Process
+
Result
+
Feedback

LearningEngine 首先需要对经验进行分析,而不是直接把经验变成知识。

基本流程:

Experience
 ↓
Experience Validation
 ↓
Condition Analysis
 ↓
Action Analysis
 ↓
Result Analysis
 ↓
Feedback Analysis
 ↓
Experience Evaluation

例如:

Experience
{
    task: "furniture_delivery",
    condition: {
        origin: "Shenzhen",
        destination: "HongKong"
    },
    action: {
        type: "DELIVERY"
    },
    result: {
        state: "SUCCESS"
    },
    feedback: {
        state: "SUCCESS"
    }
}

LearningEngine 可以提取:

条件:
深圳 → 香港

行为:
家具配送

结果:
成功

反馈:
成功

但是不能立即得出:

深圳到香港家具配送一定成功

因为:

一次 Experience
        ↓
只能形成候选知识

而不是自动形成稳定知识。


4. 模式提取

经验经过分析以后,LearningEngine 需要寻找其中可以重复利用的模式(Pattern)

模式提取的核心不是复制经验,而是寻找:

重复出现的对象
重复出现的属性
重复出现的关系
重复出现的条件
重复出现的行为
重复出现的结果

例如存在多条经验:

Experience 001
深圳 → 香港
家具 → 配送
结果 → 成功

Experience 002
深圳 → 香港
家电 → 配送
结果 → 成功

Experience 003
深圳 → 香港
个人物品 → 配送
结果 → 成功

LearningEngine 可以发现:

共同条件:

Origin = Shenzhen
Destination = HongKong
Service = Delivery

形成候选模式:

Pattern
{
    condition: {
        origin: "Shenzhen",
        destination: "HongKong",
        service: "Delivery"
    },
    occurrence: 3,
    results: {
        success: 3
    }
}

模式可以包括:

对象模式

Object Pattern

属性模式

Property Pattern

关系模式

Relation Pattern

状态模式

State Pattern

行为模式

Behavior Pattern

条件—结果模式

Condition → Result

例如:

Pattern

IF
destination = HongKong
AND
service = Delivery

THEN
delivery_service_exists = TRUE

模式仍然属于候选结构

因此:

Pattern ≠ Knowledge

还需要经过验证和知识更新。


5. 知识更新

模式经过验证以后,LearningEngine 才可以进入Knowledge Update

知识更新主要包括:

CREATE
UPDATE
CONFIRM
INVALIDATE
ARCHIVE
NO_CHANGE
CONFLICT

例如已有:

Knowledge

DeliveryService
origin = Shenzhen
destination = HongKong

新的学习结果:

origin = Shenzhen
destination = HongKong
service = DoorToDoor

LearningEngine 不应该把旧知识全部删除,而应该进行结构化更新:

旧知识
    ↓
比较
    ↓
新信息
    ↓
验证
    ↓
知识更新

形成:

Knowledge
{
    object: "DeliveryService",
    properties: {
        origin: "Shenzhen",
        destination: "HongKong",
        service: "DoorToDoor"
    },
    state: "ACTIVE"
}

如果出现冲突:

旧知识:
destination = HongKong

新信息:
destination = Guangzhou

不能直接覆盖。

应该形成:

Knowledge Conflict
{
    old_value: "HongKong",
    new_value: "Guangzhou",
    source_old: "...",
    source_new: "...",
    state: "CONFLICT"
}

然后交给后续验证、推理或人工确认机制。

因此:

LearningEngine
      ↓
Knowledge Validation
      ↓
Knowledge Update

而不是:

New Information → overwrite Knowledge

6. 能力更新

前面已经定义:

Knowledge = 能力资源

因此知识更新完成以后,可以进一步判断是否需要更新Ability Resource

基本关系:

Learning
   ↓
Knowledge
   ↓
Ability Resource
   ↓
Ability

例如学习到:

Knowledge:

DeliveryService
origin = Shenzhen
destination = HongKong
service = DoorToDoor

那么可以形成能力资源:

AbilityResource
{
    name: "HongKongDoorToDoorDelivery",
    knowledge: [
        "Shenzhen",
        "HongKong",
        "DoorToDoor",
        "DeliveryService"
    ],
    state: "AVAILABLE"
}

能力更新类型:

CREATE
EXTEND
UPDATE
CONFIRM
DISABLE
INVALIDATE

需要注意:

Knowledge ≠ Ability

知识是资源:

知道什么

能力是应用结构:

能够利用什么

例如:

Knowledge:
HongKong = 香港

Ability:
LocationRecognition

又例如:

Knowledge:
Shenzhen → HongKong → Delivery

Ability:
DeliveryServiceRecognition

LearningEngine 的职责是:

学习
 ↓
知识更新
 ↓
判断相关能力资源是否需要更新

而不是在 LearningEngine 中直接执行实际行为。


7. 记忆更新

学习完成以后,需要更新 Memory。

这是 LearningEngine 的另一个重要出口。

基本流程:

LearningResult
      ↓
Memory Evaluation
      ↓
Memory Update

更新对象可以包括:

ShortMemory
LongMemory
FactMemory
ExperienceMemory

例如:

新的事实
↓
FactMemory
新的长期对象知识
↓
LongMemory
新的经历
↓
ExperienceMemory
当前任务信息
↓
ShortMemory

Memory Update 不能简单理解为:

保存文件

而是:

检查
 ↓
比较
 ↓
确认
 ↓
更新
 ↓
记录状态

例如:

Memory Update
{
    memory_id: "M001",
    object: "DeliveryService",
    changes: {
        service: {
            old: null,
            new: "DoorToDoor"
        }
    },
    state: "UPDATED"
}

如果没有新内容:

NO_CHANGE

如果发生冲突:

CONFLICT

如果已有知识失效:

INVALID

因此:

Learning
 ├──→ Knowledge Update
 ├──→ Ability Update
 └──→ Memory Update

8. 学习历史

LearningEngine 必须保存自己的Learning History

因为学习本身也是一个需要追踪的过程。

基本结构:

LearningHistory
{
    id
    task_id
    input
    condition
    experience
    pattern
    knowledge_changes
    ability_changes
    memory_changes
    state
    source
    started_at
    completed_at
}

例如:

LearningHistory
{
    id: "LH001",
    task_id: "LT001",

    input: "深圳到香港家具送货上门",

    condition: "new_information",

    experience: {
        matched: 3
    },

    pattern: {
        origin: "Shenzhen",
        destination: "HongKong",
        service: "DoorToDoor"
    },

    knowledge_changes: {
        created: 1,
        updated: 1
    },

    ability_changes: {
        updated: 1
    },

    memory_changes: {
        updated: 2
    },

    state: "SUCCESS"
}

学习历史可以回答:

什么时候学习?
学习了什么?
为什么学习?
依据是什么?
发现了什么模式?
更新了什么知识?
更新了什么能力?
更新了什么记忆?
学习是否成功?

因此:

LearningHistory

本身也是一种长期认知记录。


9. 完整学习案例

下面使用一个完整案例说明 LearningEngine。

假设 ICAI 获得新的信息:

“深圳到香港家具可以提供送货上门服务。”

第一步:建立学习任务

LearningTask
{
    id: "LT001",
    type: "KNOWLEDGE_UPDATE",
    target: "DeliveryService",
    input: "深圳到香港家具可以提供送货上门服务。",
    goal: "更新配送服务知识",
    state: "NEW"
}

进入:

LearningTask
      ↓
READY

第二步:检查学习条件

已有 Memory:

DeliveryService
{
    origin: "Shenzhen",
    destination: "HongKong"
}

新信息增加:

service = DoorToDoor
object = Furniture

比较:

Existing Knowledge
        +
New Information
        ↓
Comparison

发现:

service = DoorToDoor

属于新的知识属性。

因此:

LearningCondition = TRUE

第三步:经验分析

系统读取相关 Experience:

Experience 001
Shenzhen → HongKong → Delivery → SUCCESS

Experience 002
Shenzhen → HongKong → Delivery → SUCCESS

Experience 003
Shenzhen → HongKong → Delivery → SUCCESS

LearningEngine 进行:

Experience Query
        ↓
Experience Matching
        ↓
Experience Analysis

得到:

Repeated Condition:

origin = Shenzhen
destination = HongKong
service = Delivery

第四步:模式提取

得到候选模式:

Pattern
{
    origin: "Shenzhen",
    destination: "HongKong",
    service: "DoorToDoor",
    object: "Furniture"
}

进一步检查:

Condition
+
Repeated Experience
+
Current Information

形成:

Candidate Knowledge

第五步:知识更新

已有:

DeliveryService
origin = Shenzhen
destination = HongKong

更新:

DeliveryService
{
    origin: "Shenzhen",
    destination: "HongKong",
    service: "DoorToDoor",
    object: "Furniture",
    state: "ACTIVE"
}

产生:

KnowledgeUpdate = SUCCESS

第六步:能力更新

根据新的知识资源,检查:

AbilityResource

发现原有:

DeliveryRecognition

可以扩展:

FurnitureDeliveryRecognition

形成:

AbilityResource
{
    name: "FurnitureDeliveryRecognition",
    knowledge: [
        "Furniture",
        "Shenzhen",
        "HongKong",
        "DoorToDoor"
    ],
    state: "AVAILABLE"
}

第七步:记忆更新

更新:

LongMemory
FactMemory
ExperienceMemory

例如新增事实:

Fact
{
    subject: "FurnitureDelivery",
    predicate: "destination",
    value: "HongKong",
    state: "ACTIVE"
}

并更新长期对象:

DeliveryService
service = DoorToDoor

第八步:生成学习结果

LearningResult
{
    id: "LR001",

    input: "深圳到香港家具可以提供送货上门服务。",

    type: "KNOWLEDGE_UPDATE",

    knowledge: {
        object: "DeliveryService",
        service: "DoorToDoor",
        object_type: "Furniture"
    },

    changes: {
        knowledge: "UPDATED",
        ability: "UPDATED",
        memory: "UPDATED"
    },

    state: "SUCCESS",

    source: "user"
}

第九步:记录学习历史

LearningHistory
{
    id: "LH001",
    task_id: "LT001",

    input:
        "深圳到香港家具可以提供送货上门服务。",

    experience:
        "3 related experiences",

    pattern:
        "Shenzhen → HongKong → DoorToDoor",

    knowledge_changes:
        "DeliveryService updated",

    ability_changes:
        "FurnitureDeliveryRecognition updated",

    memory_changes:
        "FactMemory + LongMemory updated",

    state:
        "SUCCESS"
}

LearningEngine 完整运行模型

将本章全部内容连接起来:

Information
      ↓
LearningTask
      ↓
LearningCondition
      ↓
Experience Analysis
      ↓
Pattern Extraction
      ↓
Pattern Validation
      ↓
Knowledge Update
      ↓
Ability Update
      ↓
Memory Update
      ↓
LearningResult
      ↓
LearningHistory

如果把前面的认知系统全部连接起来,则形成:

Information
    ↓
Perception
    ↓
Cognition
    ↓
Understanding
    ↓
Memory
    ↓
Reasoning
    ↓
Decision
    ↓
Behavior
    ↓
Action
    ↓
Feedback
    ↓
Experience
    ↓
LearningEngine
    ↓
Knowledge
    ↓
Ability Resource
    ↓
Memory Update
    ↓
Reasoning

这就形成了一个完整的认知—行为—反馈—学习循环


LearningEngine 核心结构

可以将 LearningEngine 抽象为:

LearningEngine
{
    TaskManager
    ConditionChecker
    ExperienceAnalyzer
    PatternExtractor
    KnowledgeUpdater
    AbilityUpdater
    MemoryUpdater
    HistoryRecorder
}

对应关系:

LearningEngine
│
├── LearningTask
│
├── LearningCondition
│
├── ExperienceAnalyzer
│
├── PatternExtractor
│
├── KnowledgeUpdater
│
├── AbilityUpdater
│
├── MemoryUpdater
│
└── LearningHistory

LearningEngine 与其他 Engine 的区别

Engine 核心职责
PerceptionEngine 获取并结构化信息
CognitionEngine 理解对象、属性、关系、状态
MatchingEngine 判断对应关系
ReasoningEngine 根据事实、规则形成结论
DecisionEngine 选择行动
BehaviorManager 管理行为执行
ActionExecutor 执行具体动作
LearningEngine 从信息、反馈、经验中获取并更新知识
Memory 保存认知资源
Ability 应用知识和方法

最重要的是:

Perception = 获取
Cognition = 理解
Reasoning = 推导
Decision = 选择
Action = 执行
Experience = 经历
Learning = 获取知识
Knowledge = 能力资源
Memory = 保存
Ability = 应用

本章核心模型

学习任务
   ↓
学习条件
   ↓
经验分析
   ↓
模式提取
   ↓
模式验证
   ↓
知识更新
   ↓
能力更新
   ↓
记忆更新
   ↓
学习结果
   ↓
学习历史

完整闭环:

Information
      ↓
Perception
      ↓
Cognition
      ↓
Understanding
      ↓
Reasoning
      ↓
Decision
      ↓
Behavior
      ↓
Action
      ↓
Feedback
      ↓
Experience
      ↓
LearningEngine
      ↓
Knowledge
      ↓
Ability Resource
      ↓
Memory Update
      ↓
Reasoning

本章核心定义

LearningEngine 是 SAI/ICAI 中负责组织学习任务、检查学习条件、分析经验、提取可重复模式、验证并更新知识资源,同时根据学习结果更新能力资源和记忆,并记录完整学习历史的学习运行引擎。

核心公式:

LearningEngine
=
Task
+
Condition
+
Experience Analysis
+
Pattern Extraction
+
Knowledge Update
+
Ability Update
+
Memory Update
+
Learning History

其中最核心的关系是:

Experience → LearningEngine → Knowledge
                         ↓
                    Ability Resource
                         ↓
                    Memory Update

这使 LearningEngine 成为前面第70章 Learning 的真正运行机制:Learning 是学习过程,LearningEngine 是执行这个过程的引擎。

Leave a Reply

Your email address will not be published. Required fields are marked *