Skip to main content

ScaleDown: A framework for LLM prompt optimization and model interaction

Project description

Modular Prompt Optimization Framework

Python 3.8+ License: MIT Tests Code style: black Imports: isort

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!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scaledown-0.1.4.tar.gz (7.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

scaledown-0.1.4-py3-none-any.whl (35.5 kB view details)

Uploaded Python 3

File details

Details for the file scaledown-0.1.4.tar.gz.

File metadata

  • Download URL: scaledown-0.1.4.tar.gz
  • Upload date:
  • Size: 7.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.4

File hashes

Hashes for scaledown-0.1.4.tar.gz
Algorithm Hash digest
SHA256 e9147c8f18388449d82aa3c25cdec30ab330784d59c2c811770a2e0ef473d365
MD5 ef37c79bcee16e309764b9e1a82bf5bf
BLAKE2b-256 0deb324cfb11ea1c9f85d777926f03a85b8e1cdcdb6a3f6c5a65b9cbfb61d4d6

See more details on using hashes here.

File details

Details for the file scaledown-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: scaledown-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 35.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.4

File hashes

Hashes for scaledown-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 cb0ae3dba9554b15f1de5b632733d23a1d1e20fbc1fe999da6d727072df55fb0
MD5 a815194dd3a82f50ca161e3160f398ab
BLAKE2b-256 2fbe53f4d8619b2c9d37aacb80b27e34d382a8ee41b688bbe5ad4887c3031080

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page