Tree of Thoughts, create a path tree

The Tree of Thoughts ToT prompting technique in LLM is a method advanced prompting that uses a structured approach to guide LLMs through their reasoning and response generation processes. It enhances problem solving by exploring multiple paths of reasoning, called “thoughts.” Unlike traditional linear prompts, ToT allows LLMs to consider a variety of possible solutions and strategies, including projecting into the future, backtracking, and self-assessment, making it more interactive and adaptable to the complexity of the task at hand.

Tree of Toughts

Exploring the paths

Each thought represents a coherent sequence of language that evolves toward the final solution. This structure allows language models to reason deliberately by evaluating the progress that thoughts generate in solving the problem. ToT integrates the model's capabilities to generate and evaluate thoughts with algorithms for research such as breadth-first or depth-first search.

This allows for systematic exploration of reasoning chains, with anticipation to expand promising directions and backtracking when solutions are incorrect. ToT excelled in the 24-game tasks, achieving a success rate of 74 %s versus 4 %s for CoT. Furthermore, in word-level tasks, ToT outperformed CoT with a success rate of 60 %s versus 16 %s.

tree of toughts

Example

The example below illustrates the structure of the prompt.

It is important to know that GPT-3.5 does not get the correct answer for the example below with the Chain of Thought prompt, but it does with the ToT prompt (built into GPT-4).

The prompt is:

Imagine three different experts are answering this question. All experts will write down 1 step of their thinking, then share it with the group. Then all experts will go on to the next step, etc. If any expert realizes they're wrong at any point then they leave. The question is...

Which gives:

Expert 1: The ball is in the living room. Expert 2: The ball is in the kitchen. Expert 3: The ball is in the bedroom. Expert 1: Bob carries the cup to the bedroom, so the ball must be in the cup. Expert 2: Oh, I see my mistake. Yes, the ball is in the cup. Expert 3: Agreed, the ball is in the cup in the bedroom. Expert 1: Next, Bob turns the cup upside down in the bedroom. Expert 2: After that, Bob walks to the garden and puts the cup down. Expert 3: Therefore, the ball must have fallen out of the cup when Bob turned it upside down in the bedroom. So, the ball is in the bedroom, not in the cup anymore. Expert 1: Oh, you're right. I made a mistake. The ball is in the bedroom, not in the cup. Expert 2: Agreed, the ball is in the bedroom. Expert 3: Bob then walks to the garage, so the ball remains in the bedroom. It is not in the garden or the garage. Expert 1: Absolutely, the ball is still in the bedroom. Expert 2: Yes, the ball hasn't moved from the bedroom. Expert 3: Therefore, the ball is in the bedroom, not in the garden or the garage.
All three experts agree that the ball is in the bedroom.
en_USEN