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

جواب «Step 2: Limits from the Evaluation» چالش 2 از جلسه‌ی 80

سؤال

تابع limits(ev) را بنویس که از دیکشنری ارزیابی، لیست جمله‌های محدودیت بسازد، به این ترتیب: ۱) اگر test کمتر از 20 است: Small test: only <test> samples, so the number may change a lot.؛ ۲) برای هر گروهی که درصدش بیش از 20 واحد از بهترین گروه کمتر است: Worse for <group>: <pct>% against <best>%.؛ ۳) اگر hallucinated بیشتر از صفر است: It made things up <n> time(s): always show the source.؛ ۴) اگر outside_range درست است: Not trusted outside the data it was trained on. خروجی:
== Limits ==
- Small test: only 15 samples, so the number may change a lot.
- Worse for other class: 62% against 90%.
- Not trusted outside the data it was trained on.

راهنما

best = max(ev["groups"].values())؛ for group, pct in ev["groups"].items(): if best - pct > 20: found.append(f"Worse for {group}: {pct}% against {best}%."). چهار if به ترتیب.

یک جواب درست

EVAL = {
    "test": 15,
    "groups": {"our group": 90, "other class": 62},
    "hallucinated": 0,
    "outside_range": True,
}


def limits(ev):
    found = []
    if ev["test"] < 20:
        found.append(f"Small test: only {ev['test']} samples, so the number may change a lot.")
    best = max(ev["groups"].values())
    for group, pct in ev["groups"].items():
        if best - pct > 20:
            found.append(f"Worse for {group}: {pct}% against {best}%.")
    if ev["hallucinated"] > 0:
        found.append(f"It made things up {ev['hallucinated']} time(s): always show the source.")
    if ev["outside_range"]:
        found.append("Not trusted outside the data it was trained on.")
    return found


print("== Limits ==")
for line in limits(EVAL):
    print("-", line)

اول خودت امتحان کن؛ جواب‌های دیگر هم قبول است. برگرد و خودت حلش کن