ShareGPT 格式 Format Guide

    用于聊天模型训练的多轮对话格式

    Conversation

    Specification

    ShareGPT 格式是一种 JSON/JSONL 对话数据集结构,用于捕获用户与 AI 助手之间的多轮对话。该格式以 ShareGPT 网站命名——该网站使用户能够分享 ChatGPT 对话。格式将每段对话表示为一个包含消息列表的对象,其中每条消息有一个 "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 格式

    当你的训练数据包含多轮对话且你想训练一个能跨多次交互处理上下文的聊天模型时,应使用 ShareGPT 格式。对于来源于真实对话交互、客服记录、辅导会话或任何助手回复依赖于先前对话历史的对话训练数据,它是天然的选择。如果你的模型需要在生成回复时引用对话的早期部分,ShareGPT 格式会显式地捕获这种上下文。

    当训练样本包含多轮对话时,应选择 ShareGPT 而非 Alpaca 格式。单个 ShareGPT 样本可以包含整个对话线程,而 Alpaca 仅限于单个指令-回复对。ShareGPT 还支持在对话结构中嵌入系统提示词,使你能够用嵌入在训练数据中的不同角色设定或行为准则来训练模型。

    当训练数据纯粹是单轮指令跟随(使用 Alpaca 格式更简单)、需要标准化的聊天模板格式(使用结构更严格的 ChatML)或训练框架明确要求不同的对话格式时,ShareGPT 格式不太适用。值得注意的是,大多数训练框架都能轻松在 ShareGPT 和其他对话格式之间进行转换。

    Schema / Structure

    typescript
    // 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;
      }[];
    }
    ShareGPT 格式的 TypeScript 模式定义,包含标准和替代角色名称

    Example Data

    json
    [
      {
        "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."}
        ]
      }
    ]
    ShareGPT 格式示例:包含系统提示词的多轮 Python 教学对话

    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.