textmachine/eval/bank_arbitration/score_baselines.py

66 lines
3.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""$0: точность бесплатного базиса P0 (§C2-3 топ-вариант) и прод-референса P1 (сведённый dst
coldrun-a) против голда; разбор промахов по классам (конвенция 古月 · реалия-транслит · прочее).
Единицы печатаются целиком (норма: вывод на агрегате до вскрытия единиц запрещён)."""
import json
import unicodedata
from pathlib import Path
HERE = Path(__file__).resolve().parent
GOLD = [json.loads(l) for l in open(HERE / "gold" / "gold.jsonl", encoding="utf-8")]
def ntgt(s: str) -> str:
s = unicodedata.normalize("NFKC", s or "").casefold().replace("ё", "е")
for ch in "«»\"'":
s = s.replace(ch, "")
return " ".join(s.split())
def eq(a: str, b: str) -> bool:
return ntgt(a) == ntgt(b) and ntgt(a) != ""
inb = [r for r in GOLD if r["in_bank"]]
print(f"голд в банке: {len(inb)} (из 53 approved)")
p0_ok, p1_ok = [], []
p0_none = []
for r in inb:
variants = r.get("variants") or []
p0 = variants[0][0] if variants else ""
if not p0:
p0_none.append(r["src"])
r["_p0"] = p0
if eq(p0, r["gold_dst"]):
p0_ok.append(r["src"])
if eq(r.get("bank_dst", ""), r["gold_dst"]):
p1_ok.append(r["src"])
print(f"P0 (топ §C2-3 из вариантов черновиков) == gold: {len(p0_ok)}/{len(inb)} (термов без вариантов: {len(p0_none)}: {p0_none})")
print(f"P1 (сведённый dst терминолога coldrun-a) == gold: {len(p1_ok)}/{len(inb)}")
# парное сравнение P1 vs P0
p1_not_p0 = [r["src"] for r in inb if eq(r.get("bank_dst", ""), r["gold_dst"]) and not eq(r["_p0"], r["gold_dst"])]
p0_not_p1 = [r["src"] for r in inb if not eq(r.get("bank_dst", ""), r["gold_dst"]) and eq(r["_p0"], r["gold_dst"])]
print(f"P1-прав-P0-неправ: {len(p1_not_p0)} {p1_not_p0}")
print(f"P0-прав-P1-неправ: {len(p0_not_p1)} {p0_not_p1}")
print("\n=== ЕДИНИЦЫ: промахи P1 (bank_dst != gold) с классом ===")
for r in inb:
if eq(r.get("bank_dst", ""), r["gold_dst"]):
continue
cls = "конвенция-古月" if r["src"].startswith("古月") and "гу юэ" in ntgt(r.get("bank_dst", "")) else ""
if not cls and r.get("bank_dst") and ntgt(r["bank_dst"]).replace(" ", "").replace("-", "") == ntgt(r["gold_dst"]).replace(" ", "").replace("-", ""):
cls = "орфография (дефис/слитно)"
print(f" {r['src']}: gold={r['gold_dst']!r} bank={r.get('bank_dst','')!r} p0={r['_p0']!r} spread={r.get('spread')} {('['+cls+']') if cls else ''}")
print("\n=== ЕДИНИЦЫ: было ли верное в вариантах, когда P1 промахнулся ===")
n_had = 0
for r in inb:
if eq(r.get("bank_dst", ""), r["gold_dst"]):
continue
had = any(eq(v[0], r["gold_dst"]) for v in (r.get("variants") or []))
n_had += had
print(f" {r['src']}: gold-в-вариантах={'ДА' if had else 'нет'} variants={[v[0] for v in (r.get('variants') or [])][:6]}")
print(f"промахов P1 с верным ответом, ЛЕЖАВШИМ в вариантах: {n_had}")