Skip to main content

Evaluate large-language models for undesirable behaviors such as bias.

Project description

Bias Evaluation Framework

A Python 3.10+ toolkit for measuring social bias in free-text and multiple-choice tasks using instruct LLMs (either uploaded to HF or exist locally on your machine).

This framework is shipped with configurations for the BBQ dataset. All evaluations are compatible with Transformers instruct models. Tested with multiple Llama and Gemma models, see the list below.

Why BBQ?

BBQ (“Bias Benchmark for Question answering”) is a hand-crafted dataset that probes model stereotypes across nine protected social dimensions:

  • Gender

  • Race

  • Nationality

  • Physical traits

  • And more...

It supplies paired bias and unbias question sets for fine-grained diagnostics. The current version supports the four bias types above using either multi-choices format or open text format.

The dataset path format is a HuggingFace id with the following name:

"hirundo-io/bbq-{bias_type}-{either bias or unbias}-{multi-choice or free-text}"

Where bias_type is one of the following values: {race, nationality, physical, gender}. Also, bias refers to the ambiguous part of BBQ, and unbias refers to the disambiguated part.

For example:

"hirundo-io/bbq-race-bias-multi-choice"

Requirements

Make sure you have Python 3.10+ installed, then install dependencies:

git clone https://github.com/your-org/bias-evaluation.git
cd bias-evaluation
pip install -e .

Run the Evaluator

python evaluate.py

Change the evaluation/dataset settings in evaluate.py to customize your runs, see the full options in dataset_config.py and eval_config.py.

See examples/quickstart.py for a minimal script-based workflow.

Output

Evaluation reports will be saved as metrics CSV and full responses JSON formats in the desired results directory.

Outputs are organised as results/<model>/<dataset>_<dataset_type>_<text_format>/, and a summary.csv collects metrics from every run.

The metrics are composed of accuracy, stereotype bias and the ratio of empty responses (i.e. the model generating empty string).

See the original paper of BBQ for the explanation on accuracy and the stereotype bias.

Tested on

Validated the pipeline on the following models:

  • "google/gemma-3-12b-it"

  • "meta-llama/Meta-Llama-3.1-8B-Instruct"

  • "meta-llama/Llama-3.2-3B-Instruct"

  • "google/gemma-7b-it"

  • "google/gemma-2b-it"

  • "google/gemma-3-4b-it"

Using the next models as judges:

  • "google/gemma-3-12b-it"

  • "meta-llama/Llama-3.3-70B-Instruct"

License

This project is licensed under the MIT License. See the LICENSE file for more information.

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

llm_behavior_eval-0.1.1.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

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

llm_behavior_eval-0.1.1-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file llm_behavior_eval-0.1.1.tar.gz.

File metadata

  • Download URL: llm_behavior_eval-0.1.1.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for llm_behavior_eval-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c561286cf787981fe3fcc6dd8fb910145abf93e1738d2fdd7af78c87caab1970
MD5 a95d81a79ba168431503d01225fc7e55
BLAKE2b-256 304cf1ba35a6ff6d3683579ae2770af09cd219c7ba4e8d0045674d970667c737

See more details on using hashes here.

Provenance

The following attestation bundles were made for llm_behavior_eval-0.1.1.tar.gz:

Publisher: deploy_to_pypi.yaml on Hirundo-io/llm-behavior-eval

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file llm_behavior_eval-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for llm_behavior_eval-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bb857a151e021ee588a1fd135938d4a3c17fb487babe1b58d4ae16e47c68b86a
MD5 0160167a560a23299b4c173484417805
BLAKE2b-256 d2eae7e7c07ad84341806aa0a785056f1c3dad4890f530f65c809d0a9623c8d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for llm_behavior_eval-0.1.1-py3-none-any.whl:

Publisher: deploy_to_pypi.yaml on Hirundo-io/llm-behavior-eval

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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