Alpaca Format Format Guide

    用於 LLM 微調的指令遵循資料集格式

    Conversation

    Specification

    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

    typescript
    // 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
    }
    Alpaca 格式 TypeScript 架構,包含標準和擴展變體

    Example Data

    json
    [
      {
        "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)"
      }
    ]
    涵蓋分類、生成、提取和推理任務的 Alpaca 格式範例

    Ertas Support

    Ertas Data Suite 原生支援 Alpaca 格式的訓練資料準備。您可以匯入 Alpaca 格式的 JSON 或 JSONL 資料集,在 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.