# DSH_CoT **Repository Path**: sun-haipeng/dsh_cot ## Basic Information - **Project Name**: DSH_CoT - **Description**: 用 dsh headless CLI 逐条跑 HotpotQA 问题,导出每条会话的推理轨迹,并清洗成可直接开源的「逐行对应」数据集。 - **Primary Language**: Python - **License**: CC-BY-SA-4.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-11-16 - **Last Updated**: 2026-11-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # HotpotQA DSH Reasoning Chains 用 `dsh` headless CLI 逐条跑 HotpotQA 问题,导出每条会话的推理轨迹,并清洗成可直接开源的「逐行对应」数据集。 ## 数据集信息 | 项目 | 内容 | | --- | --- | | 数据集名称 | sunhaipeng/hotpotqa-dsh-reasoning-chains | | 地址 | https://www.modelscope.cn/datasets/sunhaipeng/hotpotqa-dsh-reasoning-chains | | 样本数量 | 7405 条(HotpotQA dev distractor,hard 级) | | 文件数量 | 2 个 JSONL,逐行一一对应 | | 文件大小 | 原始数据 46.4 MB,推理链 66.6 MB(合计约 113 MB) | | 语言 | 英文(问题与答案),推理链含模型思考文本 | | 任务类型 | 多跳问答(multi-hop QA)、推理链 / 工具调用轨迹 | | 许可 | CC BY-SA 4.0 | | 数据来源 | HotpotQA(https://hotpotqa.github.io/)派生 | | 生成框架 | dsh headless CLI(本地文件工具模式) | ## 数据集 两个 JSONL 文件,**每行一条样本**,用 `_id` 一一对应(行序完全一致),方便逐条对比「原始问题」与「模型推理过程」。 | 文件 | 说明 | 许可 | | --- | --- | --- | | `hotpot_dev_distractor_v1.jsonl` | 原始 HotpotQA dev distractor(hard 级,7405 条),从官方 JSON 数组转成逐行 JSONL | CC BY-SA 4.0 | | `hotpot_dev_distractor_v1.reasoning_chains.jsonl` | 对应每条问题的完整推理链(思考 → 工具调用 → 工具结果 → 最终答案) | CC BY-SA 4.0 | ### 原始数据字段(`hotpot_dev_distractor_v1.jsonl`) 每条即 HotpotQA 官方样本: ```json { "_id": "5a8b57f25542995d1e6f1371", "answer": "yes", "question": "Were Scott Derrickson and Ed Wood of the same nationality?", "supporting_facts": [["Edward D. Wood Jr.", 0], ...], "context": [["Title", ["sent0", "sent1", ...]], ...], "type": "comparison", "level": "hard" } ``` ### 推理链字段(`hotpot_dev_distractor_v1.reasoning_chains.jsonl`) 每条与原始数据共享同一个 `_id`: ```json { "_id": "5a8b57f25542995d1e6f1371", "question": "Were Scott Derrickson and Ed Wood of the same nationality?", "answer": "yes", "type": "comparison", "level": "hard", "steps": [ { "step": 1, "reasoning": "模型这一步的思考文本", "tool_calls": [ { "name": "bash", "arguments": {"command": "ls -la"}, "result": "total 80\n..." }, { "name": "grep", "arguments": {"pattern": "Derrickson|nationality"}, "result": "Found 20 matches\n..." } ], "text": null } ], "final_answer": "Yes — both were American. ..." } ``` 字段说明: - `steps`:按 DSH 会话的 `step` 分组,每一步含 `reasoning`(思考)、`tool_calls`(工具调用,含 `name`/`arguments`/`result`)、`text`(该步产出的文本)。 - `final_answer`:模型给出的最终答案(取自最后一步的文本)。 ### 逐条对比示例 ```python import json raw = [json.loads(l) for l in open("hotpot_dev_distractor_v1.jsonl")] chains = [json.loads(l) for l in open("hotpot_dev_distractor_v1.reasoning_chains.jsonl")] # 两个文件行序一致、_id 一致 assert len(raw) == len(chains) == 7405 assert [r["_id"] for r in raw] == [c["_id"] for c in chains] # 取第 0 条对比:问题 + 推理链 print(raw[0]["question"]) # 原始问题 print(chains[0]["final_answer"]) # 模型答案 for s in chains[0]["steps"]: print(s["step"], s["reasoning"], [t["name"] for t in s["tool_calls"]]) ``` ## 如何得到推理链 完整流程分三步,脚本都在 `dsh_generation/` 下。 ### 1. 批量运行 DSH,导出原始会话轨迹 主入口 [generate_dsh_chains.ipynb](dsh_generation/generate_dsh_chains.ipynb): - 读取 `data/hotpot_dev_distractor_v1.json`,把每条问题的 `context` 写成 `doc_XX.txt` 文件; - 用 `dsh --profile headless --patch dsh.patch.yml` 逐条运行,导出 `~/.dsh/sessions/` 下的 `session.v4.jsonl.zstd`,解压为 `output/chains/XXXXX_.jsonl`。 ### 2. 角色与模型配置 [dsh.patch.yml](dsh_generation/dsh.patch.yml) 定义了: - 模型供应商(`aliyun-qwen-api` / `amd-radeon-cloud`)与默认模型; - 人设(`personaPrefix`):只允许使用本地文本文件,用 `grep`/`glob` 定位并读取,禁用 `web_search`/`web_fetch`,答案要求简洁。 ### 3. 提取并脱敏成推理链 [extract_clean_chains.py](dsh_generation/extract_clean_chains.py): - 从 `output/chains/*.jsonl` 筛选 `assistant/message`(reasoning / tool-call / text)和 `tool/result`; - 剥离 DSH 冗余字段(系统提示词、工具 schema、逐 token stream、replayState、job 事件等); - 递归替换本机绝对路径、用户名、密钥文件名等敏感信息; - 输出 `hotpot_dev_distractor_v1.reasoning_chains.jsonl`,行序与原始数据一致。 ```bash python3 dsh_generation/extract_clean_chains.py ``` ## 许可 - 原始数据 `hotpot_dev_distractor_v1.jsonl` 来自 [HotpotQA](https://hotpotqa.github.io/),按 [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/) 许可分发,署名归 HotpotQA 原始作者。 - 推理链 `hotpot_dev_distractor_v1.reasoning_chains.jsonl` 是基于 HotpotQA 的派生数据,同样按 CC BY-SA 4.0 分发,须以相同方式共享。 - 仓库代码与脚本同样以 CC BY-SA 4.0 发布。 完整许可条款见 [LICENSE](LICENSE)。