README_zh.md 12.5 KB
Newer Older
chenych's avatar
chenych committed
1
2
[dataset_info.json](dataset_info.json) 包含了所有可用的数据集。如果您希望使用自定义数据集,请**务必**`dataset_info.json` 文件中添加*数据集描述*,并通过修改 `dataset: 数据集名称` 配置来使用数据集。

mashun1's avatar
mashun1 committed
3
4
其中 `dataset_info.json` 文件应放置在 `dataset_dir` 目录下。您可以通过修改 `dataset_dir` 参数来使用其他目录。默认值为 `./data`

chenych's avatar
chenych committed
5
目前我们支持 **alpaca** 格式和 **sharegpt** 格式的数据集。
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
6
7
8
9
10
11

```json
"数据集名称": {
  "hf_hub_url": "Hugging Face 的数据集仓库地址(若指定,则忽略 script_url 和 file_name)",
  "ms_hub_url": "ModelScope 的数据集仓库地址(若指定,则忽略 script_url 和 file_name)",
  "script_url": "包含数据加载脚本的本地文件夹名称(若指定,则忽略 file_name)",
chenych's avatar
chenych committed
12
13
14
  "file_name": "该目录下数据集文件夹或文件的名称(若上述参数未指定,则此项必需)",
  "formatting": "数据集格式(可选,默认:alpaca,可以为 alpaca 或 sharegpt)",
  "ranking": "是否为偏好数据集(可选,默认:False)",
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
15
  "subset": "数据集子集的名称(可选,默认:None)",
chenych's avatar
chenych committed
16
  "split": "所使用的数据集切分(可选,默认:train)",
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
17
  "folder": "Hugging Face 仓库的文件夹名称(可选,默认:None)",
chenych's avatar
chenych committed
18
  "num_samples": "该数据集所使用的样本数量。(可选,默认:None)",
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
19
20
21
22
23
24
25
  "columns(可选)": {
    "prompt": "数据集代表提示词的表头名称(默认:instruction)",
    "query": "数据集代表请求的表头名称(默认:input)",
    "response": "数据集代表回答的表头名称(默认:output)",
    "history": "数据集代表历史对话的表头名称(默认:None)",
    "messages": "数据集代表消息列表的表头名称(默认:conversations)",
    "system": "数据集代表系统提示的表头名称(默认:None)",
chenych's avatar
chenych committed
26
27
    "tools": "数据集代表工具描述的表头名称(默认:None)",
    "images": "数据集代表图像输入的表头名称(默认:None)",
luopl's avatar
luopl committed
28
    "videos": "数据集代表视频输入的表头名称(默认:None)",
chenych's avatar
chenych committed
29
    "audios": "数据集代表音频输入的表头名称(默认:None)",
chenych's avatar
chenych committed
30
31
32
    "chosen": "数据集代表更优回答的表头名称(默认:None)",
    "rejected": "数据集代表更差回答的表头名称(默认:None)",
    "kto_tag": "数据集代表 KTO 标签的表头名称(默认:None)"
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
33
34
35
36
37
38
39
40
  },
  "tags(可选,用于 sharegpt 格式)": {
    "role_tag": "消息中代表发送者身份的键名(默认:from)",
    "content_tag": "消息中代表文本内容的键名(默认:value)",
    "user_tag": "消息中代表用户的 role_tag(默认:human)",
    "assistant_tag": "消息中代表助手的 role_tag(默认:gpt)",
    "observation_tag": "消息中代表工具返回结果的 role_tag(默认:observation)",
    "function_tag": "消息中代表工具调用的 role_tag(默认:function_call)",
chenych's avatar
chenych committed
41
    "system_tag": "消息中代表系统提示的 role_tag(默认:system,会覆盖 system column)"
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
42
43
44
45
  }
}
```

chenych's avatar
chenych committed
46
## Alpaca 格式
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
47

chenych's avatar
chenych committed
48
### 指令监督微调数据集
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
49

chenych's avatar
chenych committed
50
51
- [样例数据集](alpaca_zh_demo.json)

mashun1's avatar
mashun1 committed
52
53
54
在指令监督微调时,`instruction` 列对应的内容会与 `input` 列对应的内容拼接后作为提示词,即提示词为 `instruction\ninput`。而 `output` 列对应的内容为模型回答。

