ShareGPT Format Format Guide
用於聊天模型訓練的多輪對話格式
ConversationSpecification
ShareGPT 格式是一種 JSON/JSONL 對話資料集結構,用於擷取使用者和 AI 助手之間的多輪對話。以允許使用者分享 ChatGPT 對話的 ShareGPT 網站命名,該格式將每段對話表示為包含訊息列表的物件,其中每條訊息有一個「from」欄位(指示說話者)和一個「value」欄位(包含訊息內容)。這種基於輪次的結構自然地擷取了真實對話的流程,使其非常適合訓練需要處理多輪上下文的聊天模型。
標準 ShareGPT 格式使用「human」和「gpt」作為使用者和助手訊息的說話者識別符,可選的「system」角色用於系統提示。某些變體使用「user」和「assistant」代替。每段對話是一個自包含的對話,以人類訊息開始,通常在人類和助手輪次之間交替。該格式支援任意長度的對話,從簡單的單輪問答到具有數十次交流的擴展多輪對話。
ShareGPT 格式已被開源 LLM 社群廣泛採用,特別是透過 ShareGPT-Vicuna、OpenAssistant Conversations 和 WizardLM 訓練資料等資料集。Axolotl、LLaMA-Factory、FastChat 和 Hugging Face TRL 程式庫等訓練框架都支援 ShareGPT 作為一級輸入格式。該格式的流行源於它與使用者與聊天模型互動方式的自然對齊——它不僅擷取個別回應,還擷取聊天模型需要學習的對話動態。
When to Use ShareGPT Format
當您的訓練資料由多輪對話組成且您想訓練能跨多次交流處理上下文的聊天模型時,請使用 ShareGPT 格式。對於來自真實對話互動、客戶支援記錄、輔導課程或助手回應取決於前述對話歷史的任何對話的訓練資料,它是自然的選擇。如果您的模型需要在生成回應時引用對話的較早部分,ShareGPT 格式明確擷取了這種上下文。
當您的訓練範例涉及多輪對話時,選擇 ShareGPT 而非 Alpaca 格式。單一 ShareGPT 範例可以包含整個對話執行緒,而 Alpaca 僅限於單一指令-回應配對。ShareGPT 還支援對話結構中的系統提示,使您能夠訓練在訓練資料中嵌入不同角色或行為準則的模型。
當您的訓練資料純粹是單輪指令遵循時(為簡潔性使用 Alpaca 格式)、當您需要標準化的聊天範本格式時(使用具有更嚴格結構的 ChatML),或當您的訓練框架特別要求不同的對話格式時,ShareGPT 格式不太適合。請注意,在大多數訓練框架中,ShareGPT 和其他對話格式之間的轉換很簡單。
Schema / Structure
// ShareGPT format schema
interface ShareGPTMessage {
from: "system" | "human" | "gpt"; // Speaker role
value: string; // Message content
}
interface ShareGPTConversation {
conversations: ShareGPTMessage[]; // Ordered list of turns
id?: string; // Optional conversation ID
source?: string; // Optional data source
}
// Alternative variant used by some frameworks
interface ShareGPTVariant {
messages: {
role: "system" | "user" | "assistant";
content: string;
}[];
}Example Data
[
{
"id": "conv_001",
"conversations": [
{"from": "system", "value": "You are a helpful Python programming tutor. Explain concepts clearly with examples."},
{"from": "human", "value": "What's the difference between a list and a tuple in Python?"},
{"from": "gpt", "value": "Lists and tuples are both sequence types in Python, but they have key differences:\n\n**Lists** are mutable — you can add, remove, or change elements after creation:\n```python\nfruits = ['apple', 'banana']\nfruits.append('cherry') # Works fine\nfruits[0] = 'avocado' # Also works\n```\n\n**Tuples** are immutable — once created, they cannot be modified:\n```python\ncoords = (10, 20)\ncoords[0] = 15 # TypeError!\n```\n\nUse lists when your data needs to change, and tuples when it should stay constant."},
{"from": "human", "value": "When would I actually use a tuple over a list?"},
{"from": "gpt", "value": "Great question! Here are the main scenarios for tuples:\n\n1. **Dictionary keys**: Tuples can be dictionary keys, lists cannot\n```python\nlocations = {(40.7, -74.0): 'NYC', (51.5, -0.1): 'London'}\n```\n\n2. **Function return values**: Returning multiple values\n```python\ndef get_dimensions():\n return (1920, 1080) # width, height\n```\n\n3. **Data integrity**: When you want to guarantee data won't be accidentally modified\n\n4. **Performance**: Tuples are slightly faster and use less memory than lists\n\nA good rule of thumb: if the data represents a fixed collection of related items (like x,y coordinates), use a tuple. If it's a collection that may grow or change, use a list."}
]
}
]Ertas Support
Ertas Data Suite 完全支援 ShareGPT 格式的對話訓練資料準備。您可以匯入 ShareGPT JSON/JSONL 資料集、在所有對話輪次中套用 PII 編輯同時維護對話連貫性、驗證對話結構(確保正確的輪次交替和必需欄位),並匯出已處理的資料集供微調。平台在所有轉換期間保留對話執行緒,確保多輪上下文關係保持完整。
Ertas Studio 接受 ShareGPT 格式的資料集進行聊天模型微調,在分詞期間自動為您的目標模型架構套用適當的聊天範本。
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.