
# 训练数据说明
#### 支持数据简介
MindSpeed-LLM、Llama-Factory框架常用数据集格式：
- alpaca格式
- sharegpt格式
- moss格式（仅支持MindSpeed-LLM）
本教程样例数据集下载链接如下：
- 预训练(MindSpeed-LLM)：[train-00000-of-00001-a09b74b3ef9c3b56.parquet](https://huggingface.co/datasets/tatsu-lab/alpaca/resolve/main/data/train-00000-of-00001-a09b74b3ef9c3b56.parquet)，数据大小：24M左右。
- 微调：[alpaca_gpt4_data.json](https://huggingface.co/datasets/QingyiSi/Alpaca-CoT/blob/main/alpacaGPT4/alpaca_gpt4_data.json)，数据大小：43.6 MB。
- 强化学习(MindSpeed-RL):[deepscaler.json](https://huggingface.co/datasets/agentica-org/DeepScaleR-Preview-Dataset/blob/main/deepscaler.json)，数据大小：21.5 MB。
- 强化学习(VeRL)，数据集分为train和test两种，示例截图如下：
  ![](https://support.huaweicloud.com/bestpractice-modelarts/figure/zh-cn_image_0000002503500379.png)
  - 大语言模型：<https://huggingface.co/datasets/openai/gsm8k/tree/main>
  
  - 多模态模型：[https://huggingface.co/datasets/hiyouga/geometry3k/tree/main](https://huggingface.co/datasets/hiyouga/geometry3k/tree/main/data)
    
 
#### 自定义数据
1. LLamaFactory：代码包自带数据集，自定义可参考[README_zh.md](https://github.com/hiyouga/LLaMA-Factory/blob/main/data/README_zh.md)。
2. MindSpeed-LLM：数据格式如下：
   - **预训练数据(MindSpeed-LLM)** ：用户也可以自行准备预训练数据。数据要求如下：
     使用标准的.json格式的数据，通过设置--json-key来指定需要参与训练的列。可以使用--json-key标志更改数据集文本字段的名称，默认为text。在维基百科数据集中，它有四列，分别是id、url、title和text。可以指定--json-key标志来选择用于训练的列。详情可参考[预训练数据集处理](https://gitee.com/ascend/MindSpeed-LLM/blob/master/docs/pytorch/solutions/pretrain/pretrain_dataset.md)。
     ```
     {
         'id': '1',
         'url': 'https://simple.wikipedia.org/wiki/April',
         'title': 'April',
         'text': 'April is the fourth month...'
     }
     ```
     
   
   - **MOSS指令微调数** **据** ：本案例中还支持MOSS格式数据，标准的.json格式的数据，内容包括可以多轮对话、指令问答。例如以下样例：
     ```
     {
       "conversation_id": 1,
       "meta_instruction": "",
       "num_turns": 3,
       "chat": {
         "turn_1": {
           "Human": "<|Human|>: 如何保障工作中遵循正确的安全准则？<eoh>\n",
           "Inner Thoughts": "<|Inner Thoughts|>: None<eot>\n",
           "Commands": "<|Commands|>: None<eoc>\n",
           "Tool Responses": "<|Results|>: None<eor>\n",
           "MOSS": "<|MOSS|>: 为了保障xxx些建议：\n\n1.了解相关安xxx最佳实践。\n\n这些xxx环境。<eom>\n"
         },
         "turn_2": { ... },
         "turn_3": { ... },
       "category": "Brainstorming"
     }
     ```
     
   
   - **Alpaca** **指令微调数据** ：详情可参考[Alpaca风格数据集](https://gitee.com/ascend/MindSpeed-LLM/blob/master/docs/pytorch/solutions/finetune/datasets/alpaca_dataset.md)，数据集包含有以下字段：
     - instruction：描述模型应执行的任务。指令中的每一条都是唯一的。
     
     - input：任务的可选上下文或输入。instruction 对应的内容会与 input 对应的内容拼接后作为指令，即指令为 instruction\\input。
     
     - output：生成的指令的答案。
     
     - system：系统提示词，用来为整个对话设定场景或提供指导原则。
     
     - history： 一个列表，包含之前轮次的对话记录，每一对都是用户消息和模型回复。这有助于保持对话的一致性和连贯性。
     
     
     ```
     [
         {
             "instruction": "人类指令（必填）",
             "input": "人类输入（选填）",
             "output": "模型回答（必填）",
             "system": "系统提示词（选填）",
             "history": [
                 ["第一轮指令（选填）", "第一轮回答（选填）"],
                 ["第二轮指令（选填）", "第二轮回答（选填）"]
             ]
         }
     ]
     ```
     
   
   - **ShareGPT指令微调数据** ：ShareGPT 格式来源于通过记录 ChatGPT 与用户对话的数据集，主要用于对话系统的训练。它更侧重于多轮对话数据的收集和组织，模拟用户与 AI 之间的交互。详情可参考[ShareGPT 数据集](https://gitee.com/ascend/MindSpeed-LLM/blob/master/docs/pytorch/solutions/finetune/datasets/sharegpt_dataset.md)，数据集包含有以下字段：
     - conversations：包含一系列对话对象，每个对象都由发言者(from)和发言内容(value)组成。
     
     - from：表示对话的角色，可以是"human"（人类）或"gpt"（机器），表示是谁说的这句话。
     
     - value：具体的对话内容。
     
     - system：系统提示词，用来为整个对话设定场景或提供指导原则。
     
     - tools：描述可用的外部工具或功能的信息，这些工具可能被模型用来执行某些任务或获取更多信息。
     
     
     ```
     [
         {
             "conversations": [
                 {
                     "from": "human",
                     "value": "人类指令"
                 },
                 {
                     "from": "function_call",
                     "value": "工具参数"
                 },
                 {
                     "from": "observation",
                     "value": "工具结果"
                 },
                 {
                     "from": "gpt",
                     "value": "模型回答"
                 }
                 ],
             "system": "系统提示词（选填）",
             "tools": "工具描述（选填）"
         }
     ]
     ```
     
    

3. MindSpeed-MM：数据格式如下：
   - Qwen2.5VL-3b/7b**：** 参考三方官方[数据集准备及处理](https://gitee.com/ascend/MindSpeed-MM/tree/master/examples/qwen2.5vl#数据集准备及处理)，下载COCO2017数据集，并使用脚本转换，或将自定义数据集预处理为以下格式：
   
   
   ```
   {
     "id": 1,
     "image": "图片路径",
     "conversations": [
         {"from": "human", "value": "人类指令"},
         {"from": "gpt", "value": "模型回答"},
     ],
   }
   ```
   - InternVL3-8b：参考三方官方[数据集准备及处理](https://gitcode.com/Ascend/MindSpeed-MM/tree/2.2.0/examples/internvl3#数据集准备及处理)，下载[InternVL-Finetune](https://huggingface.co/datasets/OpenGVLab/InternVL-Chat-V1-2-SFT-Data)数据集。
    
 
