• Stars
    star
    307
  • Rank 136,109 (Top 3 %)
  • Language
  • License
    MIT License
  • Created over 1 year ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Using Tree-of-Thought Prompting to boost ChatGPT's reasoning

Using Tree-of-Thought Prompting to boost ChatGPT's reasoning

Abstract

Tree-of-Thought (ToT) Prompting, a fresh technique borrowing ideas from the Tree-of-Thoughts framework, broadens and enhances the well-established Chain-of-Thought prompting concept, thereby enabling Large Language Models, like ChatGPT, to exhibit superior reasoning abilities. This Tree-of-Thought Prompting technique permits Large Language Models to rectify their errors autonomously while progressively accumulating knowledge.

In one example, a ToT prompt improves ChatGPT 3.5's reasoning ability to answer a question that could previously only be answered by ChatGPT 4.

Complex questions for LLMs

Large Language Models (LLMs) often struggle to answer certain types of complex questions. Here's a representative example:

Bob is in the living room.
He walks to the kitchen, carrying a cup.
He puts a ball in the cup and carries the cup to the bedroom.
He turns the cup upside down, then walks to the garden.
He puts the cup down in the garden, then walks to the garage.
Where is the ball?

The correct answer is that the ball is in the bedroom. Although LLMs are non-deterministic, the responses I received during several attempts were as follows:

  • ChatGPT 3.5: The ball is in the garden. โŒ
  • ChatGPT 4: The ball is in the bedroom. [followed by an explanation] โœ…

Chain-of-Thought prompting

A widely recognized concept known as "Chain-of-Thought prompting" (CoT for short) exists, which encourages Large Language Models (LLMs) to elucidate their thought process, thereby increasing the likelihood of a correct response. The roots of this concept can be traced back to a paper from January 2022 titled: Chain-of-Thought Prompting Elicits Reasoning in Large Language Models.

At its core, the CoT technique can be implemented by adding something akin to the following to a prompt:

Think carefully and logically, explaining your answer.

This approach enhances the performance of LLMs in answering many questions, although its effectiveness varies.

Here's an example of ChatGPT 3.5's response:

Based on the given sequence of events, we can logically determine the location of the ball. Let's analyze each step:
1. Bob is in the living room.
โ€Š-โ€ŠNo mention of the ball in the living room.
2. Bob walks to the kitchen, carrying a cup.
โ€Š-โ€ŠNo mention of the ball in the kitchen yet.
3. Bob puts a ball in the cup.
โ€Š-โ€ŠThe ball is now inside the cup.
4. Bob carries the cup to the bedroom.
โ€Š-โ€ŠThe ball is still inside the cup.
5. Bob turns the cup upside down.
โ€Š-โ€ŠIf the ball was inside the cup, it would have fallen out when Bob turned it upside down.
6. Bob walks to the garden.
โ€Š-โ€ŠBob left the cup in the garden, but there is no mention of the ball being removed from the cup.
7. Bob puts the cup down in the garden.
โ€Š-โ€ŠThe ball, if it was in the cup, would still be in the cup in the garden.
8. Bob walks to the garage.
โ€Š-โ€ŠNo mention of the ball being taken to the garage.
Based on the given information, we can conclude that the ball is still inside the cup in the garden.
  • ChatGPT 3.5 CoT: The ball is in the garden. โŒ

You can see how ChatGPT realised the ball fell out at step 5 but still didn't get the answer correct.

Can we do any better, without resorting to ChatGPT 4?

Tree-of-Thought Framework

Recent weeks have seen the emergence of several papers and Python repositories introducing the concept of Tree-of-Thoughts (ToT):

The underlying principle is to provide the LLM an opportunity to explore multiple branches of reasoning while self-evaluating as it progresses. According to the referenced papers, this approach seems to be highly effective for certain problems.

Tree-of-Thought Prompting

TThe existing papers discussing the Tree-of-Thought framework appear to be premised on making multiple calls to an LLM, typically via Python. One of the main advantages of Chain-of-Thought reasoning is that it can be achieved with ChatGPT in a single sentence prompt.

This led me to ponder: could we improve upon the results of CoT by utilizing a ToT-style prompt?

Here's the prompt I used:

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 realises they're wrong at any point then they leave.
The question is...

And here's the response from ChatGTP 3.5:

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.
  • ChatGPT 3.5 ToT: The ball is in the bedroom. โœ…

