File size: 1,968 Bytes
fbb4123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""Entry point: build the v2 belief memory from scratch."""
from humpback2.memory import Memory
from humpback2.evaluate import full_report, changing_facts_report


def build():
    m = Memory("humpback2.db")

    # 1. Plant a small, honest knowledge base.
    facts = [
        {"claim": "python is a programming language", "subject": "python", "source_type": "user", "confidence": 0.9, "volatility": "static"},
        {"claim": "the human brain uses about 20% of the body's energy", "subject": "brain", "source_type": "user", "confidence": 0.85, "volatility": "static"},
        {"claim": "price of apple is 10", "subject": "price of apple", "source_type": "user", "confidence": 0.9, "volatility": "fast"},
        {"claim": "apple is a fruit", "subject": "apple", "source_type": "user", "confidence": 0.9, "volatility": "static"},
        {"claim": "paris is a city", "subject": "paris", "source_type": "official", "confidence": 0.95, "volatility": "static"},
        {"claim": "the capital of france is paris", "subject": "capital of france", "source_type": "official", "confidence": 0.95, "volatility": "static"},
        {"claim": "what is 6 times 7", "subject": "6 times 7", "source_type": "user", "confidence": 0.8, "volatility": "static"},
    ]
    m.learn_many(facts)
    print(f"Planted {m.size()} facts.")

    # 2. Train the change-detection and recall levels.
    report = full_report(m)
    print("Calibration:", report)
    cfr = changing_facts_report(m)
    print("Changing facts:", cfr)

    # 3. Put the engine in front of a question.
    print("\n--- Q: what is paris ---")
    print(m.ask("what is paris")["answer"])
    print("--- Q: what is the price of apple ---")
    print(m.ask("the price of apple")["answer"])
    print("--- Q: what is 6 times 7 ---")
    print(m.ask("what is 6 times 7")["answer"])
    print("--- Q: what is python ---")
    print(m.ask("what is python")["answer"])

    return m


if __name__ == "__main__":
    build()