Community写作与编辑github.com

数据集整理/数据集策展

为监督微调和偏好训练准备、格式化并验证数据集。当需要将原始数据转换为训练格式、应用聊天模板、配置序列打包、生成合成训练数据或在训练运行前编写数据集卡片时使用。

数据集策展 是什么?

数据集整理技能专注于为大型语言模型的监督微调(SFT)和偏好优化准备高质量数据集。它详细指导如何根据不同的训练方法(如SFT、DPO、KTO、GRPO等)选择合适的输入格式,以及如何正确应用聊天模板和损失掩码,以避免常见的沉默训练失败模式,比如模板不匹配或打包错误。该技能还包含了合成数据生成和混合的关键规则,强调至少25%的真实数据作为防崩溃底线,以及基于模型学生弱点进行定向生成的效率优势。此外,它强制要求生成一个包含来源、数量、合成/真实比例、去重方法、模板和打包配置六大字段的数据集卡片,作为进入微调阶段的门控条件。该技能适用于Claude Code、Cursor、Codex等AI代理平台,通过提供格式化后的JSONL数据集和完整的数据集卡片,确保训练流程的可靠性和可追溯性。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/wshobson/agents/tree/main/plugins/llm-finetuning/skills/dataset-curation

Installed? Explore more 写作与编辑 skills: steipete/notion, langchain-ai/langchain, bytedance/podcast-generation · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

数据集整理 / 数据集策展

此技能假定 微调方法选择 已经路由至此——下一步是准备数据,而非选择方法。以下内容涵盖:根据目标方法选择格式、模板/打包机制(最常见的静默训练失败根源)、混合合成数据而不崩溃的规则,以及训练运行启动前结束第二阶段所需的数据集卡片。

输入: 原始样本(演示、偏好判断或任务提示)以及来自 微调方法选择 的路由决策。
输出格式: 格式化、打包、验证后的 JSONL 数据集,以及一份完整的数据集卡片——/finetune 在启动训练前检查的第二阶段工件。

格式选择

方法形状行数
SFT,单轮指令格式 (instruction/response 或 prompt/completion)~1,000+ 下限
SFT,多轮对话 / ChatML messages 列表~1,000+ 下限
DPO / ORPO偏好对 (prompt, chosen, rejected)取决于方法,参见 偏好优化
KTO非配对 (prompt, completion, label)取决于方法,参见 偏好优化
GRPO / RLVR仅提示 (prompt + 验证器元数据)取决于方法,参见 grpo-rlvr-training
  • ~1,000+ 行是 SFT 推荐的下限,而非目标。低于此值,少量低质量或重复样本可能主导梯度;高于此值,质量优于数量——一个较小但经过验证、去重的集合胜过更大但有噪音的集合。

  • ChatML 形状供参考;另外四种格式以及 ShareGPT 转换说明见 references/formats-and-templates.md:

    {"messages": [
      {"role": "user", "content": "..."},
      {"role": "assistant", "content": "..."}
    ]}
    

聊天模板与损失掩码

在任何拼接或打包之前应用目标模型的聊天模板,切勿之后应用——对原始文本进行打包,然后对打包后的块应用模板会破坏对话轮次边界,导致角色标记相对于每个示例的位置出错。

  • 仅对助手回复进行训练。 在系统/用户轮次以及模板自身的角色标记上掩码损失(在标签张量中设为 -100)——只有助手轮次的内容标记才对损失有贡献。

  • 模板/分词器不匹配是常见的静默失败模式。 模型针对一个聊天模板训练,但使用不同的模板进行服务或评估,会在不出错的情况下导致性能下降。请确认训练时使用的同一个模板字符串在推理和评估时也被应用。

  • 保持数据集的 messages 形状,让训练器进行模板化和掩码(当前 TRL 中的 assistant_only_loss=True)——预先渲染为纯文本字段会破坏掩码所需的轮次边界。完整代码草稿见 references/formats-and-templates.md。训练前进行完整性检查——仅解码未掩码位置;应只看到助手文本:

    keep = batch["labels"][0] != -100
    print(tokenizer.decode(batch["input_ids"][0][keep]))
    

打包

