File size: 1,210 Bytes
0cc835c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Where does a trained model disagree with the labels? python confusions.py <repo or dir> [onnx file] [threshold]"""
import sys, json, runpy
from collections import Counter
from pathlib import Path

sys.argv = ["evaluate.py", "onnx:" + sys.argv[1], *(sys.argv[2:3] or ["model_qint8.onnx"])] + sys.argv[3:]
threshold = float(sys.argv[3]) if len(sys.argv) > 3 else 0.4
src = Path("evaluate.py").read_text().split("spec = sys.argv[1]")[0]
ns: dict = {"__file__": str(Path("evaluate.py").resolve()), "__name__": "x"}
exec(src, ns)
predict = ns["head_predictor"]("onnx", sys.argv[1].split(":", 1)[1])
for name in ("val", "test"):
    rows = ns["load"](name)
    preds = predict(rows)
    errors = Counter()
    by_target = Counter()
    for row, (move, p) in zip(rows, preds):
        got = move if move != "none" and p >= threshold else "none"
        if got not in row["ok"]:
            errors[(row["kind"], row["best"], got)] += 1
            by_target[(row.get("target") or row.get("source") or "?")] += 1
    print(f"== {name}: {sum(errors.values())} errors of {len(rows)}")
    print("  (kind, label, predicted):", errors.most_common(18))
    print("  by request target/source:", by_target.most_common(14))