Alpaca Format Format Guide
用於 LLM 微調的指令遵循資料集格式
ConversationSpecification
Alpaca 格式是一種 JSON/JSONL 資料集結構,專為大型語言模型的指令遵循微調而設計。由 Stanford 的 Alpaca 專案於 2023 年 3 月推出,它定義了一個簡單的三欄位架構:instruction(任務描述或問題)、input(可選的額外上下文)和 output(預期的模型回應)。此格式已成為監督式微調(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 Format
當您為 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 Studio 接受五種資料列格式的 JSONL 資料集,其中 instruction/output 格式最接近 Alpaca。請將 Alpaca 的 input 欄位併入 instruction,或將欄位改名為 Studio 的 input/output 格式,再上傳檔案,Studio 會在上傳時自動偵測格式。Hugging Face 上的 Alpaca 資料集可直接以網址匯入,若有欄位不符合任何一種格式,驗證器會在訓練前標示出來。
Studio 會在訓練時套用基礎模型的對話範本並進行分詞,因此資料列只需放純文字,不必加入範本標記。您也可以在 Studio 的資料集編輯器 Data Craft 中撰寫並修訂指令範例。
Related Resources
Ship AI that runs on your users' devices.
Start free with 150 credits after card verification. Paid plans from $20/mo USD.