Tree of Thoughts (ToT): a framework for language model inference

The Tree of Thoughts paper introduces ToT, a language model inference framework that enables exploration over coherent units of text called thoughts.

Verified

On this page

Definition

The paper introduces Tree of Thoughts (ToT) as a new framework for language model inference that generalizes over the Chain of Thought approach to prompting language models and enables exploration over coherent units of text, called thoughts, that serve as intermediate steps toward problem solving. The paper says language models are increasingly deployed for general problem solving across a wide range of tasks, but are still confined to token-level, left-to-right decision-making processes during inference. According to the paper, ToT allows language models to perform deliberate decision making by considering multiple different reasoning paths and self-evaluating choices to decide the next course of action, as well as looking ahead or backtracking when necessary to make global choices.

The paper proposes the ToT framework for general problem solving with language models. In the paper's description, ToT actively maintains a tree of thoughts, where each thought is a coherent language sequence that serves as an intermediate step toward problem solving. The paper says such a unit allows the language model to self-evaluate the progress that different intermediate thoughts make toward solving the problem, through a deliberate reasoning process that is also instantiated in language.

The paper also combines this language-based capability to generate and evaluate diverse thoughts with search algorithms such as breadth-first search (BFS) or depth-first search (DFS), which allow systematic exploration of the tree of thoughts with lookahead and backtracking.

At a glance

The paper describes a specific instantiation of ToT as answering four questions: how to decompose the intermediate process into thought steps, how to generate potential thoughts from each state, how to heuristically evaluate states, and what search algorithm to use.

  • Each node in the tree is a state that represents a partial solution, made of the input and the sequence of thoughts so far.
  • The state evaluator judges the progress that states make toward solving the problem and serves as a heuristic for the search algorithm to determine which states to keep exploring and in which order.
  • BFS maintains a set of the b most promising states per step.
  • DFS backtracks to the parent state of a state to continue exploration.

The source does not state the order of these points, so they are listed without arrows.

How it works

The paper frames problems as a search over a tree in which each node is a state representing a partial solution, made of the input and the sequence of thoughts so far. On thought size, the paper says that depending on the problem, a thought could be a couple of words (Crosswords), a line of equation (Game of 24), or a whole paragraph of writing plan (Creative Writing). In general, the paper says a thought should be small enough for language models to generate promising and diverse samples, since generating a whole book is usually too big to be coherent, yet big enough for them to evaluate its prospect toward problem solving, since generating one token is usually too small to evaluate.

For generating candidates, one approach samples i.i.d. thoughts from a CoT prompt, which the paper uses for Creative Writing. According to the paper, this approach works better when the thought space is rich, for example when each thought is a paragraph, and i.i.d. samples lead to diversity. The paper shows proposing thoughts sequentially with a propose prompt on Game of 24 and Crosswords.

The paper says proposing thoughts sequentially works better when the thought space is more constrained, for example when each thought is just a word or a line, because proposing different thoughts in the same context avoids duplication. The state evaluator takes a frontier of different states, evaluates the progress they make toward solving the problem, and serves as a heuristic for the search algorithm to determine which states to keep exploring and in which order. A value prompt reasons about a state to generate a scalar value such as 1-10 or a classification such as sure/likely/impossible that could be heuristically turned into a value.

The paper explores evaluation via a few lookahead simulations, such as quickly confirming that 5, 5, 14 can reach 24 via 5 + 5 + 14, plus commonsense, such as 1 2 3 being too small to reach 24 or no word being able to start with tzxc. Such valuations, the paper says, do not need to be perfect; they only need to be approximately helpful for decision making. When problem success is harder to value directly, such as passage coherency, the paper says it is natural to compare different partial solutions and vote for the most promising one instead.

BFS maintains a set of the b most promising states per step. DFS explores the most promising state first until the final output is reached or the state evaluator deems it impossible to solve the problem from the current state. In the latter case, the paper says the subtree from that state is pruned to trade exploration for exploitation.

In both cases, DFS backtracks to the parent state to continue exploration.

Example

Game of 24 is a mathematical reasoning challenge in which the goal is to use 4 numbers and basic arithmetic operations (+-*/) to obtain 24. For the input 4 9 10 13, the paper gives (10 - 4) * (13 - 9) = 24 as a possible solution output. The paper counts an output as a success if it is a valid equation that equals 24 and uses the input numbers each exactly once.

The paper reports the success rate across 100 games as the metric. The paper says that to frame Game of 24 in ToT, it is natural to decompose the thoughts into 3 steps, each an intermediate equation. In the paper's task overview, the thoughts for the input 4 9 10 13 are 3 intermediate equations: 13-9=4 with 4,4,10 left, 10-4=6 with 4,6 left, and 4*6=24.

At each tree node, the paper extracts the remaining numbers and prompts the language model to propose some possible next steps. The paper performs a breadth-first search in ToT and keeps the best b=5 candidates at each step. To evaluate, the paper prompts the language model to evaluate each thought candidate as sure, maybe or impossible with regard to reaching 24.

The aim is to promote correct partial solutions that can be verdicted within a few lookahead trials, eliminate impossible partial solutions based on too big or too small commonsense, and keep the rest as maybe. The paper says the valuations used to evaluate states do not need to be perfect and only need to be approximately helpful for decision making. In the paper's Game of 24 results, IO, CoT, and CoT-SC prompting achieve only 7.3%, 4.0%, and 9.0% success rates.

In the same results, ToT with a breadth of b=1 already achieves a 45% success rate, while b=5 achieves 74%. The paper's abstract states that in Game of 24, GPT-4 with chain-of-thought prompting only solved 4% of tasks, while the paper's method achieved a success rate of 74%. The paper says running ToT requires significantly more computations than IO or CoT prompting.

The paper also says deliberate search such as ToT might not be necessary for many existing tasks that GPT-4 already excels at.

Sources

This page is written from the official sources below. Open them to check the original text.

Verified ·

This page is written by AI from the official sources above and checked automatically. This site has not tested it. Found a mistake? Tell us.