当前位置: 首页 > news >正文

2023-ICLR-ReAct 首次结合Thought和Action提升大模型解决问题的能力


关于普林斯顿大学和Google Research, Brain Team合作的一篇文章, 在语言模型中协同Reasoning推理和Action行动。

论文地址:https://arxiv.org/abs/2210.03629
代码:https://github.com/ysymyth/ReAct.git
其他复现 langchain :https://python.langchain.com/api_reference/langchain/agents/langchain.agents.agent.AgentExecutor.html#

作者们注意到,尽管LLMs在理解和生成方面表现出色,但它们在推理和行动方面的能力通常是分开研究的。他们提出,通过交互式的方式生成推理痕迹(reason)和任务特定行动(act),可以更有效地结合这两种能力,从而提高模型的 interpretability、trustworthiness 和解决复杂任务的能力。

数据:

  • HotpotQA: 多跳问题回答基准,需要模型跨越多个Wikipedia页面进行推理。
  • FEVER: 事实验证基准,模型必须基于Wikipedia页面验证声明的真实性。
    方法:
  • Standard(标准提示):删除ReAct轨迹中的所有思想、行动、观察等步骤。
  • CoT(思想链提示):删除行动和观察,保留思想,并作为仅用于推理的基线。
  • CoT-SC(self-consistency):利用自一致性[1]方法,在推理期间抽样21个CoT轨迹,解码温度为0.7,并采用大多数投票得到答案。
  • Act:仅仅保留Agent提示(Act),它删除了ReAct轨迹中的Thought思维过程,可以初步认为其类似于WebGPT。
  • ReAct:本文的Thought + Action结合的方法。
  • ReAct → CoT-SC:当ReAct未能在给定步骤内返回答案时,返回CoT-SC结果。
  • CoT-SC → ReAct:当n个CoT-SC样本中的大多数答案少于n/2次(即内部知识可能无法自信地支持任务)时,返回ReAct结果。
  • 微调 (Finetuning)
    • 使用3000个由ReAct生成的正确答案轨迹来微调较小的语言模型。‘’

Langchain 中实现的Prompt

PREFIX = """Answer the following questions as best you can. You have access to the following tools:""" FORMAT_INSTRUCTIONS = """Use the following format: 
shell
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 [{tool_names}] 
Action Input: the input to the action 
Observation: the result of the action 
... (this Thought/Action/Action Input/Observation can repeat N times) 
Thought: I now know the final answer 
Final Answer: the final answer to the original input question""" 
SUFFIX = """Begin!Question: {input} 
Thought:{agent_scratchpad}"""

示例

from langchain.agents import initialize_agent
from langchain.llms import OpenAI
from langchain.tools import BaseTool# 搜索工具
class SearchTool(BaseTool):name = "Search"description = "如果我想知道天气,'鸡你太美'这两个问题时,请使用它"return_direct = True  # 直接返回结果def _run(self, query: str) -> str:print("\nSearchTool query: " + query)return "这个是一个通用的返回"async def _arun(self, query: str) -> str:raise NotImplementedError("暂时不支持异步")# 计算工具
class CalculatorTool(BaseTool):name = "Calculator"description = "如果是关于数学计算的问题,请使用它"def _run(self, query: str) -> str:print("\nCalculatorTool query: " + query)return "100"async def _arun(self, query: str) -> str:raise NotImplementedError("暂时不支持异步")llm = OpenAI(temperature=0.5)
tools = [SearchTool(), CalculatorTool()]
agent = initialize_agent(tools, llm, agent="zero-shot-react-description", verbose=True)print("问题:")
print("答案:" + agent.run("查询这周天气"))
print("问题:")
print("答案:" + agent.run("告诉我'鸡你太美'是什么意思"))
print("问题:")
print("答案:" + agent.run("告诉我'hello world'是什么意思"))
print("问题:")
print("答案:" + agent.run("告诉我10的3次方是多少?"))

相关文章:

  • CentOS:企业级Linux的社区力量与未来演进
  • aws instance store 的恢复
  • lesson04-简单回归案例实战(理论+代码)
  • AWS WebRTC:获取ICE服务地址(part 2): ICE Agent的作用
  • MySQL JSON数据存储结构与操作
  • 【深度学习】11. Transformer解析: Self-Attention、ELMo、Bert、GPT
  • jenkins集成gitlab实现自动构建
  • Redis--基础知识点--28--慢查询相关
  • 腾讯云国际站性能调优
  • WPF 全局加载界面、多界面实现渐变过渡效果
  • 浅谈JMeter之常见问题Address already in use: connect
  • Hadoop MapReduce:大数据处理利器
  • springboot配置cors拦截器与cors解释
  • 【东枫科技】KrakenSDR 测向快速入门指南
  • CSS 样式表的四种应用方式及css注释的应用小结
  • 板凳-------Mysql cookbook学习 (八--2)
  • Oracle OCP认证的技术定位怎么样?
  • Redis Stack常见拓展
  • 2024长春全国邀请赛CCPC
  • 【Oracle】DCL语言
  • 晨光科技+网站建设/app拉新平台有哪些
  • 网站建设的开发的主要方法/线上培训课程
  • 全球外贸b2b网站大全/北京seo培训
  • 网站备案 企业备案/色盲能治好吗
  • 如何兼职做网站/江西百度推广公司
  • 用cms建网站/关键词seo排名优化如何