不进行打包,40–70% 的计算量将花在填充上——将可变长度样本以固定序列长度分批处理,会浪费每个样本长度与批次最大长度之间的间隙。打包将多个样本串联成一个序列,直至达到最大长度,从而消除大部分浪费。

  • 打包会改变批次语义。 一个打包后的序列可能包含多个原始样本,因此一旦启用打包,“每epoch步数”以及任何基于样本数量的学习率调度时间点都会发生变化——请根据打包后的序列数量重新计算调度里程碑。

  • 强制要求:在扩展到完整运行前,解码并手动检查 5–10 个打包序列。 确认样本边界符合预期,每个子样本内的模板标记完好无损,并且损失掩码在每个打包序列内仍仅限于助手。此步骤不可省略——打包错误是静默的(损失曲线看起来正常),只会在数小时后的评估质量中暴露出来:

    for seq in packed_dataset.select(range(10)):
        print(tokenizer.decode(seq["input_ids"]))
    

合成数据规则

  • 保持 ≥25% 的真实数据作为防崩溃底线。 在没有真实数据下限的情况下,训练模型生成的、占比越来越高的数据会随着迭代导致可测量的质量下降——25% 的真实数据是维持稳定的最低要求。通用域回放行计入此底线——“真实”意味着“不是为此任务从此学生模型生成的”,而非“人工编写的”。完全由合成构造的数据集可以仅通过回放达到 ≥25% 的底线(参见 references/synthetic-data.md 中的回放-混合构造配方);在数据集中说明哪些行被视为“真实”,而不是让底线在结构上无法满足。
  • Magpie 和拒绝采样是主力方法。 Magpie 从模型自身的模板先验中提取提示;拒绝采样为每个提示生成多个候选,只保留过滤器通过的候选。两者都优于简单的单次生成。
  • 针对性的、感知学生弱点的生成比静态生成的样本效率高 1.3–2 倍——瞄准学生模型的实际失败模式,可以用更少的过滤样本达到质量门槛。
  • 过滤后的典型接受率为 10–30%。 请相应规划所需量——目标是 10,000 行,接受率为 15%,则需要约 65,000+ 个原始生成。
  • 生成方法排名、过滤漏斗、回放-混合构造以及蒸馏模式:references/synthetic-data.md。

数据集卡片

每个进入训练的数据集都必须附带卡片——/finetune 在启动前检查的必需第二阶段工件。此卡不是自由格式的文档;它必须包含以下字段:

  • 来源 — 每一行的来源(真实来源、合成方法,或两者),可追溯到 trace-to-training-data 的输出。
  • 数量 — 总行数,以及如果分拆,每个拆分(训练/评估/留出)的行数。
  • 合成/真实比例 — 测量到的比例,对照上述 ≥25% 的真实数据底线进行检查。
  • 去重方法 — 精确匹配、语义去重(嵌入阈值),或两者兼用;参见 references/synthetic-data.md 中的过滤漏斗。
  • 使用的模板 — 确切的聊天模板字符串/标识符,在推理和评估中保持一致——这是将 eval-harness-first 运行与检查点关联起来的关键。
  • 打包配置 — 是否使用了打包、最大序列长度,以及是否完成了上述 5–10 个序列的手动检查确认。

缺少上述六个字段中任何一个的数据集,都不应提交给 /finetune ——该卡片是一个门控条件,而非事后编写的总结。

第二阶段退出检查清单

在移交给 /finetune 之前,请确认:

  1. 格式与方法匹配(见上表)。
  2. 模板在拼接前应用。
  3. 损失掩码仅限于助手轮次。
  4. 解码并阅读了 5–10 个打包序列。
  5. 最终混合中 ≥25% 为真实数据。
  6. 数据集卡片完整——所有六个字段。

参考资料

  • references/formats-and-templates.md — 每种格式的 JSONL 示例、当前 TRL 的掩码代码以及 ShareGPT 转换说明。
  • references/synthetic-data.md — 生成方法排名、过滤漏斗、回放-混合构造以及教师→学生蒸馏模式。

相关技能:微调方法选择 路由至此;lora-qlora-recipes、vision-sft 和 偏好优化 会使用此技能产生的数据集;trace-to-training-data 是分级轨迹数据集的来源;eval-harness-first 对结果检查点进行评分。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

wshobson/accessibility-compliance

Implement WCAG 2.2 compliant interfaces with mobile accessibility, inclusive design patterns, and assistive technology support. Use when auditing accessibility, implementing ARIA patterns, building for screen readers, or ensuring inclusive user experiences.

wshobson/airflow-dag-patterns

Build production Apache Airflow DAGs with best practices for operators, sensors, testing, and deployment. Use when creating data pipelines, orchestrating workflows, or scheduling batch jobs.

