pocketflow/cookbook/pocketflow-majority-vote
zachary62 e303c3ad9b init add to majority vote 2025-03-31 19:43:32 -04:00
..
README.md init add to majority vote 2025-03-31 19:43:32 -04:00
main.py init add to majority vote 2025-03-31 19:43:32 -04:00
requirements.txt init add to majority vote 2025-03-31 19:43:32 -04:00
utils.py init add to majority vote 2025-03-31 19:43:32 -04:00

README.md

Extended Thinking

This project demonstrates an extended thinking mode implementation that enables LLMs to solve complex reasoning problems by thinking step-by-step. It's designed to improve problem-solving accuracy through deliberate reasoning.

Features

  • Improves model reasoning on complex problems
  • Works with models like Claude 3.7 Sonnet that support extended thinking
  • Solves problems that direct prompting often fails on
  • Provides detailed reasoning traces for verification

Getting Started

  1. Install the required packages:
pip install -r requirements.txt
  1. Set up your API key:
export ANTHROPIC_API_KEY="your-api-key-here"
  1. Run a test problem to see thinking mode in action:
python main.py
  1. Try your own reasoning problem:
python main.py --"Your complex reasoning problem here"

How It Works

The implementation uses a self-looping Chain of Thought node that allows an LLM to think through complex problems step by step:

flowchart LR
    cot[ChainOfThoughtNode] -->|"continue"| cot

Each time the node loops, it:

  1. Reads the problem and previous thoughts
  2. Generates the next thought or final solution
  3. Decides whether more thinking is needed

This approach helps LLMs solve problems that would be difficult with a single-pass approach.

Example Thinking Process

Example Problem from Quant Interview:

You work at a shoe factory. In front of you, there are three pairs of shoes (six individual shoes) with the following sizes: two size 4s, two size 5s, and two size 6s. The factory defines an "acceptable pair" as two shoes that differ in size by a maximum of one size (e.g., a size 5 and a size 6 would be an acceptable pair). If you close your eyes and randomly pick three pairs of shoes without replacement, what is the probability that you end up drawing three acceptable pairs?

Below is an example of how Claude 3.7 Sonnet to solve this complex problem, and get the correct result:

========================
All structured answers: ['0.333', '0.333', '0.333', '0.6', '0.333']
Majority vote => 0.333
Frequency => 4
========================

=== Final Answer ===
0.333
====================

Files

  • main.py: Implementation of the ...
  • utils.py: Simple wrapper for calling the Anthropic model