
Open-Assistant 数据集工程实践SODA Synthetic Dialogue 合成对话数据集的构建、加载与训练接入指南【免费下载链接】Open-AssistantOpenAssistant is a chat-based assistant that understands tasks, can interact with third-party systems, and retrieve information dynamically to do so.项目地址: https://gitcode.com/gh_mirrors/op/Open-AssistantSODA Synthetic Dialogue 是 Open-Assistant 仓库中一个用于对话生成dialogue-generation任务的大规模合成数据集它从 SODA 原始故事对话数据出发通过模板化改写生成 150 万条以上的「User–Assistant」多轮对话覆盖摘要、故事续写、标题生成与主题抽取等指令形态。本文将基于 数据集卡片 的完整说明结合仓库内的生成脚本、Hugging Face 加载脚本与模型训练端代码逐步拆解该数据集的构建原理、数据结构、加载方式以及接入 SFT 训练链路的具体方法读完即可在本地复现生成流程并直接复用它训练对话模型。一、数据集概览它是什么、解决什么问题SODA Synthetic Dialogue 是一组在Assistant与User之间展开的合成对话。每条对话中User 会基于一段已有的对话片段、故事或者一个标题/主题向 Assistant 提出摘要、故事续写或故事生成类任务。其核心价值在于把原本故事叙述体的 SODA 语料通过一套模板系统转化为指令-回答形态的对话语料从而更适合用来训练具备指令跟随能力的对话式语言模型。根据数据集卡片 frontmatter 中的元信息该数据集的客观属性如下属性取值pretty_nameSODA Synthetic Dialogueannotations_creatorsno-annotation无人工标注机器生成language / multilingualityen / monolingual纯英文licensemitsize_categories1M n 10Msource_datasetsextended | allenai/sodatask_categories / task_idsconversational / dialogue-generationconfig_namesoda_synthetic_dialogue_dialogue_modeling三个官方切分的规模来自卡片 frontmattersplitnum_examplesnum_bytestrain1,191,5821,524,941,476test148,968190,565,707validation146,346187,161,878数据集整体下载体积约 1.95 GBdownload_size展开后约 1.9 GBdataset_size。数据集由 ontocord 原创合成思路最初以 Colab notebook 形式公开后由 Jeffrey Quesnelle 整理为 Hugging Face 数据集格式。其生成依据是 SODA 原始研究论文arXiv:2212.10465。二、数据形态与典型样本解读数据集卡片给出了一个完整示例。这条样本对应场景续写 标题 摘要 主题四段式交互完整还原了模板化合成的输出形态User: Can you write the next few lines of dialogue for this scene: Cornell: I know what youre thinking, Dontrell. I can sense your feelings and know exactly what youre going to say or do next. Youre thinking about how much you miss your family, and how you wish you could see them again. Youre wondering if theres anything you can do to make that happen. And youre also feeling a little guilty, because you know that if you could see them again, it would only be for a short while before they died. Dontrell: Cornell, how can you possibly know all that? Its like you can read my mind! Assistant: Sure, the next dialogue for this scene could be: Cornell: I told you, I can sense your feelings. Its like I have a connection to your thoughts and emotions. Im not sure why or how it works, but ever since we met, Ive been able to understand what youre thinking and feeling pretty easily. Dontrell: Wow...thats amazing! And a little bit scary too. But it does explain why weve always been so close - even though weve only known each other for a few months. Cornell: Yeah, I guess our connection is pretty strong. But dont worry, Dontrell - Ill never use it to manipulate or control you in any way. I promise. Dontrell: Thats a relief! I was starting to feel a little bit like you could read my mind, and it was kind of creepy. But if you promise not to use your abilities to control me, then Im okay with it. Cornell: I swear, Dontrell. Ill never use my abilities to control or manipulate you in any way. You have my word. User: And a title? Assistant: Sure, a title for this dialogue could be: Cornell is intuitive. Cornell reads Dontrells mind. User: How about a short description? Assistant: Sure, a short description for this dialogue could be: Cornell knows what Dontrell is thinking. He can sense her feelings and know exactly what she is going to say or do next. User: What would be one theme of this story? Assistant: One theme of this story could be: being intuitive从样本中可以归纳出该数据集的几个关键特征对话固定由User:与Assistant:前缀标注角色轮换清晰便于下游做角色切分场景文本以两个空格缩进逐行呈现Assistant 的续写内容同样保持缩进保留原文的对白结构每条样本末尾通常会追加主题theme问答为模型提供从故事中归纳主题的额外监督信号对话正文被存为单条字符串不会拆分成结构化的多轮字段。三、数据是怎么造出来的模板系统与合成管线数据集的合成逻辑全部实现在 prepare.py 中。该脚本以allenai/soda为源数据逐条读取故事样本通过一套固定模板 随机分支的策略将故事重构为对话指令任务。3.1 九大对话模板脚本顶部集中定义了合成所用到的全部模板模板中的{}为待填充字段模板常量任务形态填充字段SUMMARY_TEMPLATE基于对话生成故事摘要 标题dialogue、story、titleTHEME_TEMPLATE抽取故事主题追加段themeNEW_DIALOGUE_TEMPLATE基于故事新写一段对话 标题story、dialogue、titleNEXT_LINES_TEMPLATE基于场景续写后续对白 标题 摘要scene、dialogue、title、storyNEW_STORY_AND_DIALOGUE_TEMPLATE基于标题片段写故事title1、storyFULL_DIALOGUE_TEMPLATE在故事后追加完整对话conversation、dialogueMORE_DIALOGUE_TEMPLATE在已有对话上追加更多对白conversation、dialogue1、title2、dialogue2NEXT_DIALOGUE_TEMPLATEMore please 式追加对话conversation、dialogue1、dialogue2NEW_STORY_AND_DIALOGUE_FROM_THEME_TEMPLATE基于主题写故事 对话 标题theme、story、dialogue、title以NEXT_LINES_TEMPLATE为例其模板原文为User: Can you write the next few lines of dialogue for this scene: {scene} Assistant: Sure, the next dialogue for this scene could be: {dialogue} User: And a title? Assistant: Sure, a title for this dialogue could be: {title} User: How about a short description? Assistant: Sure, a short description for this dialogue could be: {story}对比第一节的示例样本可以发现数据集卡片中的示例正是由该模板并追加THEME_TEMPLATE生成的二者在措辞、缩进和轮次结构上完全一致。3.2 主题theme的推导规则SODA 原始数据中的每条样本带有relation如xWant、xNeed等常识关系类型和tail关系宾语prepare.py 据此推导出主题短语relation xWant→theme wanting tailrelation xNeed→theme needing tailtail不以to、and开头 →theme being tailtail以and开头 →theme people are tail.replace(and PersonY , )其余情况 → 直接取tail。随后还有两处全局清洗theme.replace(PersonY, another person)把模板中的泛指角色替换为更自然的表述theme.replace(being is, being)修正语法冗余。示例样本结尾的being intuitive正是该规则链的产物。3.3 随机分支从同一条故事派生五种任务脚本使用random.seed(42)固定随机种子保证可复现对每条 SODA 样本按嵌套的随机数分支决定最终对话形态分支一概率约 1/7摘要任务——套用SUMMARY_TEMPLATE把完整对话作为输入、故事与标题作为输出有 theme 则追加THEME_TEMPLATE分支二概率约 1/7故事反写对话——套用NEW_DIALOGUE_TEMPLATE把故事作为输入、对话与标题作为输出分支三概率约 1/3续写任务——把原始对话按尾部 3/4/5 行切分为场景 续写两段套用NEXT_LINES_TEMPLATE卡片示例即来自此分支分支四概率约 1/3故事 对话组合——以标题第一句为输入写故事再以 50% 概率随机选择完整对话多续一段对话More please 续写等子分支对应FULL_DIALOGUE_TEMPLATE、MORE_DIALOGUE_TEMPLATE、NEXT_DIALOGUE_TEMPLATE默认分支主题驱动生成——套用NEW_STORY_AND_DIALOGUE_FROM_THEME_TEMPLATE以主题为输入生成故事、对话与标题。这种同一源数据、多样任务形态的设计天然制造了对话轮数、任务类型和长度分布的多样性有助于提升下游模型的泛化能力。3.4 输出格式每条样本最终被序列化为一行 JSON写入对应的data/{split}.jsonloutput.write(f{json.dumps({conversation: conversation})}\n)即每条样本只有一个字段conversation字符串与数据集卡片中声明的 feature 完全对应。脚本同时支持--print参数PRINT len(sys.argv) 1 and sys.argv[1] --print用于在控制台逐条预览生成的对话。四、Hugging Face 加载脚本把 jsonl 变成标准 dataset为了将本地生成的 jsonl 文件包装成标准 Hugging Face 数据集仓库提供了完整的加载脚本 soda_synthetic_dialogue.py配套的公共配置与特征定义位于 hub.py。关键实现点如下特征定义hub.pyfeatures datasets.Features({conversation: datasets.Value(string)})与卡片声明的单字段结构一致配置定义BUILDER_CONFIGS中注册唯一配置soda_synthetic_dialogue_dialogue_modelingschemadialogue_modeling并设为DEFAULT_CONFIG_NAME即数据集卡片中标注的config_name数据源路径_URLS将 train/test/validation 三个切分映射到本地./data/train.jsonl、./data/test.jsonl、./data/validation.jsonl正好对应 prepare.py 的产出目录结构数据读取_generate_examples按行读取 jsonl对每行json.loads后以自增 key 逐条 yield即标准GeneratorBasedBuilder的流式读法。也就是说完整的复现链路是先运行prepare.py生成data/目录下的三个 jsonl 文件再通过该加载脚本即可load_dataset(soda_synthetic_dialogue)得到带 train/test/validation 三个 split 的 Hugging Face 数据集对象。五、在 Open-Assistant 训练链路中的实际接入方式SODA Synthetic Dialogue 不仅是仓库中的一个数据集还真实接入了模型训练端可以从源码中看到两条接入路径。5.1 训练端数据集类SODADialogue在 qa_datasets.py 中定义了SODADialogue类model/model_training/custom_datasets/qa_datasets.py#L283-L315它直接加载emozilla/soda_synthetic_dialogue遍历全部三个 split对每条样本的conversation字段按User: 切分丢弃首段空串再对每一段按\nAssistant: 拆成「问题、回答」二元组对切分失败对话内容里混有多余的User:/Assistant:标记的样本计数为 fault 并跳过——这是对模板化数据中偶发格式噪声的容错处理最终把每个对话整理成(question, answer)交替的元组序列供下游 SFT 使用。可见该数据集在训练端是以纯对话建模方式使用的与其dialogue_modeling的 schema 命名相呼应。5.2 配置文件与数据集注册在 custom_datasets/init.py 中soda_dialogue被注册为SODADialogue(data_path)同文件soda则注册为原始 SODA 的SODA类在 configs/config.yaml 的sft_datasets列表中同时出现soda带input_max_length: 1024参数与soda_dialogue说明两者可一起参与 SFT 训练在 check_dataset_appearances.py 与 check_dataset_counts.py 的示例命令中soda均被列入 sft 模式的数据集名单用于检查数据集出现次数与统计样本量。此外数据集卡片中的引用citation同样被完整固化在加载脚本的_CITATION字段中确保使用该数据训练时可以被正确引用article{ontocord2023sodasynth, author {ontocord and Jeffrey Quesnelle}, title {SODA Synthetic Dialogue}, year {2023} }六、从零复现本地生成与加载的完整步骤综合上述源码可以在本地完整复现该数据集的生成与加载流程准备源数据与依赖安装datasets与tqdm确保可访问allenai/sodaprepare.py 通过load_dataset(allenai/soda)拉取原始数据运行生成脚本python data/datasets/soda_synthetic_dialogue/prepare.py脚本会以random.seed(42)的固定随机序列在data/目录下生成train.jsonl、test.jsonl、validation.jsonl三个 UTF-8 编码的 jsonl 文件每行形如{conversation: User: ...\nAssistant: ...}。如需预览生成效果可追加--print参数python data/datasets/soda_synthetic_dialogue/prepare.py --print加载为 Hugging Face 数据集在data/datasets/soda_synthetic_dialogue/目录下或把_URLS指向对应 jsonl 路径后使用datasets.load_dataset加载soda_synthetic_dialogue配置soda_synthetic_dialogue_dialogue_modeling即可得到含 train/test/validation 三个 split、每个样本仅含conversation字段的标准数据集对象接入训练在模型训练端可直接在 configs/config.yaml 的sft_datasets中保留soda_dialogue该名字对应SODADialogue类训练脚本会自动完成对话切分与 QA 对抽取。七、注意事项与使用边界生成脚本中的缺陷需留意在第四个随机分支中代码无条件执行title2 title.split(.)[1]若title不含.会触发IndexError这是脚本本身的容错盲区同时第 87 行dat dataset[train][i]在所有 split 的循环中都固定取 train split 的数据意味着 test/validation 切分实际上来源于 train 子集内的抽样顺序差异而非源数据集的原始切分语义数据为机器合成卡片明确标注annotations_creators: no-annotation、language_creators: machine-generated语料由模板拼接而成可能存在重复句式、格式噪声训练端SODADialogue类专门统计的 fault 即为佐证使用时建议配合数据清洗与去重许可与合规数据集采用 MIT 许可符合 data/datasets/README.md 中数据集必须具有宽松许可、不得包含儿童性虐待内容与个人隐私信息的贡献要求适用任务该数据集的 schema 为dialogue_modeling适合用于对话生成 / 指令跟随类模型的 SFT 训练而非评测集或人工偏好数据。八、小结SODA Synthetic Dialogue 展示了 Open-Assistant 在数据工程上的一个典型范式以开源故事语料为原料用一套可复现的模板合成管线低成本制造出海量、多样、可直接用于对话模型训练的指令数据。通过本仓库的生成脚本、加载脚本与训练端接入代码你既可以一键复现该数据集也能参考其模板设计思路为自己的对话模型构造同类合成语料。【免费下载链接】Open-AssistantOpenAssistant is a chat-based assistant that understands tasks, can interact with third-party systems, and retrieve information dynamically to do so.项目地址: https://gitcode.com/gh_mirrors/op/Open-Assistant创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考