Community寫作與編輯github.com

wshobson/dataset-curation

準備、格式化並驗證用於監督式微調和偏好訓練的資料集。用於將原始資料轉換為訓練格式、應用對話模板、配置序列打包、生成合成訓練資料或在開始訓練前撰寫資料集卡。

dataset-curation 是什麼?

此技能專注於資料集策劃,特別是為監督式微調(SFT)和偏好優化(如 DPO、KTO)準備訓練數據。它自動處理格式選擇、對話模板應用、損失遮罩、以及序列打包以提升計算效率。此外,它還提供合成資料生成的具體規則,並要求資料集卡必須包含來源、數量、合成/真實比例、去重方法、模板和打包配置等六個欄位,作為進入訓練階段的閘門。此技能支援多種平台(Claude Code、Cursor、Codex 等),其工作流程基於 `SKILL.md` 文檔,從 `finetuning-method-selection` 路由接收決策,並產出格式化的 JSONL 資料集和完整的資料集卡,供後續訓練技能(如 `lora-qlora-recipes`)使用。

相容平台~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 的新對話。

說明文件

資料集策劃

此技能假定 finetuning-method-selection 已將任務路由至此 — 下一步是準備資料, 而非選擇方法。以下內容包括:根據目標方法選擇格式, 導致常見無聲訓練失敗的模板/打包機制, 在不導致模型崩潰的前提下混合合成資料的規則, 以及在開始訓練之前、結束第二階段的資料集卡。

輸入: 原始範例(示範、偏好判斷 或任務提示)加上來自 finetuning-method-selection 的路由決策。 輸出格式: 一個格式化、打包、驗證過的 JSONL 資料集,加上一份完整的資料集卡 — /finetune 在啟動訓練前檢查的第二階段產出。

格式選擇

方法形狀行數
SFT,單輪指令(instruction/response 或 prompt/completion)約 1,000+ 起
SFT,多輪對話 / ChatML messages 列表約 1,000+ 起
DPO / ORPO偏好配對(prompt、chosen、rejected)取決於方法,請參閱 preference-optimization
KTO未配對(prompt、completion、label)取決於方法,請參閱 preference-optimization
GRPO / RLVR僅提示(prompt + 驗證器元數據)取決於方法,請參閱 grpo-rlvr-training
  • 約 1,000+ 行是 SFT 的建議下限, 而非目標。低於此數值時,少數低品質 或重複的範例可能會主導梯度;高於此數值時, 品質重於數量 — 一個較小、經驗證、 去重複的集合勝過一個較大的雜訊集合。

  • ChatML 形狀僅供參考;其他四種格式 以及 ShareGPT 轉換註記位於 references/formats-and-templates.md:

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

對話模板與損失遮罩

在任何串接或打包之前應用目標模型的對話模板, 切勿之後才做 — 對原始文字進行打包然後 對打包後的區塊套用模板會破壞對話輪次邊界, 導致角色標記相對於每個範例的位置錯誤。

  • 僅訓練助理回應。 對系統/使用者輪次 以及模板本身的角色標記遮罩損失(在標籤張量中設為 -100)— 僅有助理輪次的內容 token 貢獻損失。

  • 模板/分詞器不匹配是主要的無聲失敗模式。 使用一個對話模板訓練,但以另一個模板提供服務或評估的模型 會在不出錯的情況下退化。請驗證訓練時使用的模板字串 與推論和評估時使用的相同。

  • 將資料集保持為 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 — 生成方法排名、過濾漏斗、回放混合構建 以及教師→學生蒸餾模式。

相關技能:finetuning-method-selection 路由至此; lora-qlora-recipes、vision-sft 和 preference-optimization 會使用此技能產出的資料集; 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.

相關技能