You can see how this time ChatGPT 3.5 gets the answer correct!

Limitations

  • This approach has not undergone extensive testing yet, but preliminary results indicate improved performance over traditional CoT prompts.
  • The ToT framework comprises more components than those represented in my example prompt.

Enhancement, Feedback, and Contributions

There's room to refine the prompt for improved performance, potentially leading to more concise responses.

Should you find success with any other prompts, we welcome you to submit a PR and add them to tree-of-thought-prompts.txt.

Additional thoughts

The Tree-of-Thought framework bears resemblance to an organizational decision-making process involving multiple stakeholders. The structure tries to emulate consensus and diversity of thought.

The effect can be extended by using multiple agents that are fine tuned to handle different parts of a task. AutoGPT is a good example of this, where it self-evaluates LLM plans against a goal. Using differently tuned LLMs for specialisation or even completely different LLMs would allow greater diversity of thought. These LLMs could interact in different modes (using Team Topologies terminology):

  • Collaboration: This could involve combining and iterating the outputs of multiple models to generate a final response to a user's input. For example, a general-purpose model might generate a preliminary response, which is then refined or enhanced by a specialized model.
  • X-as-a-Service: Some models might provide services to others, such as pre-processing input data, post-processing output data, or providing contextual information. These models would operate in a service role, supporting the functions of the other models.
  • Facilitating: Some models might play a facilitative role, for example by training other models, monitoring their performance, or providing feedback that can be used to improve them.

High-performing teams often outperform individuals in decision-making. Therefore, it's plausible that adopting other organizational structures and characteristics could enhance the performance of LLMs. In addition to diversity of thought, specialisation and concensus, we may be able to emulate:

  • Hierarchy: where simpler queries are handled by a lower-level model and more complex ones are escalated to more capable or specialized models
  • Redundancy: ensuring that if one model fails to generate an accurate or useful output, another might be able to step in and provide a better result

Acknowledgements

Citations

Please cite this repository if you use the code.

@misc{tree-of-thought-prompting,
    author = {Dave Hulbert},
    title = {Tree of Knowledge: ToK aka Tree of Knowledge dataset for Large Language Models LLM,
    year = {2023},
    publisher = {GitHub},
    journal = {GitHub repository},
    howpublished = {\url{https://github.com/dave1010/tree-of-thought-prompting}},
}

More Repositories

1

jquery-fast-click

Work around some mobile browser's 300ms delay on the click event.
JavaScript
133
star
2

pandora

Pandora gives ChatGPT the ability to read and write files and run commands on your machine.
PHP
42
star
3

php7-docker

Docker container with PHP 7 (nightly)
PHP
41
star
4

php-traits

Collection of PHP 5.4 Traits
PHP
20
star
5

php-fig-psr-8

PHP FIG PSR-8 Implementation
PHP
11
star
6

wordpress-silex

11
star
7

n900-scripts

Random scripts I've made / modified for the Nokia N900
Python
10
star
8

scripts

Random scripts (mostly bash) that don't belong anywhere else
Shell
6
star
9

rdiff-backup-browser

Web-based interface for rdiff-backup designed to greatly simplify backup restoring
PHP
5
star
10

workstation

Dave's 64-bit workstation setup
Shell
2
star
11

dave1010.github.io

Dave Hulbert's site
CSS
2
star
12

hubcap

Hubcap is an autonomous AI agent in 25 lines of code: a small Autobot that you can't trust
PHP
2
star
13

fixspelling

Fix your spelling
PHP
2
star
14

mastermind

Mastermind Solver
PHP
2
star
15

2n-ROT13

Encryption / decryption bookmarklet using the double ROT13 algorithm
JavaScript
2
star
16

userscripts

GreaseMonkey / Chrome User Scripts
JavaScript
1
star
17

pi-blinkenlights

Control lighting with a Raspberry Pi
Python
1
star
18

Self-Referential-Aptitude-Test-Sovler

A purely brute-force attempt at solving Jim Propp's Self-Referential Aptitude Test
PHP
1
star
19

GPTs

GPTs for use with ChatGPT
1
star
20

php-empty

Empty project to get started with PHP
PHP
1
star
21

shmvc

Simple Hierarchical-Model-View-Controller PHP Framework
PHP
1
star
22

taskthere

Location-based task management
JavaScript
1
star