بتل کد Battle Codeدارد باز می‌شود…

Step 3: Is the Answer Grounded? چالش 3 از جلسه‌ی 72، متوسط

این مدل گاهی از خودش اضافه می‌کند. تابع grounded(answer, context) را بنویس: True اگر همه‌ی کلمه‌های تمیز (tokens) جواب در کلمه‌های زمینه باشند. اگر نبود، به جای جواب Not sure: the answer says more than the notes. Check chunk <i>. چاپ کن و کلمه‌های اضافه را به ترتیب الفبا. خروجی:
Condensation is when the vapour cools high in the sky and forms clouds.
Not sure: the answer says more than the notes. Check chunk 2.
extra words: ['chocolate', 'fridays']

STOP = {"the", "a", "an", "is", "are", "and", "or", "of", "in", "on", "to", "into", "it", "this",
        "that", "what", "how", "why", "does", "do", "as", "when", "they", "called", "its"}
CHUNKS = [
    "Evaporation is when the sun heats water in seas and lakes and the warm water turns into vapour and rises.",
    "Condensation is when the vapour cools high in the sky and forms clouds.",
    "Precipitation is when the drops in a cloud get heavy and fall as rain or snow.",
]


def tokens(text):
    words = []
    for w in text.lower().split():
        w = "".join(ch for ch in w if ch.isalpha())
        if w and w not in STOP:
            words.append(w)
    return words


def fake_model(question, context):
    # A pretend model that answers from the context... and sometimes adds a "fact".
    if context.startswith("Precipitation"):
        return context.rstrip(".") + ", and on Fridays as chocolate."
    return context


def grounded(answer, context):
    return True


for question, i in [("What is condensation?", 1), ("What is precipitation?", 2)]:
    answer = fake_model(question, CHUNKS[i])
    print(answer)

راهنما و جواب این چالش · برگشت به درس جلسه‌ی 72: RAG کوچک (۲): از روی جزوه جواب بده · چالش بعدی: Step 4: With and Without RAG

بیشتر بخوان: تابع در پایتون: آموزش def، پارامتر و return با مثال