Search agent 怎么训?
reward 怎么设计,怎么防 reward hacking?
先弄清楚:每个概念是什么
- Rollout
- 模型做一遍题的全过程:想,发出 search query,系统插入检索结果,再想,最后回答。Search-R1 用四种 tag 标记:
<think>、<search>、<information>、<answer>。 - Outcome reward
- 只看最终答案对不对。Search-R1 用 exact match,没有 format reward,也没有 neural reward model。
- Retrieved token masking
- 检索结果是 retriever 给的,不是 policy 的 action,所以算 loss 时跳过这些 token,否则等于训练模型去“生成”检索结果。Search-R1 的 ablation(Qwen2.5-7B-Base,PPO):平均 EM 有 masking 是 0.431,没有是 0.343。
- PPO 与 GRPO
- GRPO 用同一题一组回答的平均 reward 当 baseline,不像 PPO 要另训 critic(见 RLHF、DPO、GRPO)。Search-R1 里 GRPO 收敛更快,但训久了 reward 可能崩。PPO 更稳,两者最终 reward 相近。
- Reward hacking
- 模型找到让 reward 变高、但没完成任务的捷径。例:reward 用 substring match,模型就把所有候选答案都列出来。
30 秒回答
I'd start with supervised fine-tuning on good trajectories so the model learns the format, then use RL to improve search behavior. Each rollout interleaves reasoning, search queries, and retrieved results until an answer. The simplest reward is outcome-only, like exact match on the final answer; Search-R1 does this. The loss is computed only on tokens the model generated, masking the retrieved text. I'd cap the number of searches and guard against reward hacking with a strict verifier, a held-out check, and reading the trajectories whose reward jumped.
Reward 怎么选
| 设计 | 优点 | 风险 |
|---|---|---|
| Outcome only (EM 或 verifier) | 简单,难被格式骗 | sparse;EM 太严,同义答案算错 |
| 加 process reward (找到 gold 文档、步数惩罚) | 信号更密 | 模型去刷中间分;需要 gold evidence |
| Reward model 或 LLM judge | 能评开放式回答 | judge 的漏洞和偏好会被模型学走 |
防 reward hacking:verifier 用 exact match 或规则,不用宽松匹配。训练用一个 verifier,评估另留一个 held-out 的。限制输出长度和 search 次数(Search-R1 的 action 上限是 4,见多步 search loop)。抽看 reward 突然上涨的 trajectory。reward 和人工评分对不上就停下来修。
迁移到对话任务:对话没有唯一正确答案,所以把 reward 拆成两部分。可验证的部分(任务完成、事实 grounded)用规则或 verifier,偏好的部分(是否有帮助)用 pairwise 人工偏好训 reward model。对话里容易被 hack 的是长度和讨好语气,要限制长度,并用人工校准 reward model。
必答点
- 先 SFT 学格式,再 RL 学怎么搜
- outcome reward 最简单;加 process reward 要小心被刷
- loss 只算模型生成的 token(retrieved token masking)
- PPO 稳,GRPO 快且不需要 critic
- reward hacking:收紧 verifier、held-out 检查、人工看 trajectory
追问
reward 几乎全是 0(太 sparse)怎么办?
先 SFT,让初始成功率不为 0。再用 curriculum 从单跳题开始,加少量 process reward。
你的项目怎么接上?
Excel Copilot 的 RL environment 同样有 task、episode、reward、verifier,训练路线也是先 SFT 再 RL。只讲简历上公开的层面。
来源Jin et al. 2025, Search-R1:四种 tag、outcome-only EM reward、retrieved token masking 的 ablation、PPO 与 GRPO 对比、Appendix B.2 的 action budget · 牛客:Apple 大模型算法面经