tree-of-thought-llm/readme.md

92 lines
4.7 KiB
Markdown
Raw Normal View History

2023-05-31 19:31:50 +00:00
# Official Repo of Tree of Thoughts (ToT)
[![DOI](https://zenodo.org/badge/642099326.svg)](https://zenodo.org/badge/latestdoi/642099326)
2023-05-25 15:26:04 +00:00
2023-07-04 01:51:09 +00:00
<details>
2023-07-04 02:29:31 +00:00
<summary>Note: https://github.com/kyegomez/tree-of-thoughts CANNOT replicate paper results. </summary>
2023-07-04 02:16:03 +00:00
In fact, people have reported that his code [cannot](https://github.com/kyegomez/tree-of-thoughts/issues/52) [properly](https://github.com/kyegomez/tree-of-thoughts/issues/41) [run](https://github.com/kyegomez/tree-of-thoughts/issues/60), and is [probably automatically generated by ChatGPT](pics/fake.png), and [kyegomez has done so for other popular ML methods](https://twitter.com/qbitium/status/1663954096741814272), while intentionally refusing to link to official implementations for his own interests (see https://github.com/kyegomez/tree-of-thoughts/issues/54, https://github.com/kyegomez/tree-of-thoughts/issues/55, https://github.com/kyegomez/tree-of-thoughts/issues/56).
2023-06-09 13:50:46 +00:00
Unfortunately, Google/Github searches go to kyegomez's malicious repo by default as it has more stars. **Please DE-STAR his repo and STAR this to help other people avoid being misled, thanks!**
2023-07-04 01:51:09 +00:00
</details>
2023-07-04 02:16:03 +00:00
![teaser](pics/teaser.png)
2023-05-31 19:31:50 +00:00
Official implementation for paper [Tree of Thoughts: Deliberate Problem Solving with Large Language Models](https://arxiv.org/abs/2305.10601) with code, prompts, model outputs.
2023-05-23 22:34:41 +00:00
Also check [its tweet thread](https://twitter.com/ShunyuYao12/status/1659357547474681857) in 1min.
2023-05-31 19:03:38 +00:00
2023-05-23 22:34:41 +00:00
2023-05-31 19:31:50 +00:00
2023-05-23 22:34:41 +00:00
## Setup
2023-07-04 02:29:31 +00:00
- Set up OpenAI API key and store in environment variable ``OPENAI_API_KEY`` (see [here](https://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety)).
- Install dependencies and `tot` package:
```bash
pip install -r requirements.txt
pip install -e . # install `tot` package
```
2023-05-23 22:34:41 +00:00
2023-05-24 15:59:18 +00:00
2023-07-04 02:29:31 +00:00
## Quick Start
The following minimal script will attempt to solve the game of 24 with `4 5 6 10`:
```python
import argparse
from tot.methods.bfs import solve
from tot.tasks.game24 import Game24Task
2023-05-23 22:34:41 +00:00
2023-07-04 02:29:31 +00:00
args = argparse.Namespace(backend='gpt-4', temperature=0.7, task='game24', naive_run=False, prompt_sample=None, method_generate='propose', method_evaluate='value', method_select='greedy', n_generate_sample=1, n_evaluate_sample=3, n_select_sample=5)
task = Game24Task()
2023-07-04 02:39:33 +00:00
ys, infos = solve(args, task, 900)
print(ys[0])
2023-07-04 02:29:31 +00:00
```
2023-07-04 02:39:33 +00:00
And the output would be something like (note it's not deterministic, and sometimes the output can be wrong):
```
10 - 4 = 6 (left: 5 6 6)
5 * 6 = 30 (left: 6 30)
30 - 6 = 24 (left: 24)
Answer: (5 * (10 - 4)) - 6 = 24
```
2023-07-04 02:29:31 +00:00
## Paper Experiments
2023-05-23 22:34:41 +00:00
Run experiments via ``sh scripts/{game24, text, crosswords}/{standard_sampling, cot_sampling, bfs}.sh``, except in crosswords we use a DFS algorithm for ToT, which can be run via ``scripts/crosswords/search_crosswords-dfs.ipynb``.
The very simple ``run.py`` implements the ToT + BFS algorithm, as well as the naive IO/CoT sampling. Some key arguments:
- ``--naive_run``: if True, run naive IO/CoT sampling instead of ToT + BFS.
- ``--prompt_sample`` (choices=[``standard``, ``cot``]): sampling prompt
- ``--method_generate`` (choices=[``sample``, ``propose``]): thought generator, whether to sample independent thoughts (used in Creative Writing) or propose sequential thoughts (used in Game of 24)
- ``--method_evaluate`` (choices=[``value``, ``vote``]): state evaluator, whether to use the value states independently (used in Game of 24) or vote on states together (used in Creative Writing)
- ``--n_generate_sample``: number of times to prompt for thought generation
- ``--n_evaluate_sample``: number of times to prompt for state evaluation
- ``--n_select_sample``: number of states to keep from each step (i.e. ``b`` in the paper's ToT + BFS algorithm)
2023-07-04 02:29:31 +00:00
## Paper Trajectories
2023-05-27 19:35:17 +00:00
``logs/`` contains all the trajectories from the paper's experiments, except for ``logs/game24/gpt-4_0.7_propose1_value3_greedy5_start900_end1000.json`` which was reproduced after the paper (as the original experiment was done in a notebook) and achieved a 69\% score instead of the original 74\% score due to randomness in GPT decoding. We hope to aggregate multiple runs in the future to account for sampling randomness and update the paper, but this shouldn't affect the main conclusions of the paper.
2023-05-23 22:34:41 +00:00
2023-07-04 02:29:31 +00:00
## How to Add New Tasks/Methods
TBA.
2023-05-23 22:34:41 +00:00
2023-07-04 02:29:31 +00:00
## Citations
Please cite the paper and star this repo if you use ToT and find it interesting/useful, thanks! Feel free to contact shunyuyao.cs@gmail.com or open an issue if you have any questions.
2023-05-31 15:48:52 +00:00
2023-07-04 02:29:31 +00:00
```bibtex
@misc{yao2023tree,
title={{Tree of Thoughts}: Deliberate Problem Solving with Large Language Models},
author={Shunyu Yao and Dian Yu and Jeffrey Zhao and Izhak Shafran and Thomas L. Griffiths and Yuan Cao and Karthik Narasimhan},
year={2023},
eprint={2305.10601},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
```