Communityライティング&編集github.com

データセットキュレーション

教師ありファインチューニングや選好学習のために、生データをトレーニング形式に変換、フォーマット、検証します。チャットテンプレートの適用、シーケンスパッキングの設定、合成トレーニングデータの生成、実行前のデータセットカード作成などに使用します。

データセットキュレーション とは?

このスキルは、教師ありファインチューニング(SFT)や選好学習(DPO/ORPO/KTO/GRPOなど)向けに生データを整形・検証するプロセス全体をカバーします。第一段階として、ファインチューニング手法に応じたフォーマット(Instruct形式、ChatML形式、選好ペア形式など)を選択するための表を提供します。次に、チャットテンプレートの適用や損失マスキングの正しい手順を解説し、トレーニングの失敗を防ぎます。また、パッキングによる計算効率の向上方法と、その際の注意点(手動検査の必須性)を詳述しています。さらに、合成データに関する具体的なルール(最低25%の実データの維持、マグパイ法やリジェクションサンプリングの推奨など)を提示し、品質崩壊を防ぎます。最後に、トレーニング開始前に必要なデータセットカードの6つの必須フィールド(出典、行数、合成/実データ比率、重複除去方法、使用テンプレート、パッキング設定)を定義し、これをゲートとして機能させることで、データ品質を保証します。このスキルは、ファインチューニング手法選択スキルからの出力を受け取り、LoRA/QLoRAや選好学習などの後続スキルが消費するデータセットを生成します。

対応~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に質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

データセットキュレーション は何をしますか?

このスキルは、finetuning-method-selection が既にここにルーティングされていることを前提とします — 次のステップはデータの準備であり、手法の選択ではありません。以下では、ターゲット手法によるフォーマット選択、最も一般的なサイレントトレーニング障害の背後にあるテンプレート/パッキングの仕組み、崩壊を起こさずに合成データを混ぜるためのルール、そして実行開始前にフェーズ2を締めくくるデータセットカードについて説明します。

入力: 生のサンプル(デモ、選好判断、またはタスクプロンプト)と、finetuning-method-selection からのルーティング決定。 出力形式: フォーマットされ、パックされ、検証されたJSONLデータセットと、完成したデータセットカード — /finetune がトレーニング開始前にチェックするフェーズ2のアーティファクト。

フォーマット選択

手法形状行数
SFT、シングルターンInstruct(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形状の参考例です。他の4つのフォーマットと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%をパディングに費やします — 可変長サンプルを固定シーケンス長でバッチ処理すると、各サンプルの長さとバッチの最大値との間のギャップが無駄になります。パッキングは複数のサンプルを最大長まで連結して1つのシーケンスにし、その無駄のほとんどを削減します。

  • パッキングはバッチセマンティクスを変更します。 パックされたシーケンスには複数の元のサンプルが含まれる可能性があるため、「エポックあたりのステップ数」やサンプル数に依存するLRスケジュールは、パッキングがオンになると変化します — スケジュールのマイルストーンをパックされたシーケンス数に基づいて再計算してください。

  • 必須: 本格的な実行にスケールする前に、5~10個のパックされたシーケンスをデコードして手動で検査してください。 サンプル境界が期待通りに配置されていること、テンプレートマーカーが各サブサンプル内で無傷であること、損失マスクが各パックシーケンス内でもアシスタントのみであることを確認します。これはオプションではありません — パッキングのバグはサイレントであり(損失曲線は正常に見えます)、数時間後の評価品質でのみ表面化します:

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

合成データのルール

  • 崩壊防止のために最低25%の実データを維持します。 実データの下限なしにモデル生成データの割合を増やしてトレーニングすると、世代を重ねるごとに測定可能な品質崩壊が発生します — 25%の実データはそのラインを維持する最低限です。汎用ドメインのリプレイ行はこの下限にカウントされます — 「実データ」とは「このタスクのためにこの生徒モデルから生成されたものではない」という意味であり、「人間が作成した」という意味ではありません。完全に合成で構築されたデータセットでも、リプレイだけで25%以上の下限を満たすことができます(references/synthetic-data.md のリプレイミックス構築レシピを参照)。どの行を「実データ」とみなすかをデータセットカードに明記し、下限を構造的に達成不可能なままにしないでください。
  • マグパイ法とリジェクションサンプリングが主力です。 マグパイ法はモデル自身のテンプレート事前分布からプロンプトを抽出します。リジェクションサンプリングはプロンプトごとに複数の候補を生成し、フィルターを通過したものだけを保持します。どちらも単純な単発生成よりも優れています。
  • ターゲットを絞った生徒認識型生成は、静的生成よりも1.3~2倍のサンプル効率を実現します — 生徒の実際の障害モードを狙うことで、より少ないフィルタリング済みサンプルで品質基準に達します。
  • フィルタリング後の典型的な受理率は10~30%です。 それに応じてボリュームを計画してください — 15%の受理率で10,000行を目標とする場合、約65,000以上の生生成が必要です。
  • 生成手法のランキング、フィルターファネル、リプレイミックス構築、蒸留パターン: references/synthetic-data.md。

データセットカード

トレーニングに到達するすべてのデータセットにはカードが必要です — /finetune が起動前にチェックする必須のフェーズ2アーティファクトです。カードは自由形式のドキュメントではなく、以下のフィールドを必ず含める必要があります:

  • 出典 — 各行の出所(実データソース、合成手法、またはその両方)。trace-to-training-data の出力にトレース可能であること。
  • 行数 — 総行数、および分割されている場合は分割(train/eval/held-out)ごとの行数。
  • 合成/実データ比率 — 測定された比率。上記の25%以上の実データ下限と照合すること。
  • 重複除去方法 — 完全一致、意味的(埋め込みしきい値)、またはその両方。references/synthetic-data.md のフィルターファネルを参照。
  • 使用テンプレート — 正確なチャットテンプレート文字列/識別子。推論と評価を通じて一貫性を保つ — これにより eval-harness-first 実行をチェックポイントに結び付けます。
  • パッキング設定 — パッキングを使用したかどうか、最大シーケンス長、および上記の5~10シーケンスの手動検査が行われたことの確認。

これらの6つのフィールドのいずれかが欠けているデータセットは /finetune の準備ができていません — カードはゲートであり、事後的に書かれた要約ではありません。

フェーズ2 出口チェックリスト

/finetune に引き継ぐ前に、以下を確認してください:

  1. フォーマットが手法と一致していること(上の表)。
  2. テンプレートが連結前に適用されていること。
  3. 損失がアシスタントターンのみにマスクされていること。
  4. 5~10個のパックされたシーケンスをデコードして読んだこと。
  5. 最終ミックスに最低25%の実データが含まれていること。
  6. データセットカードが完全であること — 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.

関連スキル