跳转到主要内容

数据集指南

您的数据集是训练成功的最重要因素。小而高质量的数据集总是胜过庞大而嘈杂的数据集。

数据集大小问题

这很关键:小模型 + 大数据集 = 过拟合
模型大小推荐数据集大小最大数据集大小
270M - 500M1,000 - 5,00010,000
1B - 3B5,000 - 20,00050,000
7B - 13B20,000 - 100,000500,000
30B+100,000+无实际限制

为什么会这样?

这样想:
  • 小模型 = 小大脑 = 只能记忆这么多
  • 大数据集 = 大量信息
  • 结果 = 模型只是记忆示例而不是学习模式
示例:在完整 Alpaca 数据集(52k 示例)上训练 gemma-3-270m
  • 模型记忆:“当被问及法国首都时,说巴黎”
  • 但不学习:“如何一般性地回答地理问题”

如何修复

在向导中使用 --max-samples
Maximum samples (optional, for testing/debugging): 5000
或在 CLI 中:
aitraining llm --train \
  --model google/gemma-3-270m \
  --data-path tatsu-lab/alpaca \
  --max-samples 5000 \
  ...

数据集格式

向导自动检测您的数据集格式。

Alpaca 格式(最常见)

{
  "instruction": "Write a poem about the ocean",
  "input": "",
  "output": "The waves crash upon the shore..."
}
instructioninput(可选)、output 适合:遵循指令、Q&A、完成任务

ShareGPT / 对话格式

{
  "conversations": [
    { "from": "human", "value": "Hello! How are you?" },
    { "from": "gpt", "value": "I'm doing well, thank you!" },
    { "from": "human", "value": "Can you help me with Python?" },
    { "from": "gpt", "value": "Of course! What do you need help with?" }
  ]
}
适合:聊天机器人、多轮对话

Messages 格式(OpenAI 风格)

{
  "messages": [
    { "role": "system", "content": "You are a helpful assistant." },
    { "role": "user", "content": "What is 2+2?" },
    { "role": "assistant", "content": "2+2 equals 4." }
  ]
}
适合:API 风格训练、系统提示

Q&A 格式

{
  "question": "What is the capital of France?",
  "answer": "The capital of France is Paris."
}
question/query/prompt + answer/response 适合:简单问答

DPO 格式(偏好训练)

{
  "prompt": "Explain quantum physics",
  "chosen": "Quantum physics is a branch of science that studies...",
  "rejected": "idk its like small particles or something lol"
}
必需用于:DPO、ORPO 训练器

纯文本

{
  "text": "This is a document about machine learning. It covers various topics..."
}
适合:持续预训练、领域适应

自动格式检测

向导分析您的数据集并建议转换:
🔄 Dataset Format Analysis:
✓ Detected dataset format: alpaca
  • Your dataset is in alpaca format
  • This can be converted to the standard messages format for better compatibility

Do you want to analyze and convert your dataset to the model's chat format? (y/N): y

转换的作用

  1. 规范化您的数据为标准格式
  2. 应用正确的聊天模板给您的模型
  3. 处理特殊标记
示例:Alpaca → Gemma 的 Messages 之前:
{ "instruction": "Translate to French", "input": "Hello", "output": "Bonjour" }
之后:
<start_of_turn>user
Translate to French

Hello<end_of_turn>
<start_of_turn>model
Bonjour<end_of_turn>

使用本地数据

CSV 文件

创建包含示例的 CSV:
instruction,input,output
"Write a poem about cats","","Soft paws, gentle eyes..."
"Translate to Spanish","Hello","Hola"
"Summarize this","Long article text here","Brief summary"
然后在向导中:
Dataset (number, HF ID, or command): ./my_data/training.csv

JSON/JSONL 文件

创建 .jsonl 文件(每行一个 JSON 对象):
{"instruction": "Write a poem", "output": "..."}
{"instruction": "Translate", "input": "Hello", "output": "Hola"}

文件夹结构

将所有文件放在文件夹中:
my_data/
  train.jsonl
  validation.jsonl  (optional)
然后:
Dataset (number, HF ID, or command): ./my_data

数据集质量技巧

500 个高质量示例胜过 50,000 个平庸示例。每个示例应该:
  • 准确且正确
  • 格式良好
  • 代表您希望模型执行的操作
包含各种示例: - 不同主题 - 不同长度 - 不同风格 - 边缘情况
如果您想要客户支持机器人,在客户支持对话上训练。 如果您想要代码助手,在代码示例上训练。 不要在通用数据上训练并期望特定技能。
删除: - 重复项 - 损坏的示例 - 不一致的格式 - 低质量响应
如果您有类别,尝试每个类别有相似数量。 1000 个类别 A 示例 + 50 个类别 B 示例 = 模型忽略 B。

热门数据集

用于学习/测试

数据集大小格式最适合
tatsu-lab/alpaca52kAlpaca通用指令遵循
databricks/databricks-dolly-15k15kAlpaca商业/专业任务
OpenAssistant/oasst110k+Conversation有用的助手行为

用于特定任务

数据集大小格式最适合
sahil2801/CodeAlpaca-20k20kAlpaca代码生成
WizardLM/WizardLM_evol_instruct_70k70kAlpaca复杂推理
timdettmers/openassistant-guanaco9kConversation有用的聊天

用于偏好训练(DPO/ORPO)

数据集大小格式最适合
Anthropic/hh-rlhf170kDPO有用且无害
argilla/ultrafeedback-binarized-preferences60kDPO通用偏好

训练/验证分割

它们是什么

  • Train split:模型学习的数据
  • Validation split:检查模型是否在学习(而非记忆)的数据

何时使用验证

如果以下情况,使用验证分割:
  • 您有 1,000+ 示例
  • 您想检测过拟合
  • 您正在试验超参数
如果以下情况,跳过验证:
  • 您有 < 500 示例(每个示例都很重要)
  • 您正在进行快速测试运行
  • 您将在训练后单独评估

在向导中设置分割

✓ Dataset loaded. Splits found: train, test, validation
✓ Using split: train (auto-selected from: train, test, validation)

Validation split name (optional) [validation]:

限制数据集大小

用于测试或防止过拟合:
Maximum samples (optional, for testing/debugging): 1000
这在以下情况下特别有用:
  1. 首次训练运行:使用 100-500 个样本验证一切正常
  2. 小模型:对于 270M-1B 模型限制为 1,000-5,000
  3. 快速迭代:使用较小数据测试不同设置

列映射

如果您的数据集有非标准列名,向导会询问:
📝 Column Mapping:

For instruction tuning (SFT):
• Should contain complete conversations or instruction-response pairs

Text column name [text]: my_instruction_column
✓ text_column: my_instruction_column

DPO/ORPO 必需列

DPO/ORPO requires three columns:
  • Prompt column: the instruction/question
  • Chosen column: the preferred response
  • Rejected column: the non-preferred response

Prompt column name [REQUIRED] [prompt]: question
Chosen response column [REQUIRED] [chosen]: good_response
Rejected response column [REQUIRED] [rejected]: bad_response

下一步