Skip to content

Life-Experimentalist/EquiLens

Repository files navigation

EquiLens

Black-Box AI Bias Detection Framework

Detect Β· Measure Β· Understand bias in SLMs and LLMs β€” locally, privately, at scale

License Python Docker UV Docker Build DOI


πŸ”¬ Bias Audits πŸ€– Models Tested πŸ“ Prompts Run 🏷️ Bias Types πŸ‘©β€πŸ”¬ Researchers
1,847+ 23+ 94,200+ 6 12+

🌐 Website Β· πŸ“– Docs Β· πŸ› Issues Β· πŸ’¬ Discussions Β· πŸ“„ DOI


What is EquiLens?

EquiLens is a production-ready black-box bias detection framework for Small Language Models (SLMs) and Large Language Models (LLMs). It probes models purely through their input/output interface β€” no weight access required β€” using systematic prompt engineering to surface differential responses across demographic groups.

Built as a final-year B.Tech research project at Amrita Vishwa Vidyapeetham, EquiLens gives researchers, developers, and compliance teams rigorous tools to identify, quantify, and report on bias β€” all running locally via Ollama, keeping data and model interactions private.

Research Context (STAR)

Situation: As SLMs gain adoption in hiring, healthcare, and education, bias in their outputs poses real ethical and legal risk β€” but most auditing tools require white-box access or cloud APIs.

Task: Design a framework that audits any Ollama-compatible model purely through prompts, produces statistically validated bias scores, and is deployable by a solo researcher without GPU cluster access.

Action: Built a three-phase pipeline (corpus generation β†’ model auditing β†’ statistical analysis) with 94,200+ curated prompt variants spanning gender, race, occupation, and sentiment, backed by a FastAPI job system and dual CLI/web interface.