wshobson/angular-migration

Migrate from AngularJS to Angular using hybrid mode, incremental component rewriting, and dependency injection updates. Use when upgrading AngularJS applications, planning framework migrations, or modernizing legacy Angular code.

wshobson/anti-reversing-techniques

Understand anti-reversing, obfuscation, and protection techniques encountered during software analysis. Use this skill when analyzing malware evasion techniques, when implementing anti-debugging protections for CTF challenges, when reverse engineering packed binaries, or when building security research tools that need to detect virtualized environments.

wshobson/api-design-principles

Master REST and GraphQL API design principles to build intuitive, scalable, and maintainable APIs that delight developers. Use when designing new APIs, reviewing API specifications, or establishing API design standards.

wshobson/architecture-decision-records

Write and maintain Architecture Decision Records (ADRs) following best practices for technical decision documentation. Use when documenting significant technical decisions, reviewing past architectural choices, or establishing decision processes.

wshobson/architecture-patterns

Implement proven backend architecture patterns including Clean Architecture, Hexagonal Architecture, and Domain-Driven Design. Use this skill when designing clean architecture for a new microservice, when refactoring a monolith to use bounded contexts, when implementing hexagonal or onion architecture patterns, or when debugging dependency cycles between application layers.

wshobson/async-python-patterns

Master Python asyncio, concurrent programming, and async/await patterns for high-performance applications. Use when building async APIs, concurrent systems, or I/O-bound applications requiring non-blocking operations.

wshobson/attack-tree-construction

Build comprehensive attack trees to visualize threat paths. Use when mapping attack scenarios, identifying defense gaps, or communicating security risks to stakeholders.

wshobson/auth-implementation-patterns

Master authentication and authorization patterns including JWT, OAuth2, session management, and RBAC to build secure, scalable access control systems. Use when implementing auth systems, securing APIs, or debugging security issues.

wshobson/avoid-ai-writing

Audit and rewrite prose so it stops reading as machine-generated. Use this skill when asked to remove AI-isms, clean up AI writing, edit a draft for AI tells, audit a README, changelog, release note, PR description, or blog post for machine-sounding prose, or make text sound less like AI. Supports a detect-only mode, a rewrite mode, and an edit-in-place mode, with optional voice and context profiles.

wshobson/backtesting-frameworks

Build robust backtesting systems for trading strategies with proper handling of look-ahead bias, survivorship bias, and transaction costs. Use when developing trading algorithms, validating strategies, or building backtesting infrastructure.

wshobson/bash-defensive-patterns

Master defensive Bash programming techniques for production-grade scripts. Use when writing robust shell scripts, CI/CD pipelines, or system utilities requiring fault tolerance and safety.

wshobson/bats-testing-patterns

Master Bash Automated Testing System (Bats) for comprehensive shell script testing. Use when writing tests for shell scripts, CI/CD pipelines, or requiring test-driven development of shell utilities.

wshobson/bazel-build-optimization

Optimize Bazel builds for large-scale monorepos. Use when configuring Bazel, implementing remote execution, or optimizing build performance for enterprise codebases.

wshobson/before-you-build

Pre-build product and feature risk review for founders, product managers, and AI-assisted builders. Use this skill when the user is about to build a landing page, MVP, SaaS product, internal tool, agent workflow, or major feature and needs to check demand, positioning, monetization, retention, trust, distribution, and adoption risk before implementation starts.

wshobson/billing-automation

Build automated billing systems for recurring payments, invoicing, subscription lifecycle, and dunning management. Use when implementing subscription billing, automating invoicing, or managing recurring payment systems.

wshobson/binary-analysis-patterns

Master binary analysis patterns including disassembly, decompilation, control flow analysis, and code pattern recognition. Use when analyzing executables, understanding compiled code, or performing static analysis on binaries.

wshobson/block-no-verify-hook

Configure a PreToolUse hook to prevent AI agents from skipping git pre-commit hooks with --no-verify and other bypass flags. Use when setting up Claude Code projects that enforce commit quality gates.

wshobson/brand-landingpage

Brand-first landing page designer — runs a brand-identity interview (colors, typography, shape language), then generates and iterates on a polished landing page via Stitch with deployment-ready HTML. Use when the user asks to create, design, or build a landing page, homepage, or marketing page and has no established visual direction. Skip when they have a design mockup, need a dashboard or app UI, are working at component level, building a multi-page app, or restyling with known design tokens — use frontend-design instead.

相关技能