对于推理类模型的微调,如果数据集包含思维链,则需要把思维链放在模型回答中,例如 `<think>cot</think>output`
chenych's avatar
chenych committed
55
56
57
58

如果指定,`system` 列对应的内容将被作为系统提示词。

`history` 列是由多个字符串二元组构成的列表,分别代表历史消息中每轮对话的指令和回答。注意在指令监督微调时,历史消息中的回答内容**也会被用于模型学习**
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
59
60
61
62

```json
[
  {
mashun1's avatar
mashun1 committed
63
64
    "instruction": "用户指令(必填)",
    "input": "用户输入(选填)",
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
65
66
67
68
69
70
71
72
73
74
    "output": "模型回答(必填)",
    "system": "系统提示词(选填)",
    "history": [
      ["第一轮指令(选填)", "第一轮回答(选填)"],
      ["第二轮指令(选填)", "第二轮回答(选填)"]
    ]
  }
]
```

chenych's avatar
chenych committed
75
对于上述格式的数据,`dataset_info.json` 中的*数据集描述*应为:
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
76
77
78

```json
"数据集名称": {
chenych's avatar
chenych committed
79
  "file_name": "data.json",
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
80
81
82
83
84
85
86
87
88
89
  "columns": {
    "prompt": "instruction",
    "query": "input",
    "response": "output",
    "system": "system",
    "history": "history"
  }
}
```

mashun1's avatar
mashun1 committed
90
91
92
93
94
> [!TIP]
> 如果模型本身具备推理能力,而数据集不包含思维链,LLaMA-Factory 会自动为数据添加空思维链。当 `enable_thinking` 为 `True` 时(慢思考),空思维链会添加到模型回答中并且计算损失,否则会添加到用户指令中并且不计算损失(快思考)。请在训练和推理时保持 `enable_thinking` 参数一致。
>
> 如果您希望训练包含思维链的数据时使用慢思考,训练不包含思维链的数据时使用快思考,可以设置 `enable_thinking` 为 `None`。但该功能较为复杂,请谨慎使用。

chenych's avatar
chenych committed
95
96
### 预训练数据集

chenych's avatar
chenych committed
97
- [样例数据集](c4_demo.jsonl)
chenych's avatar
chenych committed
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120

在预训练时,只有 `text` 列中的内容会用于模型学习。

```json
[
  {"text": "document"},
  {"text": "document"}
]
```

对于上述格式的数据,`dataset_info.json` 中的*数据集描述*应为:

```json
"数据集名称": {
  "file_name": "data.json",
  "columns": {
    "prompt": "text"
  }
}
```

### 偏好数据集

luopl's avatar
luopl committed
121
偏好数据集用于奖励模型训练、DPO 训练、ORPO 训练和 SimPO 训练。
chenych's avatar
chenych committed
122
123
124
125
126
127

它需要在 `chosen` 列中提供更优的回答,并在 `rejected` 列中提供更差的回答。

```json
[
  {
mashun1's avatar
mashun1 committed
128
129
    "instruction": "用户指令(必填)",
    "input": "用户输入(选填)",
chenych's avatar
chenych committed
130
131
132
133
134
    "chosen": "优质回答(必填)",
    "rejected": "劣质回答(必填)"
  }
]
```
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
135

chenych's avatar
chenych committed
136
对于上述格式的数据,`dataset_info.json` 中的*数据集描述*应为:
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
137

chenych's avatar
chenych committed
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
```json
"数据集名称": {
  "file_name": "data.json",
  "ranking": true,
  "columns": {
    "prompt": "instruction",
    "query": "input",
    "chosen": "chosen",
    "rejected": "rejected"
  }
}
```

### KTO 数据集

