naem1023 / ReWOO

Decoupling Reasoning from Observations for Efficient Augmented Language Models

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ReWOO ๐Ÿฆ™

Gentopia ๐Ÿฆ™๐ŸŒŽ| Live Demo | Paper | Twitter

โš ๏ธ Beaking News The official (and better) implementation of ReWOO has been integrated into Gentopia. Check below how ReWOO helps an agent called elon to half the execution time from ReAct.

1690553790051228.mp4

Original implementation for paper: ReWOO: Decoupling Reasoning from Observations for Efficient Augmented Language Models. This is a tool-augmented LM paradigm, leveraging foreseeable reasoning ability of language models to improve system parameter and prompt efficiency.

Abstract ๐Ÿค—

Augmented Language Models (ALMs) blend the reasoning capabilities of Large Language Models (LLMs) ๐Ÿค– with tools ๐Ÿ› ๏ธ that allow for knowledge retrieval and action execution.

Current ALM systems, such as ReAct, Reflexion, Auto-GPT and implemented agent types in Langchain trigger LLM thought processes while pulling observations from these tools in an interleaved fashion. Specifically, an LLM reasons to call an external tool, gets halted to fetch the toolโ€™s response, and then decides the next action based on all preceding response tokens. Such a paradigm, though straightforward and easy to implement, often leads to huge computation complexity from redundant prompts and repeated execution. ๐Ÿ˜ฎโ€๐Ÿ’จ

This study addresses such challenges for the first time, proposing a modular paradigm ReWOO (Reasoning WithOut Observation) that detaches the reasoning process from external observations, thus significantly reducing token consumption. ๐Ÿš€

Comprehensive evaluations across six public NLP benchmarks and a curated dataset reveal consistent performance enhancements with our proposed methodology. Notably, ReWOO achieves 5ร— token efficiency and 4% accuracy improvement on HotpotQA, a multi-step reasoning benchmark.

Furthermore, ReWOO demonstrates robustness under tool-failure scenarios. Beyond prompt efficiency, decoupling parametric modules from nonparametric tool calls enables instruction fine-tuning to offload LLMs into smaller language models, thus substantially reducing model parameters. Our illustrative work offloads reasoning ability from 175B GPT3.5 into 7B LLaMA, demonstrating the significant potential for truly efficient and scalable ALM systems. ๐Ÿฆ™

Installation ๐Ÿ”ง

pip install -r requirements.txt

Generate API keys from OpenAI, WolframAlpha and SerpApi. Then save the keys to ./keys/openai.key, ./keys/wolfram.key and ./keys/serpapi.key respectively.

Single Run ๐Ÿ„

 python run.py --method rewoo --toolset Google LLM --base_lm text-davinci-003 

Use --method to choose your prompt paradigm among 'direct', 'cot', 'react', 'rewoo'

Use --toolset to provide available tools, including 'Google', 'Wikipedia', 'WolframAlpha', 'LLM', 'Calculator', 'SearchSOTU'

Use --base_lm to choose a base language model, can be either gpt-3.5-turbo, text-davinci-003, gpt-4 or path_to_alpca-lora_adapter. You can also individually assign --planner_lm and --solver_lm for rewoo.

Add --print_trajectory to print intermediate reasoning.

Batch Evaluation on Benchmarks ๐Ÿ„ ๐Ÿ„

python run_eval.py --method rewoo --dataset hotpot_qa --sample_size 10 --toolset Wikipedia LLM --base_lm gpt-3.5-turbo --save_result`

Use --dataset to assign benchmark tasks, this can be 'hotpot_qa', 'trivia_qa', 'gsm8k', 'physics_question', 'sports_understanding', 'strategy_qa', 'sotu_qa'

Use --sample_size to specify number of samples to evaluate.

Use --save_result to save evaluation results to ./results/.

Data & Model ๐Ÿ‘‡

Except public NLP benchmarks, we also evaluate ReWOO on a curated QA dataset over SOTU2023 here. It is especially useful for ALMs to examine the model's tool-augmented ability in answering over private document.

We uploaded our instruction-tuned Planner 7B model (based on Alpaca 7B) here. The instruction dataset (available here) is a mixture of "correct" HotpotQA and TriviaQA task planning trajectories in ReWOO Framework.

Run Gradio App Locally ๐Ÿ’ป

python app.py

(Make sure your openai and serpapi keys are stored under ./keys/ as mentioned in Installation ๐Ÿ‘†)

Citation

@article{xu2023rewoo,
  title={ReWOO: Decoupling Reasoning from Observations for Efficient Augmented Language Models},
  author={Xu, Binfeng and Peng, Zhiyuan and Lei, Bowen and Mukherjee, Subhabrata and Liu, Yuchen and Xu, Dongkuan},
  journal={arXiv preprint arXiv:2305.18323},
  year={2023}
}

About

Decoupling Reasoning from Observations for Efficient Augmented Language Models

License:MIT License


Languages

Language:Python 100.0%