Modular Prompt Optimization Framework
A framework for evaluating modular combinations of prompt optimization techniques on LLM hallucination reduction. Designed for systematic experimentation with comprehensive evaluation metrics.
Features
- Hallucination Evaluation: correct/incorrect/abstention responses with precision, recall, F1, and hallucination rates
- Multiple Optimizers: Chain-of-Thought, Chain-of-Verification, Expert Persona, Uncertainty Quantification, and their arbitrary combinations
- Multiple Dataset: Full support for OpenAI's SimpleQA hallucination benchmark dataset, and more
- Multi-LLM Support: OpenAI GPT, Google Gemini, via unified interface
- Automatic Checkpointing: Resume interrupted experiments, progress tracking
Quick Start
Prerequisites
Install uv for fast Python package management:
# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh
# or: pip install uv
Setup
# Clone and setup environment (uv handles everything automatically)
git clone <repository-url>
cd modular-prompt-optimization
uv sync
# Add API keys to .env file
OPENAI_API_KEY=your-key
GOOGLE_API_KEY=your-key
SCALEDOWN_API_KEY=your-key
Usage
Run Experiments
# Basic experiment
uv run experiment.py --model=scaledown-gpt-4o --optimizers=cot
# Multiple optimizers
uv run experiment.py --model=scaledown-gpt-4o --optimizers=expert_persona,cot
Evaluate Results
uv run evaluate.py -r results/experiment_results.json -d dataset/simpleqa.json
Example output:
🚨 HALLUCINATION ANALYSIS:
Hallucination Rate: 0.684 (68.4% of attempted answers)
Abstention Rate: 0.020 (model says 'I don't know')
🎯 CORE PERFORMANCE METRICS:
Precision: 0.316 (accuracy when attempting answers)
F1 Score: 0.308
Analysis
cd experiments/
jupyter notebook simpleqa_hallucination_analysis.ipynb
Available Options
Models: scaledown-gpt-4o, gemini2.5_flash_lite, llama2, llama2_70b
Optimizers: cot, cove, expert_persona, uncertainty (combinable with commas)
Architecture
-
src/llms.py- LLM provider implementations -
src/prompt_optimizer.py- Modular optimization techniques -
evaluate.py- Enhanced evaluation metrics -
experiments/- Analysis notebook and results
Evaluation Metrics
The framework provides detailed hallucination analysis:
- Response Classification: Correct, Incorrect (hallucinations), Abstentions
- Core Metrics: Precision, Recall, F1 Score
- Hallucination Metrics: Hallucination rate, abstention rate, calibration metrics
- Interactive Analysis: Inspect specific response types and compare optimizers
Extension
Add new optimizers by extending OPTIMIZER_PROMPTS in src/prompt_optimizer.py.
Testing
# Run unit tests
uv run pytest tests/
# Run with coverage
uv run pytest tests/ --cov=src
# Install dev dependencies
uv sync --group dev
GitHub Actions CI automatically runs tests on Python 3.8+ for all commits and pull requests.
Requirements
- Python 3.8+ (managed automatically by uv)
- uv package manager
- Dependencies are defined in
pyproject.toml
All dependencies are automatically managed by uv - no manual pip installs needed!
Metadata
Release files for scaledown 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| scaledown-0.1.4.tar.gz | 7.4 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| scaledown-0.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.4 MB
Release files / scaledown-0.1.4.tar.gz
| Download URL | scaledown-0.1.4.tar.gz |
|---|---|
| Size | 7.4 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e9147c8f18388449d82aa3c25cdec30ab330784d59c2c811770a2e0ef473d365
|
|
BLAKE2b-256 checksum How to use checksums |
0deb324cfb11ea1c9f85d777926f03a85b8e1cdcdb6a3f6c5a65b9cbfb61d4d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.4
|
Release files / scaledown-0.1.4-py3-none-any.whl
| Download URL | scaledown-0.1.4-py3-none-any.whl |
|---|---|
| Size | 35.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cb0ae3dba9554b15f1de5b632733d23a1d1e20fbc1fe999da6d727072df55fb0
|
|
BLAKE2b-256 checksum How to use checksums |
2fbe53f4d8619b2c9d37aacb80b27e34d382a8ee41b688bbe5ad4887c3031080
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.4
|