textmachine/eval/exp14b/exp14b_monitor.py

53 lines
3.1 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
"""exp14b §2 — слепой head-to-head пакет P1a(=C, glm-5 дискурс) ↔ F-disc(=F, gpt-5.4 дискурс)
на главах 17/18/19 (+ оригинал для верности). Метки U1/U2 перемешаны по главам, ключ отдельно.
Копирайт: ВНЕ git.
"""
from __future__ import annotations
import json, random, sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "exp14")) # exp14b reuses exp14's harness (exp14_common lives in eval/exp14/)
import exp14_common as C
ARMS = Path("/home/ubuntu/books/gu-zhenren/exp14b/arms")
RERUN = Path("/home/ubuntu/books/gu-zhenren/rerun")
RECS = {(r["chapter"], r["chunk_idx"]): r for r in json.load(open(RERUN / "records.json"))}
OUT = Path("/home/ubuntu/books/gu-zhenren/exp14b/monitor"); OUT.mkdir(parents=True, exist_ok=True)
FINALISTS = {"cheap-P1a": "C", "frontier-F-disc": "F"}
CHAPTERS = [19, 17, 18]
CHUNKS = {19: [0, 1], 17: [0, 1], 18: [0, 1, 2]}
SALT = "exp14b-h2h-blind-v1"
def ch_text(arm, ch):
return "\n\n".join((ARMS / arm / f"{ch}.{ck}.txt").read_text(encoding="utf-8") for ck in CHUNKS[ch])
def ch_src(ch):
return "\n".join(RECS[(ch, ck)]["source"] for ck in CHUNKS[ch])
def main():
miss = [(f, ch, ck) for f, a in FINALISTS.items() for ch in CHAPTERS for ck in CHUNKS[ch]
if not (ARMS / a / f"{ch}.{ck}.txt").exists()]
if miss:
print("⚠ нет выходов:", miss[:8]); return
key = {}
md = ["# exp14b head-to-head — P1a(дешёвый дискурс) ↔ F-disc(фронтир). Слепо.\n",
"Две версии на главу (U1/U2, порядок в каждой главе СВОЙ). Сверху китайский оригинал. "
"Оцени РАЗДЕЛЬНО: (A) какая читается лучше как русская проза; (B) верность смыслу (сверяя с "
"оригиналом) — смысловые ошибки/инверсии со спанами. Насколько дешёвый близок к фронтиру? Ключ — `_КЛЮЧ.json`, ПОСЛЕ.\n"]
for ch in CHAPTERS:
order = list(FINALISTS); random.Random(f"{SALT}-{ch}").shuffle(order)
labels = {f"U{i+1}": order[i] for i in range(len(order))}
key[str(ch)] = {lab: {"finalist": fin, "arm": FINALISTS[fin]} for lab, fin in labels.items()}
md.append(f"\n\n{'='*60}\n## Глава {ch}\n{'='*60}\n\n### ОРИГИНАЛ (zh)\n\n```\n{ch_src(ch)}\n```\n")
for lab in ("U1", "U2"):
md.append(f"\n### {lab}\n\n{ch_text(FINALISTS[labels[lab]], ch)}\n")
(OUT / "h2h.md").write_text("\n".join(md), encoding="utf-8")
(OUT / "_КЛЮЧ.json").write_text(json.dumps({"salt": SALT, "finalists": FINALISTS, "per_chapter": key}, ensure_ascii=False, indent=1), encoding="utf-8")
print(f"{OUT/'h2h.md'} (2 версии × 3 главы + оригинал)")
for ch in CHAPTERS:
print(f" гл.{ch}: " + ", ".join(f"{lab}={key[str(ch)][lab]['finalist']}" for lab in ("U1","U2")))
if __name__ == "__main__":
main()