qwen指令微调中对话样本是否需要加入指令分析

文章探讨了如何在训练Qwen这样的大模型时,通过指令微调数据增强其功能调用能力,并考虑了自我认知、对话等其他相关能力的训练。强调了训练数据的选择对模型适应业务场景的重要性。
摘要由CSDN通过智能技术生成

场景

当训练一个具有业务的功能的大模型时,有的时候不能直接通过prompt就能达到很好的效果,需要准备一些指令微调数据,让模型能够训练学习到如何使用我们的业务的工具,更好的使用我们的工具,而在模型进行指令微调过程中,往往目标是不仅仅让模型有function calling的能力,也需要其他的配套能力,比如自我认知、对话等等,所以训练数据不仅仅局限于指令微调数据,也需要其他一些数据,例如自我认知数据、多轮对话数据等等。

问题

以qwen为例,在推理过程中,当我们给模型配置完functions时,qwen会以instruct的形式注入到input当中

messages = [{"role": "user", "content": "你好"}]
rnt = openai.ChatCompletion.create(model="Qwen", messages=messages, functions=qwen_functions, temperature=0)

此时,指令内容会放入到用户问前面

f"{QWEN_INSTRUCTION}\n\nQuestion: 你好"

传入到模型的input是token和msg的拼接

<|im_start|>system
You are a helpful assistant.<|im_end|>
<|im_start|>user
Answer the following questions as best you can. You have access to the following APIs:

google_search: Call this tool to interact with the 谷歌搜索 API. What is the 谷歌搜索 API useful for? 谷歌搜索是一个通用搜索引擎,可用于访问互联网、查询百科知识、了解时事新闻等。 Format the arguments as a JSON object. Parameters: [{"name": "search_query", "description": "搜索关键词或短语", "required": true, "schema": {"type": "string"}}]

image_gen: Call this tool to interact with the 文生图 API. What is the 文生图 API useful for? 文生图是一个AI绘画(图像生成)服务,输入文本描述,返回根据文本作画得到的图片的URL。 Format the arguments as a JSON object. Parameters: [{"name": "prompt", "description": "英文关键词,描述了希望图像具有什么内容", "required": true, "schema": {"type": "string"}}]

Use the following format:

Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [google_search, image_gen]
Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can be repeated zero or more times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question

Begin!

Question: 你好<|im_end|>
<|im_start|>assistant

而在训练过程中,由于qwen训练不提供instruct的配置,为了让模型学会调用我们业务上的function,同时保证训练和推理数据的一直性,需要在训练数据input前手动加上instruct内容,让我模型训练时有instruct。

对于指令微调数据肯定需要加instruct的,但是对于非指令数据是否需要加入instruct是需要思考的问题。因为在推理过程中,因为配置了function,不管是否是需要调用function的input,都会传入instruct给予模型,而这些得出不需要function得出的output,是在input中有instruct存在而产生的,是否让这些不调用function的input适配instruct的存在,是考量的问题。

分析

举例来说,我们先让模型进行一个给予function但又不用function 的推理。

messages = [{"role": "user", "content": "你好"}]
rnt = openai.ChatCompletion.create(model="Qwen", messages=messages, functions=qwen_functions, temperature=0)
<|im_start|>system
You are a helpful assistant.<|im_end|>
<|im_start|>user
Answer the following questions as best you can. You have access to the following APIs:

google_search: Call this tool to interact with the 谷歌搜索 API. What is the 谷歌搜索 API useful for? 谷歌搜索是一个通用搜索引擎,可用于访问互联网、查询百科知识、了解时事新闻等。 Format the arguments as a JSON object. Parameters: [{"name": "search_query", "description": "搜索关键词或短语", "required": true, "schema": {"type": "string"}}]

image_gen: Call this tool to interact with the 文生图 API. What is the 文生图 API useful for? 文生图是一个AI绘画(图像生成)服务,输入文本描述,返回根据文本作画得到的图片的URL。 Format the arguments as a JSON object. Parameters: [{"name": "prompt", "description": "英文关键词,描述了希望图像具有什么内容", "required": true, "schema": {"type": "string"}}]

Use the following format:

Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [google_search, image_gen]
Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can be repeated zero or more times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question

Begin!

Question: 你好<|im_end|>
<|im_start|>assistant

模型的output是这个样子的,后续qwen经部署程序处理后会直接返回的内容final answer的内容

"Thought: 提供的工具帮助较小,我将直接回答。\nFinal Answer: 你好!有什么我可以帮你的吗?"

而不给与function直接向模型推理

messages = [{"role": "user", "content": "你好"}]
rnt = openai.ChatCompletion.create(model="Qwen", messages=messages, temperature=0)

input

<|im_start|>system
You are a helpful assistant.<|im_end|>
<|im_start|>user
你好<|im_end|>
<|im_start|>assistant

output

"你好!有什么我能帮助你的吗?"

首先,我们能够看到,两种方式的output时不一样的,有instruct的output中会有thought思考内容和最终回答内容,也就是说有instruct的大模型在按照我们的cot在运行工作,同时模型没有应用我们提供的access,而是使用自己的先验知识进行回答。

因此需要把模型上面的涉及能力拆成两部分来说,一部分是instruct能力,一部分是使用access能力,而这两种能力在同为需要需要调用function的数据时,是都增加的,而对于加上instruct的对话类不调用function的数据,增加的是instruct能力,强化的是不使用access的能力

然后,我们尝试正反两个方向分析一下如果以推理数据内容进行训练的影响

1优势:模型提升react能力,强化模型反思决策的能力;劣势:过度微雕,模型会倾向我们提供react的cot思考问题,对于其他instruct能力,或者非instruct能力的弱化

2优势:让模型学会在有提供access的前提下,预期output不被access干扰,模型结合access能力和自身能力进行最终output的输出。劣势:如果不使用access的数据量很大,让模型学习到的是不使用access独立解决的能力。

此外,训练数据是否要和推理数据要保持一致呢?这个目标的前提是数据质量,如果推理数据是高质量数据,那么需要让训练数据和推理数据保持一致,如果推理数据中本身就含有一大堆噪音,那么没必要让噪音出现在训练数据中。

所以,到底我们要怎么训练合适,一味的追求适配推理场景数据是不合适的,归根揭底我们要从模型能力出发,我们要根据我们需要的模型能力进行训练,同时也需要根据模型能力的重要程度进行不同数据的配比。想我们认为对话能力,自我认知能力,指令能力都是比较重要的,所以在我们训练中训练数据比例要重一些,让模型适配业务的cot逻辑也是比较重要的,数据比例也应当要高,而像模型不依赖access独立回答的能力或者是模型对于是否调用acess的决策能力,相对来说并没有特别重要,还有就是是模型是否一定遵守cot逻辑思考问题的能力,也不是特别重要,可以这些加入instruct的对话等相关数据当作一些小样本或者负样本进行训练。

参考来源:Qwen Function Calling 的对话模板及训练方法总结 - 知乎 (zhihu.com)

  • 9
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值