finishi batch tutorial
This commit is contained in:
parent
11f808ee8d
commit
748d37fc7b
|
|
@ -1,14 +1,11 @@
|
||||||
# Majority Vote Reasoning
|
# Batch Translation Process
|
||||||
|
|
||||||
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.
|
This project demonstrates a batch processing implementation that enables LLMs to translate documents into multiple languages simultaneously. It's designed to efficiently handle the translation of markdown files while preserving formatting.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- Improves model reliability on complex problems through multiple attempts
|
- Translates markdown content into multiple languages in parallel
|
||||||
- Works with models like Claude 3.7 Sonnet
|
- Saves translated files to specified output directory
|
||||||
- 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
|
## Getting Started
|
||||||
|
|
||||||
|
|
@ -22,35 +19,34 @@ pip install -r requirements.txt
|
||||||
export ANTHROPIC_API_KEY="your-api-key-here"
|
export ANTHROPIC_API_KEY="your-api-key-here"
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Run a test problem to see majority voting in action:
|
3. Run the translation process:
|
||||||
```bash
|
```bash
|
||||||
python main.py
|
python main.py
|
||||||
```
|
```
|
||||||
|
|
||||||
## How It Works
|
## How It Works
|
||||||
|
|
||||||
The implementation uses a MajorityVoteNode that processes multiple attempts and finds consensus:
|
The implementation uses a `TranslateTextNode` that processes batches of translation requests:
|
||||||
|
|
||||||
```mermaid
|
```mermaid
|
||||||
flowchart LR
|
flowchart LR
|
||||||
mv[MajorityVoteNode]
|
batch[TranslateTextNode]
|
||||||
```
|
```
|
||||||
|
|
||||||
The MajorityVoteNode:
|
The `TranslateTextNode`:
|
||||||
1. Makes multiple independent attempts to solve the same problem
|
1. Prepares batches for multiple language translations
|
||||||
2. Collects structured answers from each attempt
|
2. Executes translations in parallel using the model
|
||||||
3. Determines the most frequent answer as the final solution
|
3. Saves the translated content to individual files
|
||||||
4. Returns the consensus answer
|
4. Maintains the original markdown structure
|
||||||
|
|
||||||
This approach helps overcome occasional reasoning errors that might occur in individual attempts.
|
This approach demonstrates how PocketFlow can efficiently process multiple related tasks in parallel.
|
||||||
|
|
||||||
## Example Output
|
## Example Output
|
||||||
|
|
||||||
Below is an example of how the majority vote approach uses Claude 3.7 Sonnet to solve this complex problem:
|
When you run the translation process, you'll see output similar to this:
|
||||||
|
|
||||||
```
|
```
|
||||||
Translated Chinese text
|
Translated Chinese text
|
||||||
|
|
||||||
Translated Spanish text
|
Translated Spanish text
|
||||||
Translated Japanese text
|
Translated Japanese text
|
||||||
Translated German text
|
Translated German text
|
||||||
|
|
@ -72,9 +68,10 @@ Translations saved to: translations
|
||||||
============================
|
============================
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Files
|
## Files
|
||||||
|
|
||||||
- [`main.py`](./main.py): Implementation of the majority vote node and flow
|
- [`main.py`](./main.py): Implementation of the batch translation node
|
||||||
- [`utils.py`](./utils.py): Simple wrapper for calling the Anthropic model
|
- [`utils.py`](./utils.py): Simple wrapper for calling the Anthropic model
|
||||||
|
- [`requirements.txt`](./requirements.txt): Project dependencies
|
||||||
|
|
||||||
|
The translations are saved to the `translations` directory, with each file named according to the target language.
|
||||||
Loading…
Reference in New Issue