Login Sign Up

Chain-of-Thought (CoT), Self- Consistency and Tree of Thought (ToT) Prompting

Chain of Thought Prompting

Chain of Thought Prompting
Chain of Thought Prompting

Chain-of-Thought (CoT) prompting is a technique that enhances an AI’s ability to reason through problems by guiding it to break down its response into a logical sequence of steps. Rather than just providing an answer, CoT ensures that the AI explains its thought process, making its reasoning clearer and more reliable.

Example Without CoT Prompting

Prompt:
“What is 234 × 56?”

AI Response:
“13,104.”

Example With CoT Prompting

Prompt:
“Solve 234 × 56 step by step.”

AI Response:
1.Break it down: 234 × 50 = 11,700
2.Break it down: 234 × 6 = 1,404
3.Final sum: 11,700 + 1,404 = 13,104

Using CoT for Better Reasoning

This approach is particularly effective in tasks that require structured decision-making:

  • Mathematical Reasoning:
    “Explain how to solve a quadratic equation step by step.”
  • Logical Deduction:
    “If John is taller than Mike and Mike is taller than Sarah, who is the shortest?”
  • Debugging Code:
    “Analyze why this Python script isn’t working and suggest a fix.”

Why CoT Works

  • Encourages structured reasoning, making answers more transparent.
  • Reduces AI hallucinations by enforcing a logical approach.
  • Improves multi-step problem-solving, making responses more accurate and useful.

By shifting AI from generating simple responses to breaking problems into logical sequences, CoT prompting makes it significantly more effective for handling complex queries.

Tree of Thought (ToT) Prompting

Tree of Thought (ToT) Prompting is an advanced technique designed to enhance the reasoning capabilities of large language models (LLMs). This method generalizes Chain-of-Thought (CoT) prompting, introducing structured, multi-step exploration to improve problem-solving in complex tasks.

How Tree of Thought Works

Tree of Thought
Tree of Thought

ToT operates by maintaining a tree-like structure, where each thought (or step) represents an intermediate step towards solving a problem. The model evaluates each thought systematically, pruning incorrect or unhelpful paths while refining promising ones.

A key feature of ToT is its ability to incorporate search-based strategies:

  • Breadth-First Search (BFS): Explores multiple thought paths in parallel before progressing deeper.
  • Depth-First Search (DFS): Dives deeper into a single thought path before backtracking if necessary.
  • Beam Search: Maintains a fixed number of best candidates at each step to balance depth and breadth.

 

Example: Game of 24 Using ToT

Let’s consider a mathematical reasoning task:

Given four numbers, generate an expression that evaluates to 24.

1. Standard Approach (Fails on Complex Cases)

A simple LLM prompt might look like:

Given the numbers [8, 3, 3, 1], generate an expression that evaluates to 24.

However, the model may not always find the correct answer.

2. ToT-Based Approach (More Accurate)

With ToT prompting, we:

  • Break down the problem into 3 steps.
  • Generate 5 candidate expressions at each step.
  • Use BFS to evaluate and refine them.

ToT Prompt Example:

Let’s solve the problem step by step using a Tree of Thought approach.

  1. Generate 5 possible intermediate expressions using the given numbers.
  2. Evaluate each candidate: “sure,” “maybe,” or “impossible.”
  3. Keep the best candidates and continue.

Numbers: [8, 3, 3, 1]

  • Step 1: Generate 5 possible expressions.
  • Step 2: Evaluate them.
  • Step 3: Continue with the best ones.

Key Benefits of ToT Prompting

  • Improves complex problem-solving through structured reasoning.
  • Enhances accuracy by evaluating multiple intermediate steps.
  • Supports dynamic exploration with search-based techniques.
  • Adapts to new tasks through reinforcement learning (RL-based ToT).

Self-Consistency Prompting

Self-consistency is an advanced prompting technique designed to improve the accuracy and reliability of Large Language Models (LLMs). It enhances Chain-of-Thought (COT) prompting by generating multiple reasoning paths and selecting the most consistent answer. Instead of following a single logical path, self-consistency encourages the model to explore diverse approaches and use majority voting to identify the most reliable response.

Self-consistency Prompting
Self-consistency Prompting

How to Use Self-Consistency Prompting

To apply self-consistency prompting, follow these steps:

  1. Define the Problem: Clearly state the question or task.
  2. Create Diverse Prompts: Approach the problem from multiple angles to encourage varied reasoning paths.
  3. Generate Multiple Responses: Submit the prompts and gather multiple outputs from the model.
  4. Evaluate Consistency: Analyze the responses, looking for logical coherence and recurring correct answers.
  5. Select the Best Answer: Use majority voting or pattern recognition to determine the most consistent response.

Example: Improving Arithmetic Accuracy

Incorrect Example (Greedy Decoding Approach)

Q: When I was 6, my sister was half my age. Now I’m 70, how old is my sister?

Model Output: 73 (Incorrect)

Correcting This with Self-Consistency

Instead of relying on a single output, we provide multiple examples of logical reasoning paths to guide the AI toward consistency.

Combining Self-Consistency and COT

By generating multiple reasoning paths and selecting the most consistent one, we further refine the accuracy.

Q: Michael had 58 golf balls. On Tuesday, he lost 23. On Wednesday, he lost 2 more. How many does he have now?  

Path 1:  

  • He started with **58** golf balls.
  • Lost 23 on Tuesday → 58 – 23 = 35
  • Lost 2 on Wednesday → 35 – 2 = 33
  • Final Answer: 33

 

Path 2:  

  • Michael had 58 golf balls.
  • Subtracting 23, then subtracting 2, leaves 33.
  • Final Answer: 33

 

Path 3:  

  • Start with 58 golf balls.
  • First loss: 23 balls → 35 left
  • Second loss: 2 balls → 33 left
  • Final Answer: 33