Result: Detected statistically significant gender bias (Cohen's d > 0.4) and occupational stereotyping in multiple SLMs. Framework published on Zenodo with a citable DOI, one-command Docker deployment, and a live research website.


Research Impact

Accomplished X, as measured by Y, by doing Z

  • Quantified bias across 6 dimensions in local LLMs β€” measured by Cohen's d effect sizes and p-values β€” by engineering 15,000+ demographically-balanced prompt pairs and running them against Ollama-hosted models.
  • Reduced bias audit time from days to hours β€” measured by end-to-end pipeline runtime β€” by building a concurrent auditor with automatic retry, checkpoint resume, and optional GPU acceleration.
  • Enabled reproducible AI fairness research β€” measured by a citable Zenodo DOI and a one-command Docker deployment β€” by packaging the full pipeline as a configuration-driven Python framework with structured corpus generation.
  • Delivered a full-stack research tool β€” measured by a working CLI + REST API + web UI β€” by architecting a three-tier FastAPI/Gradio system with background job queuing and SQLite persistence.

Key Features

Black-Box Testing Engine

  • No model internals required β€” works with any Ollama-compatible model via REST API
  • Prompt-pair methodology β€” identical prompts with only the demographic variable changed
  • 6 bias dimensions: Gender Β· Racial/Ethnic Β· Occupational Β· Sentiment Β· Counterfactual Β· Associative
  • 94,200+ curated prompt variants from a JSON-driven corpus specification

Three-Phase Pipeline

Phase 1: Corpus Generation
  word_lists.json β†’ generate_corpus.py β†’ balanced CSV
  (names Γ— professions Γ— trait templates, all demographic pairs)

Phase 2: Model Auditing
  CSV corpus β†’ audit_model.py β†’ Ollama API β†’ scored response CSV
  (concurrent, resumable, GPU-accelerated via Ollama)

Phase 3: Statistical Analysis
  scored CSV β†’ analytics.py β†’ bias scores, effect sizes, HTML/Markdown reports
  (t-tests, Cohen's d, confidence intervals, AI-powered narrative insights)

Developer Experience

  • One command via UV: uv run equilens web
  • One command via Docker: docker compose -f infra/docker-compose.yml up
  • Dual interface β€” rich Terminal CLI + built-in web dashboard (Alpine.js, no build step)
  • Background job system with real-time SSE log streaming
  • Automatic port management, Docker detection, GPU detection
  • Periodic automated backups with configurable retention

Quick Start

Option 1 β€” UV Tool Install (Anywhere, No Clone Required)

# Install as a global UV tool β€” works on any machine with uv + Ollama
uv tool install git+https://github.com/Life-Experimentalist/EquiLens.git

# Start Ollama
ollama serve && ollama pull llama3.2:latest

# Launch dashboard
equilens web          # β†’ http://localhost:8000
equilens --help       # see all commands

Or try without installing: uvx --from git+https://github.com/Life-Experimentalist/EquiLens.git equilens --help

Option 2 β€” UV Dev Install (Clone + Develop)

# Install UV if you don't have it
pip install uv

# Clone and install
git clone https://github.com/Life-Experimentalist/EquiLens.git
cd EquiLens
uv sync

# Start Ollama (separate terminal)
ollama serve
ollama pull llama3.2:latest

# Launch dashboard β€” single command, single server
uv run equilens web
# β†’ Dashboard: http://localhost:8000
# β†’ API docs:  http://localhost:8000/docs

Option 3 β€” Docker (One Command)

git clone https://github.com/Life-Experimentalist/EquiLens.git
cd EquiLens
docker compose -f infra/docker-compose.yml up
# β†’ Dashboard: http://localhost:8000
# β†’ API docs:  http://localhost:8000/docs
# β†’ Ollama:    http://localhost:11434

Option 4 β€” CLI Pipeline (No Web UI)

uv sync

# Step 1: Generate bias corpus
uv run equilens generate-corpus

# Step 2: Audit a model
uv run equilens audit --model llama3.2:latest

# Step 3: Analyze results
uv run equilens analyze results/audit_*.csv

CLI Reference

Command Description
equilens web Launch dashboard + API server at http://localhost:8000
equilens backend Launch FastAPI backend only (API-only mode)
equilens audit --model <name> Run bias audit against a model
equilens analyze <results.csv> Run statistical analysis
equilens generate-corpus Generate a new prompt corpus
equilens status System health check (Ollama, Docker, GPU)

Full dashboard documentation: docs/DASHBOARD.md


Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        EquiLens v2.2                           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚   Dashboard (Alpine.js)  β”‚   CLI (Typer + Rich)                β”‚
β”‚   FastAPI + Jinja2       β”‚   No backend required               β”‚
β”‚   http://localhost:8000  β”‚                                     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                     Core Pipeline                              β”‚
β”‚   Phase 1: Corpus Gen β†’ Phase 2: Audit β†’ Phase 3: Analyze     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                  Ollama (Local LLM Runtime)                    β”‚
β”‚   llama3.2 Β· phi3 Β· mistral Β· gemma Β· qwen Β· deepseek Β· ...   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Full architecture: docs/architecture/ARCHITECTURE.md


Bias Categories

Category Description Example Probe
Gender Male vs female name substitution "Alice/Bob is applying for a software role..."
Racial/Ethnic Western vs non-Western names "Emily/Fatima submitted the report..."
Occupational Profession-based stereotyping "The nurse/engineer said..."
Sentiment Positive/negative trait association Adjective pairing by demographic group
Counterfactual Response change on single demographic swap Identical scenario, only name changes
Associative Implicit word-level associations Word completion near group identifiers

Requirements

Requirement Minimum Recommended
Python 3.11 3.12+
Ollama Latest Latest
RAM 8 GB 16 GB
Disk 5 GB + models 20 GB
GPU Not required NVIDIA CUDA

Project Structure

EquiLens/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ Phase1_CorpusGenerator/     # Prompt corpus generation
β”‚   β”‚   β”œβ”€β”€ generate_corpus.py
β”‚   β”‚   └── word_lists.json         # Curated demographic word lists
β”‚   β”œβ”€β”€ Phase2_ModelAuditor/        # Black-box model probing
β”‚   β”‚   β”œβ”€β”€ audit_model.py
β”‚   β”‚   └── enhanced_audit_model.py
β”‚   β”œβ”€β”€ Phase3_Analysis/            # Statistics + reporting
β”‚   β”‚   └── analytics.py
β”‚   └── equilens/                   # Main Python package
β”‚       β”œβ”€β”€ cli.py                  # `equilens` CLI entry point
β”‚       β”œβ”€β”€ gradio_app.py           # Gradio web UI (backend-connected)
β”‚       β”œβ”€β”€ web_ui.py               # Standalone legacy UI
β”‚       β”œβ”€β”€ backend/api.py          # FastAPI REST API
β”‚       β”œβ”€β”€ telemetry.py            # Usage metric counters
β”‚       └── core/                   # Manager, Ollama config, ports
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ telemetry.json              # Usage metrics seed
β”‚   └── jobs/equilens_jobs.db       # SQLite job database
β”œβ”€β”€ docs/                           # Full documentation suite
β”œβ”€β”€ tests/                          # Unit + integration tests
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ Dockerfile
└── pyproject.toml

Documentation

Guide Description
Quick Start 5-minute setup guide
Gradio UI Guide Web interface walkthrough
CLI Reference All CLI commands
Configuration Config options
Architecture System design diagrams
Pipeline Phase-by-phase data flow
Analytics Guide Reports and statistics
Docker Setup Docker deployment
Ollama Setup Ollama configuration
UV Scripts UV workflow reference
Keyboard Shortcuts CLI shortcuts

Research & Citation

Published on Zenodo β€” citable for academic work:

@software{equilens2025,
  author    = {VKrishna04},
  title     = {EquiLens: Black-Box AI Bias Detection Framework},
  year      = {2025},
  publisher = {Zenodo},
  doi       = {10.5281/zenodo.17014103},
  url       = {https://doi.org/10.5281/zenodo.17014103}
}

Related paper: public/AIDE_2026_Sem7.pdf β€” Auditing Gender Bias in Small Language Models.


Contributing

Contributions welcome β€” see CONTRIBUTING.md.

Good first issues: additional bias category templates, new visualization types, alternative LLM backends, more language/cultural word lists.


License

Apache 2.0 β€” see LICENSE.md.


Built with rigour for responsible AI Β· Amrita Vishwa Vidyapeetham Β· 2025

About

🎯 EquiLens - AI Bias Detection Platform for LLMs via Ollama. Interactive CLI with corpus generation, multi-metric auditing, statistical analysis & visualization. Features enhanced auditors, dynamic concurrency, resume capability & rich progress tracking. Alt Links: https://equilens.pages.dev/ , https://life-experimentalist.github.io/EquiLens/

Topics

Resources

License

Contributing

Stars

2 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors