smolcua / make_v13.py
appvoid's picture
Release SmolCUA v1.3: 2,000-example default
f966660 verified
Raw History Blame Contribute Delete
4.13 kB
"""Reproducible 2,000-instance SmolCUA subset, retaining five passes."""
from collections import defaultdict, Counter
import hashlib
import json
from pathlib import Path
SOURCE_SHA256 = '73c70dff7e46ee57140be9aea173a8dc0f3117f8c2989afcbfaadcb47bb4a0c4'
PROTOCOL = 'cognirank-v3-smolcua-2000'
def prepare_subset(source, destination):
source, destination = Path(source), Path(destination)
manifest = json.loads((source/'manifest.json').read_text())
data = (source/'questions_all_passes.jsonl').read_bytes()
if hashlib.sha256(data).hexdigest() != SOURCE_SHA256:
raise ValueError('CogniRank SmolCUA source differs from pinned v1.2')
rows = [json.loads(line) for line in data.splitlines() if line.strip()]
groups = defaultdict(list)
for row in rows:
if row['pass'] == 1:
groups[row['category'], row['response_format']].append(row['item_id'])
if len(groups) != 100 or any(len(v) != 10 for v in groups.values()):
raise ValueError('Unexpected SmolCUA category/format strata')
key = lambda item: hashlib.sha256((PROTOCOL+':'+item).encode()).hexdigest()
chosen = {item for values in groups.values() for item in sorted(values, key=key)[:4]}
selected = [r for r in rows if r['item_id'] in chosen]
if len(chosen) != 400 or len(selected) != 2000:
raise ValueError('Unexpected SmolCUA subset size')
for p in range(1,6):
counts = Counter(r['category'] for r in selected if r['pass'] == p)
if len(counts) != 10 or set(counts.values()) != {40}:
raise ValueError('Unbalanced SmolCUA subset')
ids = {r['id'] for r in selected}
by_id = {r['id']:r for r in selected}
destination.mkdir(parents=True,exist_ok=True)
(destination/'private').mkdir(exist_ok=True)
def write(path, records):
data = ''.join(json.dumps(r,ensure_ascii=False,separators=(',',':'))+'\n' for r in records).encode()
path.write_bytes(data)
return hashlib.sha256(data).hexdigest()
question_sha = write(destination/'questions_all_passes.jsonl',selected)
for p in range(1,6):
write(destination/f'pass_{p:02d}_questions.jsonl',[r for r in selected if r['pass']==p])
scoring = {}
for name in ('answers_all_passes.jsonl','weights_all_passes.jsonl'):
data = (source/'private'/name).read_bytes()
if hashlib.sha256(data).hexdigest() != manifest['scoring_file_sha256'][name]:
raise ValueError('SmolCUA scoring source integrity mismatch')
records = [json.loads(line) for line in data.splitlines() if line.strip()]
records = [r for r in records if r['id'] in ids]
if len(records) != len(ids):raise ValueError('Missing subset scoring records')
if name.startswith('weights'):
totals = defaultdict(float)
for r in records:
q=by_id[r['id']];totals[q['pass'],q['category']] += r['max_points']
for r in records:
q=by_id[r['id']]
r['max_points'] *= manifest['category_points'][q['category']]/totals[q['pass'],q['category']]
scoring[name] = write(destination/'private'/name,records)
subset = {k:manifest[k] for k in ('benchmark','version','seed','passes','category_points')}
subset.update(version="1.3",edition="compact-2000",selection_protocol=PROTOCOL,questions_per_pass=400,total_instances=2000,
categories={c:40 for c in manifest['categories']},question_file_sha256=question_sha,
scoring_file_sha256=scoring,source_question_file_sha256=SOURCE_SHA256,
selection='SHA256-ranked four item positions per category/response-format stratum in pass 1, retained across all five passes',
selected_item_ids=sorted(chosen),notes='CogniRank subset; category budgets renormalized to 100 per pass; not the full SmolCUA score.')
(destination/'manifest.json').write_text(json.dumps(subset,indent=2)+'\n')
return destination
if __name__ == '__main__':
base=Path(__file__).resolve().parent
result=prepare_subset(base/'runs/v1_2_seed_20261023',base/'runs/v1_3_seed_20261023')
print('Built SmolCUA v1.3:',result)