2.6 KiB
2.6 KiB
Majority Vote Reasoning
This project demonstrates a majority vote implementation that enables LLMs to solve complex reasoning problems by aggregating multiple independent attempts. It's designed to improve problem-solving accuracy through consensus-based reasoning.
Features
- Improves model reliability on complex problems through multiple attempts
- Works with models like Claude 3.7 Sonnet
- Solves problems that single attempts often fail on
- Provides detailed reasoning traces for verification
- Uses a consensus approach to reduce the impact of occasional reasoning errors
Getting Started
- Install the required packages:
pip install -r requirements.txt
- Set up your API key:
export ANTHROPIC_API_KEY="your-api-key-here"
- Run a test problem to see majority voting in action:
python main.py
- Try your own reasoning problem:
python main.py --problem "Your complex reasoning problem here" --tries 5
How It Works
The implementation uses a MajorityVoteNode that processes multiple attempts and finds consensus:
flowchart LR
mv[MajorityVoteNode]
The MajorityVoteNode:
- Makes multiple independent attempts to solve the same problem
- Collects structured answers from each attempt
- Determines the most frequent answer as the final solution
- Returns the consensus answer
This approach helps overcome occasional reasoning errors that might occur in individual attempts.
Example Problem
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 the majority vote approach uses Claude 3.7 Sonnet to solve this complex problem:
========================
All structured answers: ['0.333', '0.333', '0.333', '0.6', '0.333']
Majority vote => 0.333
Frequency => 4
========================
=== Final Answer ===
0.333
====================
This shows that 4 out of 5 attempts yielded the same answer (0.333), which is chosen as the final solution.