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

Track A: The Bot's RAG Core چالش 1 از جلسه‌ی 78، آسان

مسیر الف. تابع answer(question) را بنویس: بهترین تکه را با jaccard پیدا کن؛ اگر بهترین امتیاز 0 بود Not in the notes.؛ وگرنه <chunk> [source: chunk <i>]. خروجی:
Condensation is when vapour cools and forms clouds. [source: chunk 1]
Precipitation is rain or snow falling from heavy clouds. [source: chunk 2]
Not in the notes.

STOP = {"the", "a", "an", "is", "are", "and", "or", "of", "in", "on", "to", "it", "what", "how", "why", "does", "do", "when"}
CHUNKS = [
    "Evaporation is when the sun heats water and it turns into vapour.",
    "Condensation is when vapour cools and forms clouds.",
    "Precipitation is rain or snow falling from heavy clouds.",
]


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 jaccard(a, b):
    a, b = set(a), set(b)
    if not a or not b:
        return 0
    return len(a & b) / len(a | b)


def answer(question):
    return "Not in the notes."


for q in ["What is condensation?", "Why does rain fall from clouds?", "Who painted the Mona Lisa?"]:
    print(answer(q))

راهنما و جواب این چالش · برگشت به درس جلسه‌ی 78: پروژه‌ی آزاد با مربی (۲): ساختن · چالش بعدی: Track B: The Average Image of Each Class

بیشتر بخوان: list comprehension در پایتون: از حلقه for تا یک خط کد