From cc8ffa10d877f5893f3940204e5bec6f3266559f Mon Sep 17 00:00:00 2001 From: hiyouga Date: Thu, 2 Nov 2023 23:42:49 +0800 Subject: [PATCH] update data readme (zh) --- README.md | 2 +- README_zh.md | 2 +- data/README.md | 2 +- data/README_zh.md | 109 +++++++++++++++++++++++++----- data/dataset_info.json | 20 ------ src/llmtuner/dsets/loader.py | 8 +-- src/llmtuner/hparams/data_args.py | 6 ++ 7 files changed, 105 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 2a87b659..405e9e37 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ Please refer to [template.py](src/llmtuner/extras/template.py) for a full list o - [ShareGPT4 (en&zh)](https://huggingface.co/datasets/shibing624/sharegpt_gpt4) - [UltraChat 200k (en)](https://huggingface.co/datasets/HuggingFaceH4/ultrachat_200k) - [AgentInstruct (en)](https://huggingface.co/datasets/THUDM/AgentInstruct) -- [LMSYS Chat (en)](https://huggingface.co/datasets/lmsys/lmsys-chat-1m) +- [LMSYS Chat 1M (en)](https://huggingface.co/datasets/lmsys/lmsys-chat-1m) - [Evol Instruct V2 (en)](https://huggingface.co/datasets/WizardLM/WizardLM_evol_instruct_V2_196k) diff --git a/README_zh.md b/README_zh.md index 2e40c63f..b4a7174f 100644 --- a/README_zh.md +++ b/README_zh.md @@ -129,7 +129,7 @@ https://github.com/hiyouga/LLaMA-Factory/assets/16256802/6ba60acc-e2e2-4bec-b846 - [ShareGPT4 (en&zh)](https://huggingface.co/datasets/shibing624/sharegpt_gpt4) - [UltraChat 200k (en)](https://huggingface.co/datasets/HuggingFaceH4/ultrachat_200k) - [AgentInstruct (en)](https://huggingface.co/datasets/THUDM/AgentInstruct) -- [LMSYS Chat (en)](https://huggingface.co/datasets/lmsys/lmsys-chat-1m) +- [LMSYS Chat 1M (en)](https://huggingface.co/datasets/lmsys/lmsys-chat-1m) - [Evol Instruct V2 (en)](https://huggingface.co/datasets/WizardLM/WizardLM_evol_instruct_V2_196k) diff --git a/data/README.md b/data/README.md index 8a11561e..4a203f35 100644 --- a/data/README.md +++ b/data/README.md @@ -2,7 +2,7 @@ If you are using a custom dataset, please provide your dataset definition in the ```json "dataset_name": { - "hf_hub_url": "the name of the dataset repository on the HuggingFace hub. (if specified, ignore below 3 arguments)", + "hf_hub_url": "the name of the dataset repository on the Hugging Face hub. (if specified, ignore below 3 arguments)", "script_url": "the name of the directory containing a dataset loading script. (if specified, ignore below 2 arguments)", "file_name": "the name of the dataset file in the this directory. (required if above are not specified)", "file_sha1": "the SHA-1 hash value of the dataset file. (optional)", diff --git a/data/README_zh.md b/data/README_zh.md index a8f62ca2..66e666e2 100644 --- a/data/README_zh.md +++ b/data/README_zh.md @@ -1,32 +1,107 @@ -如果您使用自定义数据集,请务必在 `dataset_info.json` 文件中以如下格式提供您的数据集定义。 +如果您使用自定义数据集,请务必在 `dataset_info.json` 文件中按照以下格式提供数据集定义。 ```json "数据集名称": { - "hf_hub_url": "HuggingFace上的项目地址(若指定,则忽略下列三个参数)", - "script_url": "包含数据加载脚本的本地文件夹名称(若指定,则忽略下列两个参数)", - "file_name": "该目录下数据集文件的名称(若上述参数未指定,则此项必需)", - "file_sha1": "数据集文件的SHA-1哈希值(可选)", - "ranking": "数据集是否包含排序后的回答(默认:false)", - "columns": { - "prompt": "数据集代表提示词的表头名称(默认:instruction)", - "query": "数据集代表请求的表头名称(默认:input)", - "response": "数据集代表回答的表头名称(默认:output)", - "history": "数据集代表历史对话的表头名称(默认:None)" + "hf_hub_url": "Hugging Face 上的项目地址", // 若指定,则忽略下列三个参数 + "script_url": "包含数据加载脚本的本地文件夹名称", // 若指定,则忽略下列两个参数 + "file_name": "该目录下数据集文件的名称", // 若上述参数未指定,则此项必需 + "file_sha1": "数据集文件的SHA-1哈希值", // 可选,留空不影响训练 + "subset": "数据集子集的名称", // 可选,默认:None + "ranking": "是否为偏好数据集", // 可选,默认:False + "formatting": "数据集格式", // 可选,默认:alpaca,可以为 alpaca 或 sharegpt + "columns": { // 可选 + "prompt": "数据集代表提示词的表头名称", // 默认:instruction(alpaca 格式) + "query": "数据集代表请求的表头名称", // 默认:input(alpaca 格式) + "response": "数据集代表回答的表头名称", // 默认:output(alpaca 格式) + "history": "数据集代表历史对话的表头名称", // 默认:None(alpaca 格式) + "messages": "数据集代表消息列表的表头名称", // 默认:conversations(sharegpt 格式) + "role": "消息中代表发送者身份的键名", // 默认:from(sharegpt 格式) + "content": "消息中代表文本内容的键名" // 默认:value(sharegpt 格式) } } ``` -其中 `prompt` 和 `response` 列应当是非空的字符串。`query` 列的内容将会和 `prompt` 列拼接作为模型输入。`history` 列应当是一个列表,其中每个元素是一个字符串二元组,分别代表用户请求和模型答复。 +添加后可通过指定 `--dataset 数据集名称` 参数使用自定义数据集。 -对于训练奖励模型或 DPO 训练的数据集,`response` 列应当是一个字符串列表,排在前面的代表更优的答案,例如: +该项目目前支持两种格式的数据集:alpaca 和 sharegpt,其中 alpaca 格式的数据集按照以下方式组织: + +```json +[ + { + "instruction": "用户指令", // 必填 + "input": "用户输入", // 选填 + "output": "模型回答", // 必填 + "history": [ // 选填 + ["第一轮指令", "第一轮回答"], + ["第二轮指令", "第二轮回答"] + ] + } +] +``` + +对于上述格式的数据,定义中的 `columns` 应当为: + +```json +"数据集名称": { + "columns": { + "prompt": "instruction", + "query": "input", + "response": "output", + "history": "history" + } +} +``` + +其中 `prompt` 和 `response` 列应当是非空的字符串,分别代表用户指令和模型回答。`query` 列的内容将会和 `prompt` 列拼接作为模型输入。 + +`history` 列是由多个字符串二元组构成的列表,分别代表历史消息中每轮的指令和回答。每轮的模型回答**均会被用于训练**。 + +对于预训练数据集,仅 `prompt` 列中的内容会用于模型训练。 + +对于偏好数据集,`response` 列应当是一个长度为 2 的字符串列表,排在前面的代表更优的回答,例如: ```json { - "instruction": "Question", - "input": "", + "instruction": "用户指令", + "input": "用户输入", "output": [ - "Chosen answer", - "Rejected answer" + "优质回答", + "劣质回答" ] } ``` + +而 sharegpt 格式的数据集按照以下方式组织: + +```json +[ + { + "conversations": [ // 必填 + [ + { + "from": "human", + "value": "用户指令" + }, + { + "from": "gpt", + "value": "模型回答" + } + ] // 长度必须为 2 的倍数且符合 u/a/u/a/u/a 顺序 + ] + } +] +``` + +对于上述格式的数据,定义中的 `columns` 应当为: + +```json +"数据集名称": { + "columns": { + "messages": "conversations", + "role": "from", + "content": "value" + } +} +``` + +预训练数据集和偏好数据集尚不支持 sharegpt 格式。 diff --git a/data/dataset_info.json b/data/dataset_info.json index e4c4fb2d..5a25a34a 100644 --- a/data/dataset_info.json +++ b/data/dataset_info.json @@ -144,20 +144,10 @@ }, "sharegpt_hyper": { "hf_hub_url": "totally-not-an-llm/sharegpt-hyperfiltered-3k", - "columns": { - "prompt": "conversations", - "query": "from", - "response": "value" - }, "formatting": "sharegpt" }, "sharegpt4": { "hf_hub_url": "shibing624/sharegpt_gpt4", - "columns": { - "prompt": "conversations", - "query": "from", - "response": "value" - }, "formatting": "sharegpt" }, "ultrachat_200k": { @@ -171,11 +161,6 @@ }, "agent_instruct": { "hf_hub_url": "THUDM/AgentInstruct", - "columns": { - "prompt": "conversations", - "query": "from", - "response": "value" - }, "formatting": "sharegpt" }, "lmsys_chat": { @@ -189,11 +174,6 @@ }, "evol_instruct": { "hf_hub_url": "WizardLM/WizardLM_evol_instruct_V2_196k", - "columns": { - "prompt": "conversations", - "query": "from", - "response": "value" - }, "formatting": "sharegpt" }, "hh_rlhf_en": { diff --git a/src/llmtuner/dsets/loader.py b/src/llmtuner/dsets/loader.py index 46db294a..0a4a17f6 100644 --- a/src/llmtuner/dsets/loader.py +++ b/src/llmtuner/dsets/loader.py @@ -69,7 +69,7 @@ def get_dataset( def convert_format(examples: Dict[str, List[Any]]) -> Dict[str, List[Any]]: # convert dataset from sharegpt format to alpaca format outputs = {"prompt": [], "query": [], "response": [], "history": []} - for msg_list in examples[dataset_attr.prompt]: + for msg_list in examples[dataset_attr.messages]: msg_list = msg_list[:len(msg_list) // 2 * 2] # should be multiples of 2 if len(msg_list) == 0: continue @@ -78,15 +78,15 @@ def get_dataset( user_role, assistant_role = None, None for idx in range(0, len(msg_list), 2): if user_role is None and assistant_role is None: - user_role = msg_list[idx][dataset_attr.query] - assistant_role = msg_list[idx + 1][dataset_attr.query] + user_role = msg_list[idx][dataset_attr.role] + assistant_role = msg_list[idx + 1][dataset_attr.role] else: if ( msg_list[idx][dataset_attr.query] != user_role or msg_list[idx+1][dataset_attr.query] != assistant_role ): raise ValueError("Only accepts conversation in u/a/u/a/u/a order.") - msg_pairs.append((msg_list[idx][dataset_attr.response], msg_list[idx + 1][dataset_attr.response])) + msg_pairs.append((msg_list[idx][dataset_attr.content], msg_list[idx + 1][dataset_attr.content])) if len(msg_pairs) != 0: outputs["prompt"].append(msg_pairs[-1][0]) diff --git a/src/llmtuner/hparams/data_args.py b/src/llmtuner/hparams/data_args.py index 2f4cda38..4c67dd65 100644 --- a/src/llmtuner/hparams/data_args.py +++ b/src/llmtuner/hparams/data_args.py @@ -19,6 +19,9 @@ class DatasetAttr: query: Optional[str] = "input" response: Optional[str] = "output" history: Optional[str] = None + messages: Optional[str] = "conversations" + role: Optional[str] = "from" + content: Optional[str] = "value" def __repr__(self) -> str: return self.dataset_name @@ -155,6 +158,9 @@ class DataArguments: dataset_attr.query = dataset_info[name]["columns"].get("query", None) dataset_attr.response = dataset_info[name]["columns"].get("response", None) dataset_attr.history = dataset_info[name]["columns"].get("history", None) + dataset_attr.messages = dataset_info[name]["columns"].get("messages", None) + dataset_attr.role = dataset_info[name]["columns"].get("role", None) + dataset_attr.content = dataset_info[name]["columns"].get("content", None) dataset_attr.subset = dataset_info[name].get("subset", None) dataset_attr.ranking = dataset_info[name].get("ranking", False)