|
| 1 | +# 🚀 `buffdata` |
| 2 | + |
| 3 | +**AI Training Data Optimizer powered by Google Gemini API** |
| 4 | + |
| 5 | +`buffdata` is a high-throughput, modular CLI and Python framework designed to optimize, score, refine, evolve, and deduplicate AI datasets for Supervised Fine-Tuning (SFT), Pre-training, and Preference Tuning (DPO / RLHF) using state-of-the-art Google Gemini models (`gemini-3.7-flash`, `gemini-3.5-flash-lite`, and `text-embedding-004`). |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## 🌟 Key Features |
| 10 | + |
| 11 | +- 🎯 **LLM-as-a-Judge Quality Scoring**: Multi-dimensional evaluation (Clarity, Factual Accuracy, Reasoning Depth, Instruction Adherence, Safety) with structured Pydantic schemas. |
| 12 | +- 🧹 **Deep Data Refinement & Cleansing**: Eliminates AI conversational boilerplate (*"As an AI..."*, *"Certainly!"*), expands chain-of-thought reasoning, and fixes syntax/markdown errors. |
| 13 | +- 🧬 **Evol-Instruct Data Synthesis**: Complexifies datasets through reasoning deepening, constraint addition, concretization, and domain expansion. |
| 14 | +- ⚖️ **Automated DPO Preference Builder**: Automatically synthesizes high-contrast `chosen` vs. `rejected` pairs with explicit defect explanations. |
| 15 | +- 🔍 **Semantic & Lexical Deduplication**: Exact SHA-256 hash, MinHash n-gram LSH, and Gemini dense embedding similarity deduplication. |
| 16 | +- ⚡ **Async High-Throughput Engine**: Token-bucket rate limiting (RPM/TPM), concurrency control, and auto-resuming checkpoints. |
| 17 | +- 📊 **Interactive HTML & Markdown Reports**: Rich visual analytics with score distribution charts, identified issue breakdown, and Before vs. After diff viewers. |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## 📦 Installation |
| 22 | + |
| 23 | +```bash |
| 24 | +# Clone the repository and navigate to directory |
| 25 | +cd ~/projects/buffdata |
| 26 | + |
| 27 | +# Create virtual environment |
| 28 | +python3 -m venv .venv |
| 29 | +source .venv/bin/activate |
| 30 | + |
| 31 | +# Install in editable mode |
| 32 | +pip install -e ".[dev]" |
| 33 | +``` |
| 34 | + |
| 35 | +--- |
| 36 | + |
| 37 | +## 🔑 Setup API Key |
| 38 | + |
| 39 | +Set your Google Gemini API key: |
| 40 | + |
| 41 | +```bash |
| 42 | +export GEMINI_API_KEY="your-gemini-api-key" |
| 43 | +``` |
| 44 | + |
| 45 | +Or create a `.env` file in the project directory: |
| 46 | + |
| 47 | +```env |
| 48 | +GEMINI_API_KEY=your-gemini-api-key |
| 49 | +BUFFDATA_DEFAULT_MODEL=gemini-3.7-flash |
| 50 | +``` |
| 51 | + |
| 52 | +--- |
| 53 | + |
| 54 | +## 💻 CLI Quickstart |
| 55 | + |
| 56 | +### 1. Score & Filter Dataset |
| 57 | +```bash |
| 58 | +buffdata score examples/alpaca_sample.jsonl -o filtered.jsonl --min-score 7.5 --filter |
| 59 | +``` |
| 60 | + |
| 61 | +### 2. Refine & Elevate Quality |
| 62 | +```bash |
| 63 | +buffdata refine examples/alpaca_sample.jsonl -o refined.jsonl --mode all |
| 64 | +``` |
| 65 | + |
| 66 | +### 3. Evolve Reasoning Complexity (Evol-Instruct) |
| 67 | +```bash |
| 68 | +buffdata evolve examples/alpaca_sample.jsonl -o evolved.jsonl --strategy deepen_reasoning |
| 69 | +``` |
| 70 | + |
| 71 | +### 4. Build DPO / RLHF Preference Pairs |
| 72 | +```bash |
| 73 | +buffdata dpo examples/alpaca_sample.jsonl -o dpo_dataset.jsonl |
| 74 | +``` |
| 75 | + |
| 76 | +### 5. Deduplicate |
| 77 | +```bash |
| 78 | +buffdata dedup examples/alpaca_sample.jsonl -o deduped.jsonl --method minhash --threshold 0.85 |
| 79 | +``` |
| 80 | + |
| 81 | +### 6. Run Full Multi-Stage Pipeline |
| 82 | +```bash |
| 83 | +buffdata pipeline examples/pipeline_config.yaml -i examples/alpaca_sample.jsonl -o optimized.jsonl |
| 84 | +``` |
| 85 | + |
| 86 | +### 7. View Stats & Generate HTML Audit Report |
| 87 | +```bash |
| 88 | +# Print summary to terminal |
| 89 | +buffdata stats examples/alpaca_sample.jsonl |
| 90 | + |
| 91 | +# Generate interactive HTML report |
| 92 | +buffdata report examples/alpaca_sample.jsonl -o audit_report.html |
| 93 | +``` |
| 94 | + |
| 95 | +--- |
| 96 | + |
| 97 | +## 🐍 Python SDK Example |
| 98 | + |
| 99 | +```python |
| 100 | +from buffdata import GeminiClient, QualityScorer, DataRefiner, read_dataset, write_dataset |
| 101 | + |
| 102 | +# Load dataset |
| 103 | +items = read_dataset("examples/alpaca_sample.jsonl") |
| 104 | + |
| 105 | +# Initialize client and optimizer |
| 106 | +client = GeminiClient(default_model="gemini-3.7-flash") |
| 107 | +refiner = DataRefiner(client=client) |
| 108 | + |
| 109 | +# Refine batch asynchronously |
| 110 | +import asyncio |
| 111 | +refined_items = asyncio.run(refiner.refine_batch_async(items, mode="all")) |
| 112 | + |
| 113 | +# Save refined dataset |
| 114 | +write_dataset(refined_items, "refined_output.jsonl") |
| 115 | +``` |
| 116 | + |
| 117 | +--- |
| 118 | + |
| 119 | +## 🧪 Running Tests |
| 120 | + |
| 121 | +```bash |
| 122 | +pytest tests/ -v |
| 123 | +``` |
| 124 | + |
| 125 | +--- |
| 126 | + |
| 127 | +## 📄 License |
| 128 | +MIT License. |
0 commit comments