Alpaca 格式 Format Guide
用于 LLM 微调的指令跟随数据集格式
ConversationSpecification
Alpaca 格式是一种 JSON/JSONL 数据集结构,专为大语言模型的指令跟随微调而设计。该格式由斯坦福大学的 Alpaca 项目于 2023 年 3 月推出,定义了一个简洁的三字段模式:instruction(任务描述或问题)、input(可选的附加上下文)和 output(期望的模型回复)。Alpaca 格式已成为监督微调(SFT)数据集中最广泛采用的结构之一,主流训练框架如 Axolotl、LLaMA-Factory、FastChat 和 Hugging Face TRL 库均提供原生支持。
Alpaca 格式数据集中的每个样本代表一对指令-回复。instruction 字段包含模型应执行的任务——可以是一个问题、一条命令或对期望输出的描述。input 字段在仅凭指令不足以完成任务时提供额外上下文;例如,如果指令是"总结以下文本",input 字段将包含待总结的文本。当不需要额外上下文时,input 字段留空为空字符串。output 字段包含模型应学习生成的理 想回复。
Alpaca 格式的简洁性是其核心优势。与多轮对话格式(ShareGPT、ChatML)不同,Alpaca 专注于单轮指令跟随,使得数据的创建、验证和处理都非常直观。在训练过程中,instruction 和 input 会被组合成提示词(通常使用类似 "Below is an instruction..." 的模板),模型根据该提示词学习生成 output。该格式对具体使用的提示模板没有限制——不同的训练框架会在数据预处理阶段应用各自的模板。
When to Use Alpaca 格式
当你为 LLM 微调创建单轮指令跟随数据集时,应使用 Alpaca 格式。它是任务专用微调的理想格式,适用于每个样本展示一个完整任务的场景——回答问题、生成文本、翻译、分类、信息提取或执行特定指令。如果你的训练数据由独立的指令-回复对组成,不涉及对话上下文,Alpaca 格式是最简单且支持最广泛的选择。
当你的训练样本为单轮交互(一条指令、一个回复)且不需要多轮对话上下文时,应优先选择 Alpaca 格式而非 ShareGPT 或 ChatML。该格式的简洁性使数据创建更高效、质量审查更便捷、解析更可靠。大多数主流训练框架都原生支持 Alpaca 格式,且在需要时可轻松转换为其他格式(ChatML、ShareGPT)。
Alpaca 格式不太适合训练需要跨多轮维持上下文的对话模型——此类场景请使用 ShareGPT 或 ChatML。它也不支持系统提示词(用于设定模型角色或行为的指令)、工具/函数调用示例或多模态输入。如果你的训练数据需要上述任何特性,请考虑使用更具表达力的格式。
Schema / Structure
// Alpaca format schema
interface AlpacaExample {
instruction: string; // The task description or question
input: string; // Additional context (empty string if none)
output: string; // The expected model response
}
// Extended Alpaca format (used by some frameworks)
interface AlpacaExtended {
instruction: string;
input: string;
output: string;
system?: string; // Optional system prompt
history?: [string, string][]; // Optional conversation history
}Example Data
[
{
"instruction": "Classify the sentiment of the following product review.",
"input": "The noise cancellation on these headphones is incredible. Best purchase I've made this year.",
"output": "Positive. The review expresses strong satisfaction with the product's noise cancellation feature and overall value."
},
{
"instruction": "Write a professional email declining a meeting invitation.",
"input": "",
"output": "Subject: Re: Meeting Request\n\nHi [Name],\n\nThank you for the meeting invitation. Unfortunately, I have a scheduling conflict at that time and won't be able to attend.\n\nWould it be possible to reschedule to later in the week? I'm available Thursday or Friday afternoon.\n\nBest regards,\n[Your Name]"
},
{
"instruction": "Extract all company names mentioned in the text.",
"input": "The partnership between Microsoft and OpenAI has reshaped the industry, while Google DeepMind continues to push boundaries in AI research. Meanwhile, Anthropic has focused on AI safety.",
"output": "1. Microsoft\n2. OpenAI\n3. Google DeepMind\n4. Anthropic"
},
{
"instruction": "Convert the following temperature from Fahrenheit to Celsius. Show your work.",
"input": "98.6°F",
"output": "To convert Fahrenheit to Celsius:\nC = (F - 32) × 5/9\nC = (98.6 - 32) × 5/9\nC = 66.6 × 5/9\nC = 37°C\n\n98.6°F = 37°C (normal human body temperature)"
}
]Ertas Support
Ertas Data Suite 原生支持 Alpaca 格式,可用于训练数据准备。你可以导入 JSON 或 JSONL 格式的 Alpaca 数据集,对 instruction、input 和 output 字段进行 PII 脱敏处理,验证字段的完整性和质量,并导出处理后的数据集以供微调使用。平台还支持在 Alpaca 格式与其他指令格式(ShareGPT、ChatML)之间进行转换,以匹配训练框架的要求。
Ertas Studio 可直接接收 Alpaca 格式数据集用于云端微调,并根据目标模型架构自动处理提示模板应用和分词操作。
Related Resources
Ship AI that runs on your users' devices.
Early bird pricing starts at $14.50/mo — locked in for life. Plans for builders and agencies.