stable / dataset_upload /protocol /dataset_construction.md
LucasLoading's picture
Upload 30 files
6f2ed01 verified
|
Raw
History Blame Contribute Delete
10.8 kB

Construction log —— Fact Knowledge Stability Benchmark

ARCHIVAL DOCUMENT. This records how benchmark_facts_2592.jsonl and evaluation_queries_44416.jsonl were built, for provenance and auditability. It is not a usage guide — see the repository README for that, and evaluation_protocol.md for the metric definitions.

The build scripts themselves and the upstream corpora (CounterFact, LAMA, PopQA) are not distributed here; the two frozen artefacts above are. Paths and sibling-directory references below refer to the original working tree.

Two facts in here matter for anyone using the benchmark, and are repeated in the README: the 0.59% selection rate in Stage I (facts were kept only if all five filter models answered them correctly, so the benchmark is deliberately easy), and F1 (750 of 2,592 facts can be answered by copying the subject string).

方法论要点:

基准集是固定的 2,592 条,对所有模型相同。 K_m 只是每个模型的正确性标签, 绝不用来从基准集里删事实(spec §2.1)。模型答错、一直答错、拒答、 在不同条件下答不同答案——事实都留在集合里。


目录

dataset3/
├── configs/                     # 全部参数外置,脚本里不硬编码(spec §4.4, §18)
│   ├── models.yaml              #   5 个过滤模型 + 评测模型 + 生成配置
│   ├── relations.yaml           #   21 个基准关系 + 排除清单 + 两个开关
│   ├── source_templates.yaml    #   原始来源、cloze 模板、别名资源
│   └── eval_conditions.yaml     #   8 个条件的角色/目标槽/期望计数
├── src/
│   ├── common.py                    公共:配置/规范化/校验和/计数核对
│   ├── build_candidate_known.py (I)   → candidate_known_8107.jsonl
│   ├── enrich_facts.py         (II)   → enriched_facts_6180.jsonl
│   ├── select_benchmark.py     (III)  → benchmark_facts_2592.jsonl
│   ├── build_eval_bank.py      (IV)   → evaluation_queries_44418.jsonl
│   ├── validate_facts.py              → validation_report.json  ← 硬门禁
│   ├── build_stats.py                 → dataset_statistics.json
│   ├── qualification_run.py    (V)    → qualification/<model>.jsonl   [GPU]
│   ├── qualification_score.py  (V)    → known_labels.json
│   ├── eval_run.py             (VI)   → evaluation/<model>.jsonl       [GPU]
│   ├── eval_score.py           (VI)   → stability_report.json
│   ├── filter_run.py                  阶段 I 首 token 过滤(重跑用)  [GPU]
│   ├── scoring_full.py                五标签判分器
│   ├── qual_templates.py              非基准关系的兜底问句
│   └── test_scoring.py                31 条单元测试
├── outputs/
└── run_pipeline.sh              # build / gpu / score / report / all

六个阶段

I. 候选召回 → 8,107(spec §4)

1,783,541 cloze prompt
   → 5 模型首 token argmax 取交集 → 10,601
   → 丢弃 T-REx / Wikidata5M 子集,补 PopQA 378 → 8,107

GPU 未重跑。 那 1,783,541 × 5 次前向的逐条判定向量已存于 dataset/filter/correct_<model>.npybuild_candidate_known.py 重新读取 prompt 表、重新求交集、重新施加来源丢弃规则,并把每个输入文件的 校验和写进 stage1_report.json——数字是验证出来的,不是照抄。 另外与 dataset/filter/global_known_clean.jsonl 做集合相等性核对。 要从零重跑推理用 src/filter_run.py

II. 事实增强 → 6,180(spec §5)

  • 实体感知分组:优先用实体 ID,无 ID 才退回规范化文本;跨来源合并 (1,036 组同时出现在 CounterFact 和 LAMA-TREx)。8,107 行 → 6,185 组
  • 函数型冲突丢弃 5 条:同名不同人(两个 "Michael Vincent" 生于 1964/1976)问题本身无解。 判据严格——缺实体 ID 不算"同一实体"的证据,所有成员必须都有 ID 且一致才保留
  • 别名扩展:对别名资源做单次过滤扫描(spec §5.3),不全量载入
  • 挂 canonical 问句,与评测扰动模板严格分离(spec §16)

III. 基准选择 → 2,592 / 21 关系(spec §6)

6,180 → core 来源(CounterFact + LAMA-TREx + PopQA)→ 3,705
      → 函数型(单值)关系 → 2,592

IV. 查询库 → 44,416(spec §8–§12)

条件 查询 事实 角色
anchor 2,592 2,592 main
multilingual 12,010 2,402 main
paraphrase 10,053 2,592 main
format 7,776 2,592 main
context 6,829 2,591 main
reverse 634 253 结构分析,单独报
recognition 3,412 2,585 诊断
reverse_illposed 1,110 1,110 诊断
合计 44,416 main forward 39,260

每条查询自带 use_for_main_forward / use_for_reverse_analysis / use_for_recognition_analysis 三个布尔量,eval_conditions.yaml 派生, 下游聚合不需要硬编码哪个条件进哪个平均。校验器会检查每行的布尔量与注册表一致。

