File size: 1,872 Bytes
b222eb5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""Validate the two metrics against known-correct answers before spending GPU time.

A scorer that silently returns 0 for a correct answer would make every claim
look refuted. Feed each metric its own gold answer and require ~100%.
"""
import sys, os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import json
from run_eval import load_trip, load_humaneval, score_trip, score_humaneval

ok = True

# ---- Trip: feed the golden_plan through the paper's own parse+score path
items, _ = load_trip(limit=40, num_cities=None)
gold_responses = [i["golden_plan"] for i in items]
score, per = score_trip(items, gold_responses)
print(f"Trip   gold-plan score: {score:.1f}%  ({int(sum(per))}/{len(per)})")
if score < 95:
    print("  FAIL: trip metric does not score its own gold plans"); ok = False

# ---- HumanEval: feed the canonical_solution exactly as the model would emit it.
# The prompt already ends with gen_prefix = "...```python\n{prompt}\n", so the
# continuation the model produces is the function BODY only, then a closing fence.
docs = load_humaneval(limit=20)
resps = [d["canonical_solution"] + "```" for d in docs]
score, per = score_humaneval(docs, resps)
print(f"HumanEval canonical score: {score:.1f}%  ({int(sum(per))}/{len(per)})")
if score < 95:
    print("  FAIL: humaneval metric does not score its own canonical solutions")
    for d, p in zip(docs, per):
        if p == 0:
            print("   first failing task:", d["task_id"]); break
    ok = False

# ---- HumanEval negative control: a wrong body must score 0
bad = ["    return None\n```" for d in docs]
score_bad, _ = score_humaneval(docs, bad)
print(f"HumanEval wrong-answer score: {score_bad:.1f}%  (expect ~0)")
if score_bad > 5:
    print("  FAIL: humaneval metric passes wrong answers"); ok = False

print("\nSCORER TEST:", "PASS" if ok else "FAIL")
sys.exit(0 if ok else 1)