جواب «Right, Wrong, Hallucinated, Over-Cautious» چالش 4 از جلسهی 76
سؤال
تابع classify(reply, expected) را بنویس. expected یا یک کلمهی کلیدی است، یا None یعنی جواب در جزوه نیست. اگر expected برابر None: جواب I don't know. یعنی right refusal، وگرنه hallucinated. اگر expected داریم: I don't know. یعنی over-cautious؛ اگر کلمهی کلیدی (با حروف کوچک) در جواب بود right، وگرنه wrong. در آخر شمارش هر دسته به ترتیب الفبا. خروجی:1 right2 wrong3 hallucinated4 right refusal5 over-cautioushallucinated 1, over-cautious 1, right 1, right refusal 1, wrong 1
راهنما
refused = reply == "I don't know.". if expected is None: return "right refusal" if refused else "hallucinated". بعد if refused: return "over-cautious" و return "right" if expected in reply.lower() else "wrong".
یک جواب درست
RESULTS = [ # (the model's reply, the expected key word or None)
("Water turns into vapour.", "vapour"),
("Clouds are made of cotton.", "vapour"),
("The school was built in 1962 by Mr Karimi.", None),
("I don't know.", None),
("I don't know.", "rain"),
]
def classify(reply, expected):
refused = reply == "I don't know."
if expected is None:
return "right refusal" if refused else "hallucinated"
if refused:
return "over-cautious"
return "right" if expected in reply.lower() else "wrong"
counts = {}
for i, (reply, expected) in enumerate(RESULTS, 1):
kind = classify(reply, expected)
counts[kind] = counts.get(kind, 0) + 1
print(i, kind)
print(", ".join(f"{k} {counts[k]}" for k in sorted(counts)))
اول خودت امتحان کن؛ جوابهای دیگر هم قبول است. برگرد و خودت حلش کن