将推理与外部搜索过程相结合仍然具有挑战性,尤其是对于需要多个检索步骤的复杂多跳问题而言。为了解决这一问题,本文提出了ReSearch,这是一个全新的框架,它通过强化学习来训练大语言模型(LLM),使其能够借助搜索进行推理,且在推理步骤上不使用任何有监督的数据。
概述
方法
强化学习
这里的主要思路是对多个借助搜索的推理链(即轨迹采样)进行采样,并优化策略(即大语言模型),以使生成具有更高奖励的轨迹采样的概率最大化,如下图所示,其中(a)为通用相对策略优化算法(GRPO)流程。(b)为轨迹采样生成过程的详细信息。
a) 群体相对策略优化(GRPO)
GRPO被用作学习算法,它从一组轨迹采样中估计基线,而不是像近端策略优化(PPO)算法那样训练一个单独的评判模型。
给定一个现有的策略πθ旧和一个参考策略πθ参考,基于G个轨迹采样 。
对于每个服从分布\(D\)的输入\(x\),群体相对策略优化(GRPO)的目标是通过最大化以下目标函数来优化策略\(\pi_{\theta}\):
其中\(A_i = r_i - \frac{\text{mean}(\{r_j\}_{j = 1}^{G})}{\text{std}(\{r_j\}_{j = 1}^{G})}\)是当前组中第\(i\)次轨迹采样的归一化优势值,\(\epsilon\)是裁剪比率,\(\beta\)是KL散度损失系数。
b) 带搜索的轨迹采样
c) 检索结果掩码处理
训练模板
为了引导大语言模型理解这种轨迹采样格式,特别是那些指示何时调用搜索操作的标签,创建了两个提示模板:一个用于基础(即预训练)模型,另一个用于指令微调模型。
Prompt Template For Base Model
A conversation between User and Assistant. The user asks a question, and the assistant solves
it. The assistant first thinks about the reasoning process in the mind and then provides the
user with the answer. During thinking, the assistant can invoke the wikipedia search tool
to search for fact information about specific topics if needed. The reasoning process and
answer are enclosed within <think> </think> and <answer> </answer> tags respectively,
and the search query and result are enclosed within <search> </search> and <result>
</result> tags respectively. For example, <think> This is the reasoning process. </think>
<search> search query here </search> <result> search result here </result> <think>
This is the reasoning process. </think> <answer> The final answer is \boxed{answer here}
</answer>. In the last part of the answer, the final exact answer is enclosed within \boxed{}
with latex format. User: prompt. Assistant:
System Prompt Template For Instruction-Tuned Model
You are a helpful assistant that can solve the given question step by step with the help of the
wikipedia search tool. Given a question, you need to first think about the reasoning process in
the mind and then provide the answer. During thinking, you can invoke the wikipedia search
tool to search for fact information about specific topics if needed. The reasoning process and
answer are enclosed within <think> </think> and <answer> </answer> tags respectively,
and the search query and result are enclosed within <search> </search> and <result>
</result> tags respectively. For example, <think> This is the reasoning process. </think>
<search> search query here </search> <result> search result here </result> <think>
This is the reasoning process. </think> <answer> The final answer is \boxed{answer here}
</answer>. In the last part of the answer, the final exact answer is enclosed within \boxed{}
with latex format.
对于基础模型,这个填入了特定用户问题的模板将作为大语言模型的直接输入。
对于经过指令微调的模型,其提示模板用作系统提示,与该指令微调大语言模型对应的聊天模板结合使用。
奖励建模
奖励函数考虑以下两个部分:答案奖励和格式奖励。
a) 答案奖励
通过F1分数来计算最终答案(在\boxed{} 中)与真实答案的正确性。
b) 格式奖励
检查轨迹采样是否正确遵循了我们在提示模板中所定义的格式,主要检查标签的正确性以及答案中是否存在\boxed{} 。
具体来说,对于一次轨迹采样的最终奖励:
其中\(a_{pred}\)是\(\boxed{}\)中的最终答案,\(a_{gt}\)是真实答案,\(f1(a_{pred}, a_{gt})\)是\(a_{pred}\)和\(a_{gt}\)之间的F1分数。
实验
实现方式
结果
下面的表格展示了分别基于不同规模大语言模型的方法。
从上述表格中可得出以下结论:
a) ReSearch的有效性
b) 基础模型与指令微调模型的比较
c) 泛化能力
分析
a) 回复长度和搜索操作次数
下面的图表展示了训练过程中的回复长度和搜索操作次数。
结果表明,在整个训练过程中,回复长度和搜索操作的次数总体上是增加的。
b) 训练与验证奖励
下面的图表展示了ReSearch在强化学习过程中的训练奖励和验证奖励。
在最初的20个训练步骤中,奖励大幅提升,随后逐渐增加。对于70亿参数和320亿参数的指令微调模型,其冷启动奖励都更高。
对于70亿参数的模型,基础模型和指令微调模型的奖励收敛到了相近的水平;而对于320亿参数的模型,指令微调模型的训练奖励高于基础模型。
结论
本文介绍了ReSearch,这是一个全新的框架,它通过强化学习来训练大语言模型,使其能够借助搜索进行推理,且无需任何关于推理步骤的有监督数据。
该方法将搜索操作整合为推理链的重要组成部分,其中基于文本的思考会指导何时以及如何执行搜索,而搜索结果随后会影响进一步的推理。
在多个多跳问答基准测试上进行的大量实验表明,与基线方法相比,ReSearch取得了显著的改进。