baichuan2-7B-chat 在逻辑数据集上微调后的模型
格式上,使用了多轮对话微调样例和输入输出格式微调样例。
运行需要 python>=3.9
pip install transformers==4.30.2 accelerate sentencepiece astunparse deepspeed
微调哲学家对话数据loss变化
多轮对话格式
数据格式和预处理
对于数据文件,样例采用如下格式
如果您仅希望微调模型的对话能力,而非工具能力,您应该按照以下格式整理数据。
[
{
"conversations": [
{
"role": "system",
"content": "<system prompt text>"
},
{
"role": "user",
"content": "<user prompt text>"
},
{
"role": "assistant",
"content": "<assistant response text>"
},
// ... Muti Turn
{
"role": "user",
"content": "<user prompt text>"
},
{
"role": "assistant",
"content": "<assistant response text>"
}
]
}
// ...
]
请注意,这种方法在微调的step较多的情况下会影响到模型的工具调用功能
如果您希望微调模型的对话和工具能力,您应该按照以下格式整理数据。
[
{
"tools": [
// available tools, format is not restricted
],
"conversations": [
{
"role": "system",
"content": "<system prompt text>"
},
{
"role": "user",
"content": "<user prompt text>"
},
{
"role": "assistant",
"content": "<assistant thought to text>"
},
{
"role": "tool",
"name": "<name of the tool to be called",
"parameters": {
"<parameter_name>": "<parameter_value>"
},
"observation": "<observation>"
// don't have to be string
},
{
"role": "assistant",
"content": "<assistant response to observation>"
},
// ... Muti Turn
{
"role": "user",
"content": "<user prompt text>"
},
{
"role": "assistant",
"content": "<assistant response text>"
}
]
}
// ...
]
关于工具描述的 system prompt 无需手动插入,预处理时会将
tools
字段使用json.dumps(..., ensure_ascii=False)
格式化后插入为首条 system prompt。每种角色可以附带一个
bool
类型的loss
字段,表示该字段所预测的内容是否参与loss
计算。若没有该字段,样例实现中默认对system
,user
不计算loss
,其余角色则计算loss
。tool
并不是 ChatGLM3 中的原生角色,这里的tool
在预处理阶段将被自动转化为一个具有工具调用metadata
的assistant
角色(默认计算loss
)和一个表示工具返回值的observation
角色(不计算loss
)。目前暂未实现
Code interpreter
的微调任务。system
角色为可选角色,但若存在system
角色,其必须出现在user
角色之前,且一个完整的对话数据(无论单轮或者多轮对话)只能出现一次system
角色。
输入输出格式
对于输入-输出格式,样例采用如下输入格式
[
{
"prompt": "<prompt text>",
"response": "<response text>"
}
// ...
]
评论