နည်းသစ်ဉာဏ်ရည်တုပညာ အဆင့်မြင့်သီအိုရီများ၊ အခန်း (၁၀)၊ စာမျက်နှာ-၅၂ ရှိ Problem 10.2 ကို ကြည့်ပါ။
"John bought tomatoes" ပြဿနာသည် Knowledge Representation (အသိပညာကို ကိုယ်စားပြုခြင်း) နှင့် Common Sense Reasoning (သာမန် အသိဉာဏ်ဖြင့် ဆင်ခြင်ခြင်း) ကို စမ်းသပ်သော ဂန္တဝင် ပြဿနာတစ်ခု ဖြစ်ပါသည်။
ဤပြဿနာကို ဖြေရှင်းရန် လူသားတစ်ယောက်၏ ဦးနှောက်ထဲတွင်ရှိသော "နောက်ခံ ဗဟုသုတများ" (Background Knowledge) ကို ကွန်ပျူတာ နားလည်မည့် Logic ပုံစံသို့ ပြောင်းလဲရပါမည်။
အောက်ပါ အဆင့် (၃) ဆင့်ဖြင့် တည်ဆောက်ပြပါမည်။
အဆင့် (၁) - Knowledge Base (KB) တည်ဆောက်ခြင်း
ပထမဦးစွာ စာကြောင်းပါ အချက်အလက်များနှင့် လိုအပ်သော နောက်ခံဗဟုသုတများကို အမျိုးအစား ခွဲခြားသတ်မှတ်ကြပါစို့။
၁. Ontology (အမျိုးအစား ခွဲခြားခြင်း)
Entities (အရာဝတ္ထုများ):
John(Person, Agent)Safeway(Supermarket, Location)Tomatoes(Vegetable/Fruit, Food)Ground Beef(Meat, Food)Money / Credit Card(Payment Method)
Events (ဖြစ်စဉ်များ):
Buying(Transaction) - ပိုက်ဆံပေးပြီး ပစ္စည်းယူခြင်း။Going(Movement) - နေရာတစ်ခုသို့ သွားခြင်း။
Relations (ဆက်နွယ်မှုများ):
IsA(Object, Class)- အမျိုးအစား သတ်မှတ်ခြင်း။Sells(Store, Item)- ဆိုင်က ဘာရောင်းသလဲ။Owns(Person, Item)- ပိုင်ဆိုင်မှု။Location(Person, Place)- လူတစ်ယောက် ဘယ်ရောက်နေသလဲ။
၂. Logical Assertions (အချက်အလက်များကို Logic ပြောင်းခြင်း)
Scenario Facts (ဇာတ်လမ်းပါ အချက်အလက်များ):
Did(John, Go_to(Safeway))Did(John, Buy(Tomatoes, 2_lbs))Did(John, Buy(Ground_Beef, 1_lb))Time(Yesterday)
Background Knowledge (လိုအပ်သော နောက်ခံဗဟုသုတများ - Rules):
Buying Rule:
IFPerson buys ItemTHENPerson owns ItemANDPerson pays Money.Wealth Rule:
IFPerson buys ItemTHENPerson has less money.Meat Rule:
IFItem is Ground BeefTHENItem is Meat.Produce Rule:
IFItem is TomatoTHENItem is grown (not made in factory).Location Rule:
IFPerson A is at Place XANDPerson B is at Place Xat same timeTHENThey likely see each other.Store Rule:
IFStore is SupermarketTHENStore sells Food, Toiletries, etc.
အဆင့် (၂) - Reasoning Chain (ဆင်ခြင်စဉ်းစားပုံ အဆင့်ဆင့်)
မေးခွန်းများကို ဖြေဆိုရန် Logic စီးဆင်းပုံမှာ အောက်ပါအတိုင်း ဖြစ်သည်။
a. Is John a child or an adult?
Reasoning: Grocery shopping is typically a household responsibility.
Default Assumption-> John is an Adult.
c. Did John buy any meat?
Reasoning: John bought
Ground Beef.Ground BeefIS-AMeat. Therefore -> Yes.
e. Are the tomatoes made in the supermarket?
Reasoning:
TomatoesAREProduce.ProduceisGrown(Farming), notManufactured. Supermarkets sell goods, they don't grow them inside. Therefore -> No.
i. Does John have less money...?
Reasoning: Action is
Buying.Buyingrequires exchange of value (Money for Goods). Therefore -> Yes.
အဆင့် (၃) - Python Implementation (AI Agent)
ဤပရိုဂရမ်တွင် Knowledge Graph ပုံစံ အတိုကောက်တည်ဆောက်ထားပြီး၊ မေးခွန်းများကို ဖြေရှင်းနိုင်သော Inference Engine တစ်ခု ပါဝင်ပါသည်။
class KnowledgeBase:
def __init__(self):
# 1. Classes / Ontology (အမျိုးအစားများ)
self.taxonomy = {
"Ground Beef": ["Meat", "Food", "Perishable"],
"Tomatoes": ["Vegetable", "Food", "Produce"],
"Deodorant": ["Toiletry", "Personal Care"],
"Safeway": ["Supermarket", "Store", "Place"],
"John": ["Person", "Agent", "Shopper"],
"Mary": ["Person", "Agent"]
}
# 2. Facts Database (အဖြစ်အပျက်များ)
self.facts = {
"John": {
"action": ["went", "bought"],
"bought": {"Tomatoes": "2 lbs", "Ground Beef": "1 lb"},
"location": "Safeway",
"time": "Yesterday"
},
"Safeway": {
"sells_categories": ["Food", "Toiletry", "Household"],
"manufactures_produce": False
}
}
# 3. Rules (စည်းမျဉ်းများ - Dictionary ပုံစံဖြင့် သိမ်းဆည်းခြင်း)
self.rules = {
"buying_implies_ownership": True,
"buying_requires_money": True,
"buying_reduces_wealth": True,
"supermarket_sells_toiletries": True,
"co_location_implies_visibility": True
}
# Helper function to check inheritance (Is-A relationship)
def is_a(self, entity, category):
if entity in self.taxonomy:
return category in self.taxonomy[entity]
return False
# --- Reasoning Functions for specific questions ---
def query_a_age_group(self, person):
# Default Logic: Shoppers are typically adults
if "Shopper" in self.taxonomy[person]:
return "Adult (Based on default assumption for shoppers)"
return "Unknown"
def query_b_has_tomatoes(self, person):
# Logic: Bought implies ownership
purchases = self.facts[person].get("bought", {})
if "Tomatoes" in purchases:
return f"Yes, he bought {purchases['Tomatoes']}."
return "No"
def query_c_bought_meat(self, person):
# Logic: Check all purchases -> Check if any purchase Is-A Meat
purchases = self.facts[person].get("bought", {})
for item in purchases:
if self.is_a(item, "Meat"):
return f"Yes (Because he bought {item}, which is Meat)"
return "No"
def query_d_saw_mary(self, person1, person2):
# Logic: If Location(P1) == Location(P2) -> Saw each other
loc1 = self.facts[person1].get("location")
# Assuming Mary was there as per question hypothesis
loc2 = "Safeway"
if loc1 == loc2 and self.rules["co_location_implies_visibility"]:
return "Yes (Shared location implies visibility)"
return "No"
def query_e_tomatoes_made_in_store(self):
# Logic: Tomatoes are Produce -> Produce is grown, not made in store
if self.is_a("Tomatoes", "Produce") and not self.facts["Safeway"]["manufactures_produce"]:
return "No (Tomatoes are produce/grown, not manufactured in-store)"
return "Yes"
def query_f_purpose_of_tomatoes(self):
# Logic: Tomatoes Is-A Food -> Food is for Eating
if self.is_a("Tomatoes", "Food"):
return "Eat them (Default purpose of Food)"
return "Unknown"
def query_g_sells_deodorant(self, store):
# Logic: Store Is-A Supermarket -> Supermarket sells Toiletries -> Deodorant Is-A Toiletry
if self.is_a(store, "Supermarket"):
if "Toiletry" in self.facts[store]["sells_categories"] and self.is_a("Deodorant", "Toiletry"):
return "Yes (Supermarkets sell toiletries)"
return "No"
def query_h_brought_money(self, person):
# Logic: Did person Buy? -> Buying requires money
if "bought" in self.facts[person]["action"] and self.rules["buying_requires_money"]:
return "Yes (Buying transaction necessitates payment method)"
return "No"
def query_i_less_money(self, person):
# Logic: Did person Buy? -> Buying reduces wealth
if "bought" in self.facts[person]["action"] and self.rules["buying_reduces_wealth"]:
return "Yes (Exchange of assets for goods reduces liquid money)"
return "No"
# --- AI Agent Interface ---
class SmartAgent:
def __init__(self):
self.kb = KnowledgeBase()
print("--- AI Agent Initialized with Commonsense Knowledge Base ---\n")
def answer_questions(self):
kb = self.kb
print("Q(a): Is John a child or an adult?")
print(f"Ans: {kb.query_a_age_group('John')}\n")
print("Q(b): Does John now have at least two tomatoes?")
print(f"Ans: {kb.query_b_has_tomatoes('John')}\n")
print("Q(c): Did John buy any meat?")
print(f"Ans: {kb.query_c_bought_meat('John')}\n")
print("Q(d): If Mary was buying tomatoes at the same time, did he see her?")
print(f"Ans: {kb.query_d_saw_mary('John', 'Mary')}\n")
print("Q(e): Are the tomatoes made in the supermarket?")
print(f"Ans: {kb.query_e_tomatoes_made_in_store()}\n")
print("Q(f): What is John going to do with the tomatoes?")
print(f"Ans: {kb.query_f_purpose_of_tomatoes()}\n")
print("Q(g): Does Safeway sell deodorant?")
print(f"Ans: {kb.query_g_sells_deodorant('Safeway')}\n")
print("Q(h): Did John bring some money or a credit card?")
print(f"Ans: {kb.query_h_brought_money('John')}\n")
print("Q(i): Does John have less money after going to the supermarket?")
print(f"Ans: {kb.query_i_less_money('John')}\n")
# --- Execution ---
if __name__ == "__main__":
agent = SmartAgent()
agent.answer_questions()
ပရိုဂရမ်၏ အနှစ်သာရ သုံးသပ်ချက်
Taxonomy (မျိုးရိုးခွဲခြားခြင်း):
Ground Beefသည်Meatဖြစ်သည်၊Safewayသည်Supermarketဖြစ်သည် စသဖြင့် အဆင့်ဆင့် သတ်မှတ်ထားခြင်းကြောင့်၊ "John အမဲသား ဝယ်လား?" ဟု မေးသောအခါ ပရိုဂရမ်က John ဝယ်တာGround Beef၊Ground BeefကMeatဖြစ်တယ် ဆိုတာကို ဆက်စပ်တွေးခေါ် (Infer) နိုင်သွားသည်။Default Reasoning: မေးခွန်း (a) နှင့် (f) အတွက် တိကျသော အချက်အလက် မရှိသော်လည်း၊ "စျေးဝယ်သူသည် လူကြီးဖြစ်လေ့ရှိသည်"၊ "အစားအစာသည် စားရန်ဖြစ်သည်" ဆိုသော ပုံသေယူဆချက် (Defaults) များကို အသုံးပြုထားသည်။
Logical Rules: ဝယ်ယူခြင်း (Buying) သည် ပိုက်ဆံကုန်သည်၊ ပိုင်ဆိုင်မှု ပြောင်းလဲသည် ဆိုသော စည်းမျဉ်းများကို
rulesထဲတွင် ထည့်သွင်းထားသဖြင့် မေးခွန်း (h) နှင့် (i) ကို တိကျစွာ ဖြေဆိုနိုင်ခြင်း ဖြစ်သည်။
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.