【大模型LLM第十三篇】Agent入门之CoT,self-ask,Plan-and-execute,ReAct串讲
前言
本文主要快速总结Agent的初步形成的范式, 从COT,self-ask,Plan-and-execute agents,到ReAct目前相对来说比较广泛应用的范式。
关于Prompt可以看我之前的三篇文章:
- https://zhuanlan.zhihu.com/p/686139236
- https://zhuanlan.zhihu.com/p/687416466
- https://zhuanlan.zhihu.com/p/687424881
CoT
google的paper:《Chain-of-Thought Prompting Elicits Reasoning in Large Language Models》
- 链接:https://arxiv.org/abs/2201.11903
也很好理解,以前让大模型直接输出结果,而现在让大模型有个把task进行分解一步步分析的过程,输出的结果更准确。
本质还是为prompt提供few shot,但是few shot中除了输入和结果外,在得到结果之前会有逻辑依据
Zero-shot Cot
Large Language Models are Zero-Shot Reasoners
- paper: https://arxiv.org/pdf/2205.11916
提出了 把few shot Cot内容直接改成 让模型一步步想想,就可以达到一样的准确结果
Self-Ask
在2022年10月被提出,主要思路为在思维链的基础上进行优化
Measuring and Narrowing the Compositionality Gap in Language Models.
- paper:https://arxiv.org/pdf/2210.03350
- code:https://github.com/ofirpress/self-ask
按这张图就很清楚了,相当于显式的让大模型对自己提问,自己一步步把结果回答出来,并且这里可以轻松的引入web seach来更好的解决问题。
Plan-and-execute agents
Plan-and-Solve Prompting: Improving Zero-Shot Chain-of-Thought Reasoning by Large Language Models
- 论文链接:https://arxiv.org/abs/2305.04091
- 代码链接:https://github.com/AGI-Edgerunners/Plan-and-Solve-Prompting
中心思想:让大模型先制定一个plan,之后再将计划的每个step,依次进行。
实现上就是将 zero-shot CoT的Let’s think step by step
修改为Let’s first understand the problem and devise a plan to solve the problem. Then, let’s carry out the plan and solve the problem step by step
langchain的实现例子:https://github.com/langchain-ai/langgraph/blob/main/examples/plan-and-execute/plan-and-execute.ipynb
ReAct
ReAct: Synergizing Reasoning and Acting in Language Models
链接:https://arxiv.org/abs/2210.0362
9
简单来说就是thought-action-observation范式
在实验中还比较了不思考,只Act的结果依然无法得到正确答案。
本质创新思想就是将Act和Reason相结合,而这个动作其实和人做事情也差不多,思考,用工具,得到工具的结果,再反复这个过程。
如果有时间推荐可以看看这个代码,感受一下这个loop大概是怎么写的,以及system prompt里面的few shot是怎么写的,在这个实验中tool主要是Wikipedia。
用到的数据集讲解:https://viewsetting.xyz/2019/10/20/HotpotQA%E6%95%B0%E6%8D%AE%E9%9B%86%E6%8E%A2%E7%B4%A2/
目前来说ReAct Agent范式基本上是最流行的一种范式,在langchaing等工具上也都已经集成可以很方便的使用