From 9cf5d89bd17b70c018e9b9a955c259282a6fc225 Mon Sep 17 00:00:00 2001 From: hiyouga Date: Sat, 10 Feb 2024 21:04:29 +0800 Subject: [PATCH] update data/readme Former-commit-id: a754f6e9ec157ba76178fa8ea8111e0c7b06008b --- data/README.md | 6 +++--- data/README_zh.md | 6 +++--- src/llmtuner/data/aligner.py | 10 +++++++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/data/README.md b/data/README.md index d95c4b86..fa2c9ee0 100644 --- a/data/README.md +++ b/data/README.md @@ -65,9 +65,9 @@ Regarding the above dataset, the `columns` in `dataset_info.json` should be: } ``` -where the `prompt` and `response` columns should contain non-empty values, represent instruction and response respectively. The `query` column will be concatenated with the `prompt` column and used as input for the model. +The `query` column will be concatenated with the `prompt` column and used as the user prompt, then the user prompt would be `prompt\nquery`. The `response` column represents the model response. -The `system` column will be used as the system prompt in the template. The `history` column is a list consisting string tuples representing query-response pairs in history. Note that the responses **in each round will be used for training**. +The `system` column will be used as the system prompt. The `history` column is a list consisting string tuples representing prompt-response pairs in the history. Note that the responses in the history **will also be used for training**. For the pre-training datasets, only the `prompt` column will be used for training. @@ -123,6 +123,6 @@ Regarding the above dataset, the `columns` in `dataset_info.json` should be: } ``` -where the `messages` column should be a list whose length is even, and follow the `u/a/u/a/u/a` order. +where the `messages` column should be a list following the `u/a/u/a/u/a` order. Pre-training datasets and preference datasets are incompatible with the sharegpt format yet. diff --git a/data/README_zh.md b/data/README_zh.md index f228a921..e0004f4a 100644 --- a/data/README_zh.md +++ b/data/README_zh.md @@ -65,9 +65,9 @@ } ``` -其中 `prompt` 和 `response` 列应当是非空的字符串,分别代表用户指令和模型回答。`query` 列的内容将会和 `prompt` 列拼接作为模型输入。 +其中 `query` 列对应的内容会与 `prompt` 列对应的内容拼接后作为用户指令,即用户指令为 `prompt\nquery`。`response` 列对应的内容为模型回答。 -`system` 为模板中的系统提示词。`history` 列是由多个字符串二元组构成的列表,分别代表历史消息中每轮的指令和回答。注意每轮的模型回答**均会被用于训练**。 +`system` 列对应的内容将被作为系统提示词。`history` 列是由多个字符串二元组构成的列表,分别代表历史消息中每轮的指令和回答。注意历史消息中的回答**也会被用于训练**。 对于预训练数据集,仅 `prompt` 列中的内容会用于模型训练。 @@ -123,6 +123,6 @@ } ``` -其中 `messages` 列必须为偶数长度的列表,且符合 `用户/模型/用户/模型/用户/模型` 的顺序。 +其中 `messages` 列应当是一个列表,且符合 `用户/模型/用户/模型/用户/模型` 的顺序。 预训练数据集和偏好数据集尚不支持 sharegpt 格式。 diff --git a/src/llmtuner/data/aligner.py b/src/llmtuner/data/aligner.py index 2510e636..a982ec32 100644 --- a/src/llmtuner/data/aligner.py +++ b/src/llmtuner/data/aligner.py @@ -20,10 +20,14 @@ def convert_alpaca(examples: Dict[str, List[Any]], dataset_attr: "DatasetAttr") prompt.append({"role": Role.USER, "content": old_prompt}) prompt.append({"role": Role.ASSISTANT, "content": old_response}) - instruction = examples[dataset_attr.prompt][i] + content = [] + if dataset_attr.prompt and examples[dataset_attr.prompt][i]: + content.append(examples[dataset_attr.prompt][i]) + if dataset_attr.query and examples[dataset_attr.query][i]: - instruction += "\n" + examples[dataset_attr.query][i] - prompt.append({"role": Role.USER, "content": instruction}) + content.append(examples[dataset_attr.query][i]) + + prompt.append({"role": Role.USER, "content": "\n".join(content)}) if dataset_attr.response and isinstance(examples[dataset_attr.response][i], list): response = [{"role": Role.ASSISTANT, "content": content} for content in examples[dataset_attr.response][i]]