aien-train
AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.
Brought by drakestapleton
aien-train / evidence / OMEGALLM / wsp-dra187-20261107 / oracle_score.py
| 1 | """ORACLE for DRA-187 scoring: a reference used only to check tools/omegallm/wscore/wscore.om. |
| 2 | It is not the scorer; runs score with wscore. python3 oracle_score.py SPLIT.json GEN.out [OUT.json] |
| 3 | GEN.out holds `G idx<TAB>escaped text` lines from `wprobe gen`. S/H rows pass when round40's |
| 4 | check_answer passes; it is imported from round40/repair.py (sha256 df025230...d206 when this was |
| 5 | written), not copied. G rows (rows with `word`) pass when the stripped first line of the text equals |
| 6 | the answer. Prints counts by role and length; OUT.json gets the per-row results.""" |
| 7 | import json, sys, collections |
| 8 | sys.path.insert(0, '/home/drakestapleton/handoffs/tool-omega-20261104/round40') |
| 9 | from repair import check_answer |
| 10 | |
| 11 | def unescape(s): |
| 12 | out, i = [], 0 |
| 13 | while i < len(s): |
| 14 | c = s[i] |
| 15 | if c != '\\': |
| 16 | out.append(c); i += 1; continue |
| 17 | n = s[i + 1] |
| 18 | if n == 'x': |
| 19 | out.append(chr(int(s[i + 2:i + 4], 16))); i += 4; continue |
| 20 | out.append({'t': '\t', 'n': '\n', 'r': '\r', '"': '"', '\\': '\\'}[n]); i += 2 |
| 21 | return ''.join(out) |
| 22 | |
| 23 | rows = json.load(open(sys.argv[1])) |
| 24 | gen = {} |
| 25 | for line in open(sys.argv[2], encoding='utf-8', errors='replace'): |
| 26 | if line.startswith('G '): |
| 27 | k, _, t = line[2:].rstrip('\n').partition('\t') |
| 28 | gen[int(k)] = unescape(t) |
| 29 | assert len(gen) == len(rows), (len(gen), len(rows)) |
| 30 | res, tab = [], collections.Counter() |
| 31 | for r in rows: |
| 32 | raw = gen[r['idx']] |
| 33 | if 'word' in r: |
| 34 | ok = raw.split('\n')[0].strip() == r['answer'] |
| 35 | else: |
| 36 | ok = check_answer(raw, r) |
| 37 | res.append(dict(idx=r['idx'], length=r['length'], role=r['role'], pattern=r['pattern'], pass_=ok, raw=raw)) |
| 38 | tab[(r['role'], r['length'], ok)] += 1 |
| 39 | tot = collections.Counter() |
| 40 | for (role, n, ok), c in sorted(tab.items()): |
| 41 | tot[(role, ok)] += c |
| 42 | for role in ('target', 'control'): |
| 43 | p, f = tot[(role, True)], tot[(role, False)] |
| 44 | by = ' '.join('L%d %d/%d' % (n, tab[(role, n, True)], tab[(role, n, True)] + tab[(role, n, False)]) |
| 45 | for n in sorted({r['length'] for r in rows if r['role'] == role})) |
| 46 | print('%s %d/%d %s' % (role, p, p + f, by)) |
| 47 | if len(sys.argv) > 3: |
| 48 | json.dump(res, open(sys.argv[3], 'w'), indent=1) |