File size: 1,933 Bytes
6071ec5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Summarise results/format/<label>/<task>.jsonl (hipoteza_formatu.py output): accuracy per task and model, the share of
the most frequent predicted letter (letter bias), and a paired comparison vs the base (per-question, McNemar-style
z on the difference of correct indicators). acc = argmax of the raw log-likelihood (lm-eval `acc`)."""
import json
import math
import sys
from collections import Counter
from pathlib import Path

root = Path(sys.argv[1])
labels = sys.argv[2].split(",")
base = labels[0]
tasks = ["belebele_mc", "belebele_cloze", "arc_c_mc", "arc_c_mc_przes", "arc_c_cloze", "mmlu_mc", "mmlu_cloze"]


def load(label, task):
    p = root / label / f"{task}.jsonl"
    if not p.exists():
        return {}
    out = {}
    for line in open(p, encoding="utf-8"):
        w = json.loads(line)
        ll = w.get("ll") or w.get("logliki") or w.get("loglik")
        if ll is None:
            continue
        pred = max(range(len(ll)), key=lambda i: ll[i])
        out[w["id"]] = (pred == w.get("gold", w.get("poprawna")), pred)
    return out


print(f"{'task':16s} " + " ".join(f"{l:>22s}" for l in labels))
for t in tasks:
    rows = {l: load(l, t) for l in labels}
    cells = []
    for l in labels:
        r = rows[l]
        if not r:
            cells.append(f"{'-':>22s}")
            continue
        acc = 100 * sum(c for c, _ in r.values()) / len(r)
        top = 100 * Counter(p for _, p in r.values()).most_common(1)[0][1] / len(r)
        s = f"{acc:5.1f} (top {top:4.1f}%)"
        if l != base and rows[base]:
            ids = sorted(set(r) & set(rows[base]))
            d = [int(r[i][0]) - int(rows[base][i][0]) for i in ids]
            m = sum(d) / len(d)
            sd = math.sqrt(sum((x - m) ** 2 for x in d) / max(1, len(d) - 1)) / math.sqrt(len(d))
            s += f" {100 * m:+5.1f} z={m / sd if sd else 0:+.1f}"
        cells.append(f"{s:>22s}")
    print(f"{t:16s} " + " ".join(cells))