Datasets:
Download examples/run_reference_example.py from dengzhe-hou/HumanDec: direct link, hf CLI and curl.
- Browser
- Download file 3.51 kB
-
https://huggingface.co/datasets/dengzhe-hou/HumanDec/resolve/main/examples/run_reference_example.py
- Command line
-
hf download hf://datasets/dengzhe-hou/HumanDec/examples/run_reference_example.py
-
curl -L -o run_reference_example.py https://huggingface.co/datasets/dengzhe-hou/HumanDec/resolve/main/examples/run_reference_example.py
3.51 kB
| """Use bundled model predictions with the existing four-file paired example.""" | |
| import argparse | |
| import json | |
| import subprocess | |
| import sys | |
| from pathlib import Path | |
| def main(): | |
| p = argparse.ArgumentParser(description=__doc__) | |
| p.add_argument('--bundle', type=Path, required=True) | |
| p.add_argument('--protocol', default='external/low-pass/source_nonoverlap') | |
| p.add_argument('--pair', choices=('qwen/intern', 'lfm/d1'), default='qwen/intern') | |
| p.add_argument('--seed', type=int, choices=(0, 1, 2), default=0) | |
| p.add_argument('--output', type=Path, required=True) | |
| a = p.parse_args() | |
| from hudec.bundle import Bundle | |
| bundle = Bundle(a.bundle) | |
| base, decision = a.pair.split('/') | |
| keys = [('before-base', base, 'untrained-fixed'), | |
| ('before-decision', decision, 'untrained-fixed'), | |
| ('after-base', base, f'human-seed{a.seed}'), | |
| ('after-decision', decision, f'human-seed{a.seed}')] | |
| cases = {flag: bundle.baseline(f'common-selection/{a.protocol}/{model}_{target}') | |
| for flag, model, target in keys} | |
| command = [sys.executable, '-B', str(Path(__file__).with_name('paired_change_example.py')), | |
| '--bundle', str(bundle.root), '--protocol', a.protocol, '--output', str(a.output)] | |
| for flag, _, _ in keys: | |
| command.extend(['--' + flag, str(bundle.root / cases[flag]['predictions'])]) | |
| subprocess.run(command, check=True) | |
| report = json.loads(a.output.read_text()) | |
| report['reference_cases'] = {flag: {'case_id': row['case_id'], 'metadata': row['metadata']} | |
| for flag, row in cases.items()} | |
| report['reference_pair'] = a.pair | |
| report['reference_training_seed'] = a.seed | |
| a.output.write_text(json.dumps(report, indent=2, allow_nan=False)) | |
| lines = ['# 决策模型前后配对评分', '', f"本例使用已完成的{a.pair}、种子{a.seed},协议为`{a.protocol}`。没有训练或模型推理。", '', | |
| '| 指标 | 适配前决策减底座 | 适配后决策减底座 | 配对变化及95%区间 |', | |
| '| --- | --- | --- | --- |'] | |
| names = {'nll': '人类选择NLL', 'kappa': '正确错误κ', 'wrong_label': '双方均错时答案一致率', 'accuracy': '每图等权正确率'} | |
| for metric, name in names.items(): | |
| pre, post, change = [report[key][metric] for key in ('pre_gap', 'post_gap', 'adaptation_change')] | |
| def value(row): | |
| return '未定义' if row['point'] is None else f"{row['point']:+.6f}" | |
| ci = '区间未定义' if change['ci95'] is None else f"[{change['ci95'][0]:+.6f}, {change['ci95'][1]:+.6f}]" | |
| lines.append(f"| {name} | {value(pre)} | {value(post)} | {value(change)} {ci} |") | |
| lines.extend(['', 'NLL变化为正表示决策模型的相对优势减弱,其他三项变化为负表示减弱。区间含0表示这项比较没有确定方向,不表示等效。相对优势减弱也不表示两个模型都变差。', '', | |
| '四组使用相同目标、类别顺序及2000次刺激与观察者配对抽样,外部按原图聚类。全部组的点估计、区间、覆盖和未定义次数保存在JSON中。', '', | |
| '来源验证选模与校准固定。这里的前后变化不能单独区分人类标签作用、其他微调目标或权重与校准因素,也不是内部视觉机制的因果定位。']) | |
| a.output.with_suffix('.md').write_text('\n'.join(lines) + '\n', encoding='utf-8') | |
| if __name__ == '__main__': | |
| main() | |