Spaces:
Sleeping
Sleeping
Update graders.py
Browse files- graders.py +18 -9
graders.py
CHANGED
|
@@ -17,18 +17,21 @@ EASY_EMAILS = [
|
|
| 17 |
{"subject": "Your invoice is ready", "body": "Please find your monthly invoice attached.", "label": "important"},
|
| 18 |
]
|
| 19 |
|
| 20 |
-
def grade_easy(agent_fn):
|
| 21 |
"""
|
| 22 |
Easy task: classify obvious spam vs important emails.
|
| 23 |
agent_fn(email) -> 'spam' | 'important' | 'promotion'
|
| 24 |
-
Returns score 0.0
|
| 25 |
"""
|
|
|
|
|
|
|
| 26 |
correct = 0
|
| 27 |
for email in EASY_EMAILS:
|
| 28 |
prediction = agent_fn(email)
|
| 29 |
if prediction == email["label"]:
|
| 30 |
correct += 1
|
| 31 |
-
|
|
|
|
| 32 |
return {"task": "easy", "correct": correct, "total": len(EASY_EMAILS), "score": score}
|
| 33 |
|
| 34 |
|
|
@@ -45,17 +48,20 @@ MEDIUM_EMAILS = [
|
|
| 45 |
{"subject": "Urgent: verify your account", "body": "Your account will be suspended. Click to verify.", "label": "spam"},
|
| 46 |
]
|
| 47 |
|
| 48 |
-
def grade_medium(agent_fn):
|
| 49 |
"""
|
| 50 |
Medium task: classify emails across all 3 categories.
|
| 51 |
-
Returns score 0.0
|
| 52 |
"""
|
|
|
|
|
|
|
| 53 |
correct = 0
|
| 54 |
for email in MEDIUM_EMAILS:
|
| 55 |
prediction = agent_fn(email)
|
| 56 |
if prediction == email["label"]:
|
| 57 |
correct += 1
|
| 58 |
-
|
|
|
|
| 59 |
return {"task": "medium", "correct": correct, "total": len(MEDIUM_EMAILS), "score": score}
|
| 60 |
|
| 61 |
|
|
@@ -74,17 +80,20 @@ HARD_EMAILS = [
|
|
| 74 |
{"subject": "You've been pre-approved!", "body": "You qualify for a $50,000 loan. Apply now.", "label": "spam"},
|
| 75 |
]
|
| 76 |
|
| 77 |
-
def grade_hard(agent_fn):
|
| 78 |
"""
|
| 79 |
Hard task: subtle emails that are easy to misclassify.
|
| 80 |
-
Returns score 0.0
|
| 81 |
"""
|
|
|
|
|
|
|
| 82 |
correct = 0
|
| 83 |
for email in HARD_EMAILS:
|
| 84 |
prediction = agent_fn(email)
|
| 85 |
if prediction == email["label"]:
|
| 86 |
correct += 1
|
| 87 |
-
|
|
|
|
| 88 |
return {"task": "hard", "correct": correct, "total": len(HARD_EMAILS), "score": score}
|
| 89 |
|
| 90 |
|
|
|
|
| 17 |
{"subject": "Your invoice is ready", "body": "Please find your monthly invoice attached.", "label": "important"},
|
| 18 |
]
|
| 19 |
|
| 20 |
+
def grade_easy(agent_fn=None):
|
| 21 |
"""
|
| 22 |
Easy task: classify obvious spam vs important emails.
|
| 23 |
agent_fn(email) -> 'spam' | 'important' | 'promotion'
|
| 24 |
+
Returns score strictly in (0.0, 1.0)
|
| 25 |
"""
|
| 26 |
+
if agent_fn is None:
|
| 27 |
+
agent_fn = baseline_agent
|
| 28 |
correct = 0
|
| 29 |
for email in EASY_EMAILS:
|
| 30 |
prediction = agent_fn(email)
|
| 31 |
if prediction == email["label"]:
|
| 32 |
correct += 1
|
| 33 |
+
raw = correct / len(EASY_EMAILS)
|
| 34 |
+
score = round(min(0.99, max(0.01, raw)), 2)
|
| 35 |
return {"task": "easy", "correct": correct, "total": len(EASY_EMAILS), "score": score}
|
| 36 |
|
| 37 |
|
|
|
|
| 48 |
{"subject": "Urgent: verify your account", "body": "Your account will be suspended. Click to verify.", "label": "spam"},
|
| 49 |
]
|
| 50 |
|
| 51 |
+
def grade_medium(agent_fn=None):
|
| 52 |
"""
|
| 53 |
Medium task: classify emails across all 3 categories.
|
| 54 |
+
Returns score strictly in (0.0, 1.0)
|
| 55 |
"""
|
| 56 |
+
if agent_fn is None:
|
| 57 |
+
agent_fn = baseline_agent
|
| 58 |
correct = 0
|
| 59 |
for email in MEDIUM_EMAILS:
|
| 60 |
prediction = agent_fn(email)
|
| 61 |
if prediction == email["label"]:
|
| 62 |
correct += 1
|
| 63 |
+
raw = correct / len(MEDIUM_EMAILS)
|
| 64 |
+
score = round(min(0.99, max(0.01, raw)), 2)
|
| 65 |
return {"task": "medium", "correct": correct, "total": len(MEDIUM_EMAILS), "score": score}
|
| 66 |
|
| 67 |
|
|
|
|
| 80 |
{"subject": "You've been pre-approved!", "body": "You qualify for a $50,000 loan. Apply now.", "label": "spam"},
|
| 81 |
]
|
| 82 |
|
| 83 |
+
def grade_hard(agent_fn=None):
|
| 84 |
"""
|
| 85 |
Hard task: subtle emails that are easy to misclassify.
|
| 86 |
+
Returns score strictly in (0.0, 1.0)
|
| 87 |
"""
|
| 88 |
+
if agent_fn is None:
|
| 89 |
+
agent_fn = baseline_agent
|
| 90 |
correct = 0
|
| 91 |
for email in HARD_EMAILS:
|
| 92 |
prediction = agent_fn(email)
|
| 93 |
if prediction == email["label"]:
|
| 94 |
correct += 1
|
| 95 |
+
raw = correct / len(HARD_EMAILS)
|
| 96 |
+
score = round(min(0.99, max(0.01, raw)), 2)
|
| 97 |
return {"task": "hard", "correct": correct, "total": len(HARD_EMAILS), "score": score}
|
| 98 |
|
| 99 |
|