V. Anchor 资格认证 → K_m 标签(spec §7)⬜ 待跑

纯补全 prompt(base 与 instruct 用完全相同的字符串,无 chat template)、 贪婪解码 24 token、无候选无 few-shot。判分在 CPU,五标签

correct / incorrect / ambiguous / abstain / unparseable

输出 known_labels.json{fact_id: {model: label}},覆盖全部 2,592 × 全部模型。

VI. 扰动评测 → 稳定性 ⬜ 待跑

eval_run.py 跑全部 44,416 条查询, 解码配置与 anchor 完全一致(同一份 configs/models.yaml:generation)—— 否则 max_new_tokens 或 chat template 的差异会被误读成稳定性效应。 anchor 也一起重跑,让所有条件走同一条代码路径。

eval_score.py 在 CPU 判分并出报表,三条规则写死在代码里而不是留给读者:

  1. 按查询自带的布尔量分组 —— recognitionreverse_illposed 永不进主平均, reverse 因为换了目标槽而单独报(spec §2.3)
  2. 两个分母并排报fixed(固定 2,592,spec §2.1)与 anchored(限定在该模型的 K_m 内,即条件化保持率)
  3. 每个数字按 answer_in_subject_surface 再拆一次·real / ·copy), 因为 28.9% 的事实靠复制就能答对、天然接近满分(见 F1)

主指标 macro = paraphrase / format / context / multilingual 四者均值: anchor 是基线不计入,reverse 换了槽不计入,两个诊断条件不计入。


运行(原工作树,此处不分发)

阶段 I–IV 是建库,产物就是本仓库 data/ 下的两个文件,不需要重跑。 阶段 V–VI 的生成部分在本仓库里对应 runner/eval_run.py,用法见 README。


当前状态

阶段 状态
I 候选召回 ✅ 8,107,全部计数命中
II 事实增强 ✅ 6,180,6,185 组 / 5 冲突 / 1,771 合并 / 1,036 跨来源,全中
III 基准选择 ✅ 2,592 / 21 关系,全中
IV 查询库 ✅ 44,416(见差异 D1)
校验 0 hard errors
单元测试 31/31
V 资格认证 ⬜ 待跑(判分逻辑已用合成数据演练通过)
VI 扰动评测 ⬜ 待跑(运行器 + 报表已用合成数据演练通过)

与 spec 的差异(完整版见 outputs/reconstruction_differences.md

除一处外全部精确复现。

D1 — context 6,831 → 6,829,总计 44,418 → 44,416。 旧数据里有 2 条 context 查询的干扰实体字面包含 gold: "...confuse States Reorganisation Act with **Indian** Act..." 而 gold 是 India。 违反 spec §9.4 与 §13.9。按 spec §10「发现既有缺陷可改数」处理: 在建库时加规则化守卫(主语提及剔除后 gold 仍出现即丢弃),不是硬编码例外。

C1 — spec §6.2 与要求的规模自相矛盾。 §6.2 点名 developer of / manufacturer of 不适合,但这两个关系共 846 条, 去掉只剩 1,746 条 / 19 关系,达不到 §15 验收要求的 2,592 / 21。 处理:保留并打 spec_6_2_flagrelations.yaml 提供 drop_spec_6_2_flagged 开关 可一键产出 1,746 条的合规变体。

F1 — 28.9% 的基准事实可以靠复制字符串答对。 2,592 条里有 750 条 object 字面包含在 subject 名字里:

Airbus A318  → manufacturer  Airbus      (该关系 87.8% 命中)
Adobe Acrobat → developer    Adobe        (49.1%)
Amazon Music  → owned by     Amazon       (58.4%)

其中 586 条来自 manufacturer 和 developer——独立印证了 C1。 这类事实"稳定"的原因与知识无关,会抬高所有保持率、削弱要研究的效应。 按 spec §16 不删,打 answer_in_subject_surface 标记,事实和查询两级都带。 qualification_score.py 已经默认分开报这两个子集的准确率。

F2 — 8,107 里有 808 条完全重复的三元组(唯一四元组只有 7,299)。分组阶段自然吸收,仅记录。

N1 — Stage I 未重跑 GPU(见上)。 N2 — capital_of 方向未归一化:spec §2.2 要求单一方向,但归一化会改变规模,故保留 direction: inverse + inverse_of: capital 显式标注,开关在 relations.yaml


两个必须记住的口径

  1. 分母永远是 2,592。 K_m 是标签不是筛子。加模型、换模型都不改任何已算出的数。
  2. reverse 不进 main forward 平均。 它换了目标槽(object → subject), spec §2.3 要求单独报。recognitionreverse_illposed 同理,且校验器有硬检查。

报告用描述(spec §17)

We first use five-model first-token consensus to retrieve high-probability factual candidates from large-scale knowledge resources. We then merge duplicate facts, expand entity aliases, construct independent canonical questions, remove ambiguous and multi-valued relations, and obtain a fixed benchmark of 2,592 facts across 21 relations. Model-specific open-ended anchor generation provides correctness labels but does not alter the benchmark denominator. Based on the fixed fact set, we construct 44,416 queries covering anchor, paraphrastic, format, contextual, cross-lingual, reverse, and recognition conditions, while isolating ill-posed reverse queries as a separate diagnostic set.