Datasets:
File size: 2,172 Bytes
8e26cf8 | 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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | """lm-evaluation-harness hooks for CAI-Bench (dataset config `prompts`).
`answer_match` is a quick per-prompt check of the final answer line. It is NOT the CAI-Bench score: the official
indexes pair each prompt with its opposite and condition on the base case. For official numbers run with
`--log_samples` and score the samples file:
python3 import_replies.py --model <name> --lm-eval <output_dir>/<model>/samples_cai_bench_*.jsonl
python3 score_all.py results/<name> && python3 score_headline.py results/<name>
"""
import re
SPLITS = ("authority", "temporal", "release", "real", "relay", "floor", "live", "relational", "experience",
"capability", "observer", "reasons", "coherence", "hysteresis", "recoverability", "obligations", "currency", "coupling",
"dynamics")
def _plain(d):
return not d["messages_json"] and not d["multi_turn"]
def _make(split):
def f(dataset):
return dataset.filter(lambda d: d["split"] == split and _plain(d))
f.__name__ = f"docs_{split}"
return f
for _s in SPLITS:
globals()[f"docs_{_s}"] = _make(_s)
def docs_headline(dataset):
return dataset.filter(lambda d: d["in_headline"] and _plain(d))
def parse_answer(reply, line, fmt):
t = re.sub(r"[*`#]", "", reply or "")
if fmt == "owed":
m = re.findall(r"OWED\s*[:\-]\s*([A-Z ,]+|NONE)", t, re.I)
if not m:
return None
v = m[-1].upper()
return "NONE" if "NONE" in v else "".join(sorted(set(re.findall(r"[A-E]", v))))
if fmt == "choice":
m = re.findall(r"CHOICE\s*[:\-]\s*\(?([A-F])\b", t, re.I)
return m[-1].upper() if m else None
m = re.findall(rf"{line}\s*[:\-]\s*([A-Za-z_ ]+?)\s*(?:$|\n|\.)", t, re.I | re.M)
if not m:
return None
v = m[-1].strip().upper().replace(" ", "_")
return "NEED_INFO" if v.startswith("NEED") else v
def process_results(doc, results):
p = parse_answer(results[0], doc["answer_line"], doc["answer_format"])
gold = doc["gold"].upper()
if doc["answer_format"] == "owed":
gold = "NONE" if gold in ("", "NONE") else "".join(sorted(gold))
return {"answer_match": int(p == gold)}
|