luopl's avatar
luopl committed
153
KTO 数据集需要提供额外的 `kto_tag` 列。详情请参阅 [sharegpt](#sharegpt-格式)
chenych's avatar
chenych committed
154

luopl's avatar
luopl committed
155
### 多模态图像数据集
chenych's avatar
chenych committed
156

luopl's avatar
luopl committed
157
多模态图像数据集需要提供额外的 `images` 列。详情请参阅 [sharegpt](#sharegpt-格式)
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
158

luopl's avatar
luopl committed
159
### 多模态视频数据集
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
160

luopl's avatar
luopl committed
161
多模态视频数据集需要提供额外的 `videos` 列。详情请参阅 [sharegpt](#sharegpt-格式)
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
162

chenych's avatar
chenych committed
163
164
165
166
### 多模态音频数据集

多模态音频数据集需要提供额外的 `audios` 列。详情请参阅 [sharegpt](#sharegpt-格式)

chenych's avatar
chenych committed
167
168
169
170
171
## Sharegpt 格式

### 指令监督微调数据集

- [样例数据集](glaive_toolcall_zh_demo.json)
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
172

chenych's avatar
chenych committed
173
相比 alpaca 格式的数据集,sharegpt 格式支持**更多的角色种类**,例如 human、gpt、observation、function 等等。它们构成一个对象列表呈现在 `conversations` 列中。
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
174

chenych's avatar
chenych committed
175
注意其中 human 和 observation 必须出现在奇数位置,gpt 和 function 必须出现在偶数位置。
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
176
177
178
179
180
181
182

```json
[
  {
    "conversations": [
      {
        "from": "human",
mashun1's avatar
mashun1 committed
183
        "value": "用户指令"
chenych's avatar
chenych committed
184
185
186
187
188
189
190
191
      },
      {
        "from": "function_call",
        "value": "工具参数"
      },
      {
        "from": "observation",
        "value": "工具结果"
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
192
193
194
195
196
197
198
199
200
201
202
203
      },
      {
        "from": "gpt",
        "value": "模型回答"
      }
    ],
    "system": "系统提示词(选填)",
    "tools": "工具描述(选填)"
  }
]
```

chenych's avatar
chenych committed
204
对于上述格式的数据,`dataset_info.json` 中的*数据集描述*应为:
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
205
206
207

```json
"数据集名称": {
chenych's avatar
chenych committed
208
209
  "file_name": "data.json",
  "formatting": "sharegpt",
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
210
211
212
213
  "columns": {
    "messages": "conversations",
    "system": "system",
    "tools": "tools"
chenych's avatar
chenych committed
214
215
216
217
  }
}
```

luopl's avatar
luopl committed
218
219
220
221
### 预训练数据集

尚不支持,请使用 [alpaca](#alpaca-格式) 格式。

chenych's avatar
chenych committed
222
223
224
225
226
227
228
229
230
231
232
233
### 偏好数据集

- [样例数据集](dpo_zh_demo.json)

Sharegpt 格式的偏好数据集同样需要在 `chosen` 列中提供更优的消息,并在 `rejected` 列中提供更差的消息。

```json
[
  {
    "conversations": [
      {
        "from": "human",
mashun1's avatar
mashun1 committed
234
        "value": "用户指令"
chenych's avatar
chenych committed
235
236
237
238
239
240
241
      },
      {
        "from": "gpt",
        "value": "模型回答"
      },
      {
        "from": "human",
mashun1's avatar
mashun1 committed
242
        "value": "用户指令"
chenych's avatar
chenych committed
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
      }
    ],
    "chosen": {
      "from": "gpt",
      "value": "优质回答"
    },
    "rejected": {
      "from": "gpt",
      "value": "劣质回答"
    }
  }
]
```

对于上述格式的数据,`dataset_info.json` 中的*数据集描述*应为:

```json
"数据集名称": {
  "file_name": "data.json",
  "formatting": "sharegpt",
  "ranking": true,
  "columns": {
    "messages": "conversations",
    "chosen": "chosen",
    "rejected": "rejected"
  }
}
```

luopl's avatar
luopl committed
272
273
274
275
276
277
278
279
280
281
282
283
### KTO 数据集

- [样例数据集](kto_en_demo.json)

KTO 数据集需要额外添加一个 `kto_tag` 列,包含 bool 类型的人类反馈。

```json
[
  {
    "conversations": [
      {
        "from": "human",
mashun1's avatar
mashun1 committed
284
        "value": "用户指令"
luopl's avatar
luopl committed
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
      },
      {
        "from": "gpt",
        "value": "模型回答"
      }
    ],
    "kto_tag": "人类反馈 [true/false](必填)"
  }
]
```

对于上述格式的数据,`dataset_info.json` 中的*数据集描述*应为:

```json
"数据集名称": {
  "file_name": "data.json",
  "formatting": "sharegpt",
  "columns": {
    "messages": "conversations",
    "kto_tag": "kto_tag"
  }
}
```

### 多模态图像数据集

- [样例数据集](mllm_demo.json)

多模态图像数据集需要额外添加一个 `images` 列,包含输入图像的路径。

注意图片的数量必须与文本中所有 `<image>` 标记的数量严格一致。

```json
[
  {
    "conversations": [
      {
        "from": "human",
mashun1's avatar
mashun1 committed
323
        "value": "<image><image>用户指令"
luopl's avatar
luopl committed
324
325
326
327
328
329
330
      },
      {
        "from": "gpt",
        "value": "模型回答"
      }
    ],
    "images": [
mashun1's avatar
mashun1 committed
331
      "图像路径(必填)",
luopl's avatar
luopl committed
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
      "图像路径(必填)"
    ]
  }
]
```

对于上述格式的数据,`dataset_info.json` 中的*数据集描述*应为:

```json
"数据集名称": {
  "file_name": "data.json",
  "formatting": "sharegpt",
  "columns": {
    "messages": "conversations",
    "images": "images"
  }
}
```

### 多模态视频数据集

- [样例数据集](mllm_video_demo.json)

多模态视频数据集需要额外添加一个 `videos` 列,包含输入视频的路径。

注意视频的数量必须与文本中所有 `<video>` 标记的数量严格一致。

```json
[
  {
    "conversations": [
      {
        "from": "human",
mashun1's avatar
mashun1 committed
365
        "value": "<video><video>用户指令"
luopl's avatar
luopl committed
366
367
368
369
370
371
372
      },
      {
        "from": "gpt",
        "value": "模型回答"
      }
    ],
    "videos": [
mashun1's avatar
mashun1 committed
373
      "视频路径(必填)",
luopl's avatar
luopl committed
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
      "视频路径(必填)"
    ]
  }
]
```

对于上述格式的数据,`dataset_info.json` 中的*数据集描述*应为:

```json
"数据集名称": {
  "file_name": "data.json",
  "formatting": "sharegpt",
  "columns": {
    "messages": "conversations",
    "videos": "videos"
  }
}
```

chenych's avatar
chenych committed
393
394
395
396
397
398
399
400
401
402
403
404
405
406
### 多模态音频数据集

- [样例数据集](mllm_audio_demo.json)

多模态音频数据集需要额外添加一个 `audios` 列,包含输入音频的路径。

注意音频的数量必须与文本中所有 `<audio>` 标记的数量严格一致。

```json
[
  {
    "conversations": [
      {
        "from": "human",
mashun1's avatar
mashun1 committed
407
        "value": "<audio><audio>用户指令"
chenych's avatar
chenych committed
408
409
410
411
412
413
414
      },
      {
        "from": "gpt",
        "value": "模型回答"
      }
    ],
    "audios": [
mashun1's avatar
mashun1 committed
415
      "音频路径(必填)",
chenych's avatar
chenych committed
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
      "音频路径(必填)"
    ]
  }
]
```

对于上述格式的数据,`dataset_info.json` 中的*数据集描述*应为:

```json
"数据集名称": {
  "file_name": "data.json",
  "formatting": "sharegpt",
  "columns": {
    "messages": "conversations",
    "audios": "audios"
  }
}
```


chenych's avatar
chenych committed
436
437
438
439
440
441
442
443
444
445
446
447
448
449
### OpenAI 格式

OpenAI 格式仅仅是 sharegpt 格式的一种特殊情况,其中第一条消息可能是系统提示词。

```json
[
  {
    "messages": [
      {
        "role": "system",
        "content": "系统提示词(选填)"
      },
      {
        "role": "user",
mashun1's avatar
mashun1 committed
450
        "content": "用户指令"
chenych's avatar
chenych committed
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
      },
      {
        "role": "assistant",
        "content": "模型回答"
      }
    ]
  }
]
```

对于上述格式的数据,`dataset_info.json` 中的*数据集描述*应为:

```json
"数据集名称": {
  "file_name": "data.json",
  "formatting": "sharegpt",
  "columns": {
    "messages": "messages"
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
469
470
  },
  "tags": {
chenych's avatar
chenych committed
471
472
473
474
475
    "role_tag": "role",
    "content_tag": "content",
    "user_tag": "user",
    "assistant_tag": "assistant",
    "system_tag": "system"
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
476
477
478
  }
}
```