bias-scope 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bias_scope-0.1.0/.github/workflows/docs.yml +33 -0
- bias_scope-0.1.0/.gitignore +120 -0
- bias_scope-0.1.0/.readthedocs.yaml +16 -0
- bias_scope-0.1.0/PKG-INFO +32 -0
- bias_scope-0.1.0/README.md +4 -0
- bias_scope-0.1.0/assets/logo.png +0 -0
- bias_scope-0.1.0/docs/api/embeddings/ceat.md +88 -0
- bias_scope-0.1.0/docs/api/embeddings/seat.md +72 -0
- bias_scope-0.1.0/docs/api/embeddings/sentence_bias_score.md +105 -0
- bias_scope-0.1.0/docs/api/embeddings/weat.md +71 -0
- bias_scope-0.1.0/docs/api/generated_text/cooccurrence_bias_score.md +59 -0
- bias_scope-0.1.0/docs/api/generated_text/counterfactual_sentiment_bias.md +124 -0
- bias_scope-0.1.0/docs/api/generated_text/demographic_representation.md +59 -0
- bias_scope-0.1.0/docs/api/generated_text/emt.md +103 -0
- bias_scope-0.1.0/docs/api/generated_text/fgb.md +120 -0
- bias_scope-0.1.0/docs/api/generated_text/gender_polarity.md +130 -0
- bias_scope-0.1.0/docs/api/generated_text/honest.md +104 -0
- bias_scope-0.1.0/docs/api/generated_text/marked_persons.md +61 -0
- bias_scope-0.1.0/docs/api/generated_text/perspective_api.md +58 -0
- bias_scope-0.1.0/docs/api/generated_text/pgb.md +121 -0
- bias_scope-0.1.0/docs/api/generated_text/psycholinguistic_norms.md +104 -0
- bias_scope-0.1.0/docs/api/generated_text/regard_score.md +90 -0
- bias_scope-0.1.0/docs/api/generated_text/score_parity.md +93 -0
- bias_scope-0.1.0/docs/api/generated_text/social_group_substitution.md +74 -0
- bias_scope-0.1.0/docs/api/generated_text/stereotypical_associations.md +69 -0
- bias_scope-0.1.0/docs/api/generated_text/toxicity_fraction.md +65 -0
- bias_scope-0.1.0/docs/api/generated_text/toxicity_probability.md +75 -0
- bias_scope-0.1.0/docs/api/overview.md +100 -0
- bias_scope-0.1.0/docs/api/probability/aul.md +120 -0
- bias_scope-0.1.0/docs/api/probability/aula.md +69 -0
- bias_scope-0.1.0/docs/api/probability/cat.md +119 -0
- bias_scope-0.1.0/docs/api/probability/cbs.md +120 -0
- bias_scope-0.1.0/docs/api/probability/crows_pairs.md +117 -0
- bias_scope-0.1.0/docs/api/probability/disco.md +110 -0
- bias_scope-0.1.0/docs/api/probability/icat.md +89 -0
- bias_scope-0.1.0/docs/api/probability/lmb.md +71 -0
- bias_scope-0.1.0/docs/api/probability/lpbs.md +106 -0
- bias_scope-0.1.0/docs/api/prompts/analogical_reasoning_bias.md +57 -0
- bias_scope-0.1.0/docs/api/prompts/bbq.md +59 -0
- bias_scope-0.1.0/docs/api/prompts/bold.md +101 -0
- bias_scope-0.1.0/docs/api/prompts/counterfactual_fairness.md +62 -0
- bias_scope-0.1.0/docs/api/prompts/demographic_representation_bias.md +57 -0
- bias_scope-0.1.0/docs/api/prompts/opinion_consistency_across_personas.md +117 -0
- bias_scope-0.1.0/docs/api/prompts/realtoxicityprompts.md +99 -0
- bias_scope-0.1.0/docs/api/prompts/stereoset.md +67 -0
- bias_scope-0.1.0/docs/api/prompts/tof_nof.md +62 -0
- bias_scope-0.1.0/docs/api/prompts/truthfulqa.md +101 -0
- bias_scope-0.1.0/docs/api/prompts/unqover.md +117 -0
- bias_scope-0.1.0/docs/assets/logo.png +0 -0
- bias_scope-0.1.0/docs/authors.md +10 -0
- bias_scope-0.1.0/docs/contributing.md +136 -0
- bias_scope-0.1.0/docs/getting-started/installation.md +38 -0
- bias_scope-0.1.0/docs/getting-started/quickstart.md +118 -0
- bias_scope-0.1.0/docs/index.md +47 -0
- bias_scope-0.1.0/docs/javascripts/sidebar-visibility.js +10 -0
- bias_scope-0.1.0/docs/stylesheets/extra.css +236 -0
- bias_scope-0.1.0/docu.md +985 -0
- bias_scope-0.1.0/examples/embeddings_based/ceat.py +75 -0
- bias_scope-0.1.0/examples/embeddings_based/seat.py +59 -0
- bias_scope-0.1.0/examples/embeddings_based/sentence_bias_score.py +92 -0
- bias_scope-0.1.0/examples/embeddings_based/weat.py +58 -0
- bias_scope-0.1.0/examples/generated_text_based/__init__.py +0 -0
- bias_scope-0.1.0/examples/generated_text_based/cooccurrence_bias_score.py +50 -0
- bias_scope-0.1.0/examples/generated_text_based/counterfactual_sentiment_bias.py +115 -0
- bias_scope-0.1.0/examples/generated_text_based/demographic_representation.py +50 -0
- bias_scope-0.1.0/examples/generated_text_based/emt.py +94 -0
- bias_scope-0.1.0/examples/generated_text_based/fgb.py +111 -0
- bias_scope-0.1.0/examples/generated_text_based/gender_polarity.py +121 -0
- bias_scope-0.1.0/examples/generated_text_based/honest.py +95 -0
- bias_scope-0.1.0/examples/generated_text_based/marked_persons.py +52 -0
- bias_scope-0.1.0/examples/generated_text_based/perspective_api.py +49 -0
- bias_scope-0.1.0/examples/generated_text_based/pgb.py +112 -0
- bias_scope-0.1.0/examples/generated_text_based/psycholinguistic_norms.py +95 -0
- bias_scope-0.1.0/examples/generated_text_based/regard_score.py +77 -0
- bias_scope-0.1.0/examples/generated_text_based/score_parity.py +80 -0
- bias_scope-0.1.0/examples/generated_text_based/social_group_substitution.py +65 -0
- bias_scope-0.1.0/examples/generated_text_based/stereotypical_associations.py +60 -0
- bias_scope-0.1.0/examples/generated_text_based/toxicity_fraction.py +56 -0
- bias_scope-0.1.0/examples/generated_text_based/toxicity_probability.py +66 -0
- bias_scope-0.1.0/examples/probability_based/__init__.py +0 -0
- bias_scope-0.1.0/examples/probability_based/aul.py +107 -0
- bias_scope-0.1.0/examples/probability_based/aula.py +56 -0
- bias_scope-0.1.0/examples/probability_based/cat.py +106 -0
- bias_scope-0.1.0/examples/probability_based/cbs.py +111 -0
- bias_scope-0.1.0/examples/probability_based/crows_pairs.py +104 -0
- bias_scope-0.1.0/examples/probability_based/disco.py +101 -0
- bias_scope-0.1.0/examples/probability_based/icat.py +76 -0
- bias_scope-0.1.0/examples/probability_based/lmb.py +58 -0
- bias_scope-0.1.0/examples/probability_based/lpbs.py +97 -0
- bias_scope-0.1.0/examples/prompts_based/__init__.py +0 -0
- bias_scope-0.1.0/examples/prompts_based/analogical_reasoning_bias.py +48 -0
- bias_scope-0.1.0/examples/prompts_based/bbq.py +50 -0
- bias_scope-0.1.0/examples/prompts_based/bold.py +92 -0
- bias_scope-0.1.0/examples/prompts_based/counterfactual_fairness.py +53 -0
- bias_scope-0.1.0/examples/prompts_based/demographic_representation_bias.py +48 -0
- bias_scope-0.1.0/examples/prompts_based/opinion_consistency_across_personas.py +108 -0
- bias_scope-0.1.0/examples/prompts_based/realtoxicityprompts.py +90 -0
- bias_scope-0.1.0/examples/prompts_based/stereoset.py +58 -0
- bias_scope-0.1.0/examples/prompts_based/tof_nof.py +53 -0
- bias_scope-0.1.0/examples/prompts_based/truthfulqa.py +92 -0
- bias_scope-0.1.0/examples/prompts_based/unqover.py +108 -0
- bias_scope-0.1.0/mkdocs.yml +129 -0
- bias_scope-0.1.0/pyproject.toml +56 -0
- bias_scope-0.1.0/src/bias_scope/__init__.py +178 -0
- bias_scope-0.1.0/src/bias_scope/base.py +483 -0
- bias_scope-0.1.0/src/bias_scope/embeddings_based/__init__.py +9 -0
- bias_scope-0.1.0/src/bias_scope/embeddings_based/_helpers.py +135 -0
- bias_scope-0.1.0/src/bias_scope/embeddings_based/ceat.py +273 -0
- bias_scope-0.1.0/src/bias_scope/embeddings_based/seat.py +107 -0
- bias_scope-0.1.0/src/bias_scope/embeddings_based/sentence_bias_score.py +320 -0
- bias_scope-0.1.0/src/bias_scope/embeddings_based/weat.py +187 -0
- bias_scope-0.1.0/src/bias_scope/generated_text_based/__init__.py +50 -0
- bias_scope-0.1.0/src/bias_scope/generated_text_based/_helpers.py +301 -0
- bias_scope-0.1.0/src/bias_scope/generated_text_based/cooccurrence_bias_score.py +323 -0
- bias_scope-0.1.0/src/bias_scope/generated_text_based/counterfactual_sentiment_bias.py +78 -0
- bias_scope-0.1.0/src/bias_scope/generated_text_based/demographic_representation.py +270 -0
- bias_scope-0.1.0/src/bias_scope/generated_text_based/emt.py +64 -0
- bias_scope-0.1.0/src/bias_scope/generated_text_based/fgb.py +76 -0
- bias_scope-0.1.0/src/bias_scope/generated_text_based/gender_polarity.py +163 -0
- bias_scope-0.1.0/src/bias_scope/generated_text_based/honest.py +138 -0
- bias_scope-0.1.0/src/bias_scope/generated_text_based/marked_persons.py +262 -0
- bias_scope-0.1.0/src/bias_scope/generated_text_based/perspective_api.py +219 -0
- bias_scope-0.1.0/src/bias_scope/generated_text_based/pgb.py +75 -0
- bias_scope-0.1.0/src/bias_scope/generated_text_based/psycholinguistic_norms.py +223 -0
- bias_scope-0.1.0/src/bias_scope/generated_text_based/regard_score.py +250 -0
- bias_scope-0.1.0/src/bias_scope/generated_text_based/score_parity.py +208 -0
- bias_scope-0.1.0/src/bias_scope/generated_text_based/social_group_substitution.py +396 -0
- bias_scope-0.1.0/src/bias_scope/generated_text_based/stereotypical_associations.py +296 -0
- bias_scope-0.1.0/src/bias_scope/generated_text_based/toxicity_fraction.py +191 -0
- bias_scope-0.1.0/src/bias_scope/generated_text_based/toxicity_probability.py +137 -0
- bias_scope-0.1.0/src/bias_scope/probability_based/__init__.py +33 -0
- bias_scope-0.1.0/src/bias_scope/probability_based/_helpers.py +117 -0
- bias_scope-0.1.0/src/bias_scope/probability_based/_scorers.py +100 -0
- bias_scope-0.1.0/src/bias_scope/probability_based/aul.py +171 -0
- bias_scope-0.1.0/src/bias_scope/probability_based/aula.py +282 -0
- bias_scope-0.1.0/src/bias_scope/probability_based/cat.py +187 -0
- bias_scope-0.1.0/src/bias_scope/probability_based/cbs.py +297 -0
- bias_scope-0.1.0/src/bias_scope/probability_based/crows_pairs.py +196 -0
- bias_scope-0.1.0/src/bias_scope/probability_based/disco.py +151 -0
- bias_scope-0.1.0/src/bias_scope/probability_based/icat.py +131 -0
- bias_scope-0.1.0/src/bias_scope/probability_based/lmb.py +489 -0
- bias_scope-0.1.0/src/bias_scope/probability_based/lpbs.py +203 -0
- bias_scope-0.1.0/src/bias_scope/prompts_based/__init__.py +74 -0
- bias_scope-0.1.0/src/bias_scope/prompts_based/analogical_reasoning_bias.py +396 -0
- bias_scope-0.1.0/src/bias_scope/prompts_based/bbq.py +286 -0
- bias_scope-0.1.0/src/bias_scope/prompts_based/bold.py +267 -0
- bias_scope-0.1.0/src/bias_scope/prompts_based/counterfactual_fairness.py +279 -0
- bias_scope-0.1.0/src/bias_scope/prompts_based/demographic_representation_bias.py +269 -0
- bias_scope-0.1.0/src/bias_scope/prompts_based/opinion_consistency_across_personas.py +280 -0
- bias_scope-0.1.0/src/bias_scope/prompts_based/realtoxicityprompts.py +246 -0
- bias_scope-0.1.0/src/bias_scope/prompts_based/stereoset.py +431 -0
- bias_scope-0.1.0/src/bias_scope/prompts_based/tof_nof.py +338 -0
- bias_scope-0.1.0/src/bias_scope/prompts_based/truthfulqa.py +336 -0
- bias_scope-0.1.0/src/bias_scope/prompts_based/unqover.py +683 -0
- bias_scope-0.1.0/src/bias_scope/utils.py +92 -0
- bias_scope-0.1.0/tests/test_embeddings/__init__.py +1 -0
- bias_scope-0.1.0/tests/test_embeddings/test_ceat.py +345 -0
- bias_scope-0.1.0/tests/test_embeddings/test_seat.py +91 -0
- bias_scope-0.1.0/tests/test_embeddings/test_sentence_bias_score.py +296 -0
- bias_scope-0.1.0/tests/test_embeddings/test_weat.py +189 -0
- bias_scope-0.1.0/tests/test_examples/test_metric_usage_examples.py +9 -0
- bias_scope-0.1.0/tests/test_examples/test_public_exports.py +40 -0
- bias_scope-0.1.0/tests/test_generated_text_based/__init__.py +0 -0
- bias_scope-0.1.0/tests/test_generated_text_based/test_cooccurrence_bias_score.py +487 -0
- bias_scope-0.1.0/tests/test_generated_text_based/test_counterfactual_sentiment_bias.py +107 -0
- bias_scope-0.1.0/tests/test_generated_text_based/test_demographic_representation.py +386 -0
- bias_scope-0.1.0/tests/test_generated_text_based/test_emt.py +66 -0
- bias_scope-0.1.0/tests/test_generated_text_based/test_fgb.py +93 -0
- bias_scope-0.1.0/tests/test_generated_text_based/test_gender_polarity.py +101 -0
- bias_scope-0.1.0/tests/test_generated_text_based/test_honest.py +80 -0
- bias_scope-0.1.0/tests/test_generated_text_based/test_marked_persons.py +406 -0
- bias_scope-0.1.0/tests/test_generated_text_based/test_perspective_api.py +79 -0
- bias_scope-0.1.0/tests/test_generated_text_based/test_pgb.py +89 -0
- bias_scope-0.1.0/tests/test_generated_text_based/test_psycholinguistic_norms.py +89 -0
- bias_scope-0.1.0/tests/test_generated_text_based/test_regard_score.py +203 -0
- bias_scope-0.1.0/tests/test_generated_text_based/test_score_parity.py +221 -0
- bias_scope-0.1.0/tests/test_generated_text_based/test_social_group_substitution.py +528 -0
- bias_scope-0.1.0/tests/test_generated_text_based/test_stereotypical_associations.py +415 -0
- bias_scope-0.1.0/tests/test_generated_text_based/test_toxicity_fraction.py +153 -0
- bias_scope-0.1.0/tests/test_generated_text_based/test_toxicity_probability.py +179 -0
- bias_scope-0.1.0/tests/test_probability_based/__init__.py +1 -0
- bias_scope-0.1.0/tests/test_probability_based/test_aul.py +249 -0
- bias_scope-0.1.0/tests/test_probability_based/test_aula.py +418 -0
- bias_scope-0.1.0/tests/test_probability_based/test_cat.py +317 -0
- bias_scope-0.1.0/tests/test_probability_based/test_cbs.py +98 -0
- bias_scope-0.1.0/tests/test_probability_based/test_crows_pairs.py +254 -0
- bias_scope-0.1.0/tests/test_probability_based/test_disco.py +66 -0
- bias_scope-0.1.0/tests/test_probability_based/test_icat.py +498 -0
- bias_scope-0.1.0/tests/test_probability_based/test_lmb.py +611 -0
- bias_scope-0.1.0/tests/test_probability_based/test_lpbs.py +94 -0
- bias_scope-0.1.0/tests/test_prompts_based/__init__.py +0 -0
- bias_scope-0.1.0/tests/test_prompts_based/test_analogical_reasoning_bias.py +232 -0
- bias_scope-0.1.0/tests/test_prompts_based/test_bbq.py +309 -0
- bias_scope-0.1.0/tests/test_prompts_based/test_bold.py +151 -0
- bias_scope-0.1.0/tests/test_prompts_based/test_counterfactual_fairness.py +267 -0
- bias_scope-0.1.0/tests/test_prompts_based/test_demographic_representation_bias.py +274 -0
- bias_scope-0.1.0/tests/test_prompts_based/test_opinion_consistency_across_personas.py +209 -0
- bias_scope-0.1.0/tests/test_prompts_based/test_realtoxicityprompts.py +146 -0
- bias_scope-0.1.0/tests/test_prompts_based/test_stereoset.py +278 -0
- bias_scope-0.1.0/tests/test_prompts_based/test_tof_nof.py +320 -0
- bias_scope-0.1.0/tests/test_prompts_based/test_truthfulqa.py +156 -0
- bias_scope-0.1.0/tests/test_prompts_based/test_unqover.py +332 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
name: Deploy MkDocs Documentation
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- documentation
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: write
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
deploy:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- name: Checkout repository
|
|
17
|
+
uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Set up Python
|
|
20
|
+
uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: '3.11'
|
|
23
|
+
|
|
24
|
+
- name: Install documentation dependencies
|
|
25
|
+
run: python -m pip install '.[docs]'
|
|
26
|
+
|
|
27
|
+
- name: Configure Git author
|
|
28
|
+
run: |
|
|
29
|
+
git config --global user.name 'github-actions[bot]'
|
|
30
|
+
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
|
|
31
|
+
|
|
32
|
+
- name: Deploy documentation
|
|
33
|
+
run: mkdocs gh-deploy --force
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
env/
|
|
12
|
+
build/
|
|
13
|
+
_build/
|
|
14
|
+
develop-eggs/
|
|
15
|
+
dist/
|
|
16
|
+
downloads/
|
|
17
|
+
eggs/
|
|
18
|
+
.eggs/
|
|
19
|
+
lib/
|
|
20
|
+
lib64/
|
|
21
|
+
parts/
|
|
22
|
+
sdist/
|
|
23
|
+
var/
|
|
24
|
+
wheels/
|
|
25
|
+
*.egg-info/
|
|
26
|
+
.installed.cfg
|
|
27
|
+
*.egg
|
|
28
|
+
testenv/
|
|
29
|
+
|
|
30
|
+
# PyInstaller
|
|
31
|
+
# Usually these files are written by a python script from a template
|
|
32
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
33
|
+
*.manifest
|
|
34
|
+
*.spec
|
|
35
|
+
|
|
36
|
+
# Installer logs
|
|
37
|
+
pip-log.txt
|
|
38
|
+
pip-delete-this-directory.txt
|
|
39
|
+
|
|
40
|
+
# Unit test / coverage reports
|
|
41
|
+
htmlcov/
|
|
42
|
+
.tox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
.hypothesis/
|
|
50
|
+
.pytest_cache/
|
|
51
|
+
|
|
52
|
+
# Translations
|
|
53
|
+
*.mo
|
|
54
|
+
*.pot
|
|
55
|
+
|
|
56
|
+
# Django stuff:
|
|
57
|
+
*.log
|
|
58
|
+
local_settings.py
|
|
59
|
+
|
|
60
|
+
# Flask stuff:
|
|
61
|
+
instance/
|
|
62
|
+
.webassets-cache
|
|
63
|
+
|
|
64
|
+
# Scrapy stuff:
|
|
65
|
+
.scrapy
|
|
66
|
+
|
|
67
|
+
# Sphinx documentation
|
|
68
|
+
docs/_build/
|
|
69
|
+
|
|
70
|
+
# PyBuilder
|
|
71
|
+
target/
|
|
72
|
+
|
|
73
|
+
# Jupyter Notebook
|
|
74
|
+
.ipynb_checkpoints
|
|
75
|
+
|
|
76
|
+
# pyenv
|
|
77
|
+
.python-version
|
|
78
|
+
|
|
79
|
+
# celery beat schedule file
|
|
80
|
+
celerybeat-schedule
|
|
81
|
+
|
|
82
|
+
# SageMath parsed files
|
|
83
|
+
*.sage.py
|
|
84
|
+
|
|
85
|
+
# dotenv
|
|
86
|
+
.env
|
|
87
|
+
|
|
88
|
+
# virtualenv
|
|
89
|
+
.venv
|
|
90
|
+
venv/
|
|
91
|
+
ENV/
|
|
92
|
+
|
|
93
|
+
# Spyder project settings
|
|
94
|
+
.spyderproject
|
|
95
|
+
.spyproject
|
|
96
|
+
|
|
97
|
+
# Rope project settings
|
|
98
|
+
.ropeproject
|
|
99
|
+
|
|
100
|
+
# mkdocs documentation
|
|
101
|
+
/site
|
|
102
|
+
|
|
103
|
+
# mypy
|
|
104
|
+
.mypy_cache/
|
|
105
|
+
|
|
106
|
+
# IDE settings
|
|
107
|
+
.vscode/
|
|
108
|
+
.idea/
|
|
109
|
+
|
|
110
|
+
.DS_STORE
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
# Ignore .claude directory
|
|
114
|
+
.claude/
|
|
115
|
+
|
|
116
|
+
#Ignore zip files
|
|
117
|
+
*.zip
|
|
118
|
+
|
|
119
|
+
# HuggingFace cache
|
|
120
|
+
.hf_cache*/
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bias-scope
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A library for detecting biases in machine learning models.
|
|
5
|
+
Author-email: ChadiHelwe <chadi.helwe@gmail.com>
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Requires-Dist: datasets>=2.0.0
|
|
8
|
+
Requires-Dist: datasets>=5.0.0
|
|
9
|
+
Requires-Dist: litellm>=1.0.0
|
|
10
|
+
Requires-Dist: numpy>=2.1.3
|
|
11
|
+
Requires-Dist: requests>=2.28.0
|
|
12
|
+
Requires-Dist: sentence-transformers>=2.0.0
|
|
13
|
+
Requires-Dist: torch>=2.5.1
|
|
14
|
+
Requires-Dist: transformers>=4.31.0
|
|
15
|
+
Provides-Extra: dev
|
|
16
|
+
Requires-Dist: black>=26.1.0; extra == 'dev'
|
|
17
|
+
Requires-Dist: coverage>=7.6.4; extra == 'dev'
|
|
18
|
+
Requires-Dist: isort>=5.13.2; extra == 'dev'
|
|
19
|
+
Requires-Dist: nox>=2025.11.12; extra == 'dev'
|
|
20
|
+
Requires-Dist: pytest>=9.0.0; extra == 'dev'
|
|
21
|
+
Provides-Extra: docs
|
|
22
|
+
Requires-Dist: mkdocs-gen-files>=0.5.0; extra == 'docs'
|
|
23
|
+
Requires-Dist: mkdocs-literate-nav>=0.6.0; extra == 'docs'
|
|
24
|
+
Requires-Dist: mkdocs-material>=9.0.0; extra == 'docs'
|
|
25
|
+
Requires-Dist: mkdocs>=1.6.1; extra == 'docs'
|
|
26
|
+
Requires-Dist: mkdocstrings[python]>=0.25.0; extra == 'docs'
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
<div align="center">
|
|
30
|
+
<img src="assets/logo.png" alt="Logo" />
|
|
31
|
+
</div>
|
|
32
|
+
|
|
Binary file
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# CEAT
|
|
2
|
+
|
|
3
|
+
::: bias_scope.embeddings_based.ceat.CEAT
|
|
4
|
+
|
|
5
|
+
## Example
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
# --------------------------------------------------------------
|
|
9
|
+
# CEAT — Contextualized Embedding Association Test
|
|
10
|
+
#
|
|
11
|
+
# Extends WEAT to contextualized embeddings by computing a
|
|
12
|
+
# distribution of WEAT scores over random subsamples and
|
|
13
|
+
# aggregating with inverse-variance weighting.
|
|
14
|
+
#
|
|
15
|
+
# This example embeds each word in multiple sentence contexts
|
|
16
|
+
# to simulate contextualized representations, then runs CEAT.
|
|
17
|
+
#
|
|
18
|
+
# NOTE: all-MiniLM-L6-v2 is a sentence encoder, so these results
|
|
19
|
+
# are illustrative. For production use a model like BERT that
|
|
20
|
+
# produces different representations per context.
|
|
21
|
+
# --------------------------------------------------------------
|
|
22
|
+
|
|
23
|
+
from sentence_transformers import SentenceTransformer
|
|
24
|
+
from bias_scope.embeddings_based import CEAT
|
|
25
|
+
|
|
26
|
+
# --- Load encoder ---
|
|
27
|
+
model = SentenceTransformer("all-MiniLM-L6-v2")
|
|
28
|
+
|
|
29
|
+
# --- Words and sentence contexts ---
|
|
30
|
+
male_names = ["John", "Paul", "Mike", "Kevin", "Steve", "Greg", "Jeff", "Bill"]
|
|
31
|
+
female_names = ["Amy", "Joan", "Lisa", "Sarah", "Diana", "Kate", "Ann", "Donna"]
|
|
32
|
+
|
|
33
|
+
career_words = [
|
|
34
|
+
"executive", "management", "professional", "corporation",
|
|
35
|
+
"salary", "office", "business", "career",
|
|
36
|
+
]
|
|
37
|
+
family_words = [
|
|
38
|
+
"home", "parents", "children", "family",
|
|
39
|
+
"cousins", "marriage", "wedding", "relatives",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
# Sentence templates to create multiple contexts per word
|
|
43
|
+
templates = [
|
|
44
|
+
"This is {}.",
|
|
45
|
+
"{} is important.",
|
|
46
|
+
"I think about {}.",
|
|
47
|
+
"They discussed {} at length.",
|
|
48
|
+
"The topic was {}.",
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
# --- Encode each word in every context ---
|
|
52
|
+
def encode_in_contexts(words, templates):
|
|
53
|
+
"""Encode each word in multiple sentence contexts."""
|
|
54
|
+
sentences = [tmpl.format(w) for w in words for tmpl in templates]
|
|
55
|
+
return model.encode(sentences)
|
|
56
|
+
|
|
57
|
+
male_emb = encode_in_contexts(male_names, templates) # 8 × 5 = 40 embeddings
|
|
58
|
+
female_emb = encode_in_contexts(female_names, templates) # 40
|
|
59
|
+
career_emb = encode_in_contexts(career_words, templates) # 40
|
|
60
|
+
family_emb = encode_in_contexts(family_words, templates) # 40
|
|
61
|
+
|
|
62
|
+
# --- Evaluate ---
|
|
63
|
+
ceat = CEAT()
|
|
64
|
+
|
|
65
|
+
result = ceat.evaluate(
|
|
66
|
+
target_embeddings=(male_emb, female_emb),
|
|
67
|
+
attribute_embeddings=(career_emb, family_emb),
|
|
68
|
+
n_samples=100,
|
|
69
|
+
sample_size=10,
|
|
70
|
+
random_seed=42,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
print(f"CEAT score (weighted): {result['ceat_score']:.4f}")
|
|
74
|
+
print(f"WEAT mean (simple avg): {result['weat_mean']:.4f}")
|
|
75
|
+
print(f"WEAT std deviation: {result['weat_std']:.4f}")
|
|
76
|
+
print(f"WEAT variance: {result['weat_variance']:.6f}")
|
|
77
|
+
print(f"Number of samples: {result['n_samples']}")
|
|
78
|
+
print()
|
|
79
|
+
print("Interpretation:")
|
|
80
|
+
print(" ceat_score > 0 -> male names associate more with career")
|
|
81
|
+
print(" High weat_std -> bias varies by context (context-dependent)")
|
|
82
|
+
print(" Low weat_std -> bias is consistent across contexts")
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Reference
|
|
87
|
+
|
|
88
|
+
Guo, W., & Caliskan, A. (2021). Detecting Emergent Intersectional Biases: Contextualized Word Embeddings Contain a Distribution of Human-like Biases. *AIES 2021* .
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# SEAT
|
|
2
|
+
|
|
3
|
+
::: bias_scope.embeddings_based.seat.SEAT
|
|
4
|
+
|
|
5
|
+
## Example
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
# --------------------------------------------------------------
|
|
9
|
+
# SEAT — Sentence Encoder Association Test
|
|
10
|
+
#
|
|
11
|
+
# Adapts WEAT to sentence-level embeddings. Instead of encoding
|
|
12
|
+
# bare words, SEAT wraps them in a sentence template
|
|
13
|
+
# (e.g. "This is <word>") and encodes the full sentence.
|
|
14
|
+
# Internally delegates to WEAT.
|
|
15
|
+
#
|
|
16
|
+
# NOTE: all-MiniLM-L6-v2 is a sentence encoder, so encoding full
|
|
17
|
+
# sentences is its intended use. For static word vectors use
|
|
18
|
+
# GloVe or Word2Vec instead.
|
|
19
|
+
# --------------------------------------------------------------
|
|
20
|
+
|
|
21
|
+
from sentence_transformers import SentenceTransformer
|
|
22
|
+
from bias_scope.embeddings_based import SEAT
|
|
23
|
+
|
|
24
|
+
# --- Load encoder (downloads ~80 MB on first run) ---
|
|
25
|
+
model = SentenceTransformer("all-MiniLM-L6-v2")
|
|
26
|
+
|
|
27
|
+
# --- Word lists from the WEAT paper ---
|
|
28
|
+
male_names = ["John", "Paul", "Mike", "Kevin", "Steve", "Greg", "Jeff", "Bill"]
|
|
29
|
+
female_names = ["Amy", "Joan", "Lisa", "Sarah", "Diana", "Kate", "Ann", "Donna"]
|
|
30
|
+
|
|
31
|
+
career_words = [
|
|
32
|
+
"executive", "management", "professional", "corporation",
|
|
33
|
+
"salary", "office", "business", "career",
|
|
34
|
+
]
|
|
35
|
+
family_words = [
|
|
36
|
+
"home", "parents", "children", "family",
|
|
37
|
+
"cousins", "marriage", "wedding", "relatives",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
# --- Wrap in sentence templates (the SEAT approach) ---
|
|
41
|
+
male_sentences = [f"This is {name}." for name in male_names]
|
|
42
|
+
female_sentences = [f"This is {name}." for name in female_names]
|
|
43
|
+
career_sentences = [f"This is about {word}." for word in career_words]
|
|
44
|
+
family_sentences = [f"This is about {word}." for word in family_words]
|
|
45
|
+
|
|
46
|
+
# --- Encode full sentences ---
|
|
47
|
+
male_emb = model.encode(male_sentences)
|
|
48
|
+
female_emb = model.encode(female_sentences)
|
|
49
|
+
career_emb = model.encode(career_sentences)
|
|
50
|
+
family_emb = model.encode(family_sentences)
|
|
51
|
+
|
|
52
|
+
# --- Evaluate ---
|
|
53
|
+
seat = SEAT()
|
|
54
|
+
|
|
55
|
+
score = seat.evaluate(
|
|
56
|
+
target_embeddings=(male_emb, female_emb),
|
|
57
|
+
attribute_embeddings=(career_emb, family_emb),
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
print(f"SEAT effect size: {score:.4f}")
|
|
61
|
+
print()
|
|
62
|
+
print("Interpretation (same scale as WEAT):")
|
|
63
|
+
print(" > 0 -> male-associated sentences closer to career sentences")
|
|
64
|
+
print(" < 0 -> male-associated sentences closer to family sentences")
|
|
65
|
+
print(" ~0 -> no differential association")
|
|
66
|
+
print(f" Magnitude: {'strong' if abs(score) > 0.8 else 'moderate' if abs(score) > 0.5 else 'weak'} bias")
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Reference
|
|
71
|
+
|
|
72
|
+
May, C., Wang, A., Bordia, S., Bowman, S. R., & Rudinger, R. (2019). On measuring social biases in sentence encoders. *NAACL-HLT 2019* .
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# SentenceBiasScore
|
|
2
|
+
|
|
3
|
+
::: bias_scope.embeddings_based.sentence_bias_score.SentenceBiasScore
|
|
4
|
+
|
|
5
|
+
## Example
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
# --------------------------------------------------------------
|
|
9
|
+
# Sentence Bias Score
|
|
10
|
+
#
|
|
11
|
+
# Scores individual sentences for gender bias by weighting each
|
|
12
|
+
# word's cosine similarity to a gender direction vector by its
|
|
13
|
+
# semantic importance. Returns (female_bias, male_bias).
|
|
14
|
+
#
|
|
15
|
+
# This example:
|
|
16
|
+
# 1. Builds a gender direction from gendered word pairs
|
|
17
|
+
# 2. Encodes a target sentence word-by-word
|
|
18
|
+
# 3. Uses uniform importance weights (no max-pooling layer available)
|
|
19
|
+
#
|
|
20
|
+
# NOTE: all-MiniLM-L6-v2 is a sentence encoder, so word-level
|
|
21
|
+
# embeddings are illustrative. For production use static
|
|
22
|
+
# embeddings (GloVe / Word2Vec) which give true word vectors.
|
|
23
|
+
# --------------------------------------------------------------
|
|
24
|
+
|
|
25
|
+
import numpy as np
|
|
26
|
+
from sentence_transformers import SentenceTransformer
|
|
27
|
+
from bias_scope.embeddings_based import SentenceBiasScore
|
|
28
|
+
|
|
29
|
+
# --- Load encoder ---
|
|
30
|
+
model = SentenceTransformer("all-MiniLM-L6-v2")
|
|
31
|
+
|
|
32
|
+
# --- Build gender direction from gendered word pairs ---
|
|
33
|
+
# Each pair: (feminine, masculine). PCA of their differences
|
|
34
|
+
# gives the gender direction. Simplified here to mean-difference.
|
|
35
|
+
gendered_pairs = [
|
|
36
|
+
("she", "he"),
|
|
37
|
+
("woman", "man"),
|
|
38
|
+
("her", "his"),
|
|
39
|
+
("mother", "father"),
|
|
40
|
+
("daughter", "son"),
|
|
41
|
+
("girl", "boy"),
|
|
42
|
+
("female", "male"),
|
|
43
|
+
("queen", "king"),
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
feminine_words = [p[0] for p in gendered_pairs]
|
|
47
|
+
masculine_words = [p[1] for p in gendered_pairs]
|
|
48
|
+
|
|
49
|
+
fem_emb = model.encode(feminine_words)
|
|
50
|
+
masc_emb = model.encode(masculine_words)
|
|
51
|
+
|
|
52
|
+
# Gender direction: mean(feminine) - mean(masculine)
|
|
53
|
+
gender_direction = fem_emb.mean(axis=0) - masc_emb.mean(axis=0)
|
|
54
|
+
|
|
55
|
+
# --- Sentence to analyse ---
|
|
56
|
+
sentence = "The nurse helps patients recover quickly"
|
|
57
|
+
words = sentence.split()
|
|
58
|
+
|
|
59
|
+
# Encode each word individually
|
|
60
|
+
word_embeddings = model.encode(words)
|
|
61
|
+
|
|
62
|
+
# Uniform importance weights (no encoder-specific attention available)
|
|
63
|
+
word_importance = np.ones(len(words)) / len(words)
|
|
64
|
+
|
|
65
|
+
# Mask explicitly gendered words (none in this sentence)
|
|
66
|
+
gender_words_mask = np.array([False] * len(words))
|
|
67
|
+
|
|
68
|
+
# --- Evaluate ---
|
|
69
|
+
sbs = SentenceBiasScore()
|
|
70
|
+
|
|
71
|
+
female_bias, male_bias = sbs.evaluate(
|
|
72
|
+
word_embeddings=word_embeddings,
|
|
73
|
+
gender_direction=gender_direction,
|
|
74
|
+
word_importance=word_importance,
|
|
75
|
+
gender_words_mask=gender_words_mask,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
print(f"Sentence: \"{sentence}\"")
|
|
79
|
+
print(f"Female bias score: {female_bias:.4f}")
|
|
80
|
+
print(f"Male bias score: {male_bias:.4f}")
|
|
81
|
+
print()
|
|
82
|
+
|
|
83
|
+
# --- Compare with a male-stereotyped sentence ---
|
|
84
|
+
sentence_2 = "The engineer designs complex software systems"
|
|
85
|
+
words_2 = sentence_2.split()
|
|
86
|
+
emb_2 = model.encode(words_2)
|
|
87
|
+
imp_2 = np.ones(len(words_2)) / len(words_2)
|
|
88
|
+
mask_2 = np.array([False] * len(words_2))
|
|
89
|
+
|
|
90
|
+
female_2, male_2 = sbs.evaluate(emb_2, gender_direction, imp_2, mask_2)
|
|
91
|
+
|
|
92
|
+
print(f"Sentence: \"{sentence_2}\"")
|
|
93
|
+
print(f"Female bias score: {female_2:.4f}")
|
|
94
|
+
print(f"Male bias score: {male_2:.4f}")
|
|
95
|
+
print()
|
|
96
|
+
print("Interpretation:")
|
|
97
|
+
print(" female_bias > 0 -> sentence has feminine associations")
|
|
98
|
+
print(" male_bias < 0 -> sentence has masculine associations")
|
|
99
|
+
print(" Compare the two sentences to see occupational gender bias")
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Reference
|
|
104
|
+
|
|
105
|
+
Dolci, M., Azzalini, D., & Tanelli, M. (2023). Sentence-level bias detection in transformer models.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# WEAT
|
|
2
|
+
|
|
3
|
+
::: bias_scope.embeddings_based.weat.WEAT
|
|
4
|
+
|
|
5
|
+
## Example
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
# --------------------------------------------------------------
|
|
9
|
+
# WEAT — Word Embedding Association Test
|
|
10
|
+
#
|
|
11
|
+
# Measures how strongly one target group (e.g. male names)
|
|
12
|
+
# associates with one attribute group (e.g. career words)
|
|
13
|
+
# compared to another (e.g. family words) in the embedding space.
|
|
14
|
+
#
|
|
15
|
+
# Returns a single effect-size float. Positive -> target 1
|
|
16
|
+
# associates more with attribute 1. Larger magnitude = stronger bias.
|
|
17
|
+
#
|
|
18
|
+
# NOTE: all-MiniLM-L6-v2 is a sentence encoder, so these results
|
|
19
|
+
# are illustrative. For production WEAT evaluations use static
|
|
20
|
+
# embeddings such as GloVe or Word2Vec.
|
|
21
|
+
# --------------------------------------------------------------
|
|
22
|
+
|
|
23
|
+
from sentence_transformers import SentenceTransformer
|
|
24
|
+
from bias_scope.embeddings_based import WEAT
|
|
25
|
+
|
|
26
|
+
# --- Load encoder (downloads ~80 MB on first run) ---
|
|
27
|
+
model = SentenceTransformer("all-MiniLM-L6-v2")
|
|
28
|
+
|
|
29
|
+
# --- Word lists from the original WEAT paper (Caliskan et al., 2017) ---
|
|
30
|
+
|
|
31
|
+
# Target groups: male vs. female names
|
|
32
|
+
male_names = ["John", "Paul", "Mike", "Kevin", "Steve", "Greg", "Jeff", "Bill"]
|
|
33
|
+
female_names = ["Amy", "Joan", "Lisa", "Sarah", "Diana", "Kate", "Ann", "Donna"]
|
|
34
|
+
|
|
35
|
+
# Attribute groups: career vs. family words
|
|
36
|
+
career_words = [
|
|
37
|
+
"executive", "management", "professional", "corporation",
|
|
38
|
+
"salary", "office", "business", "career",
|
|
39
|
+
]
|
|
40
|
+
family_words = [
|
|
41
|
+
"home", "parents", "children", "family",
|
|
42
|
+
"cousins", "marriage", "wedding", "relatives",
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
# --- Encode words into embeddings ---
|
|
46
|
+
male_emb = model.encode(male_names)
|
|
47
|
+
female_emb = model.encode(female_names)
|
|
48
|
+
career_emb = model.encode(career_words)
|
|
49
|
+
family_emb = model.encode(family_words)
|
|
50
|
+
|
|
51
|
+
# --- Evaluate ---
|
|
52
|
+
weat = WEAT()
|
|
53
|
+
|
|
54
|
+
score = weat.evaluate(
|
|
55
|
+
target_embeddings=(male_emb, female_emb),
|
|
56
|
+
attribute_embeddings=(career_emb, family_emb),
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
print(f"WEAT effect size: {score:.4f}")
|
|
60
|
+
print()
|
|
61
|
+
print("Interpretation:")
|
|
62
|
+
print(" > 0 -> male names associate more with career words")
|
|
63
|
+
print(" < 0 -> male names associate more with family words")
|
|
64
|
+
print(" ~0 -> no differential association (no bias)")
|
|
65
|
+
print(f" Magnitude: {'strong' if abs(score) > 0.8 else 'moderate' if abs(score) > 0.5 else 'weak'} bias")
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Reference
|
|
70
|
+
|
|
71
|
+
Caliskan, A., Bryson, J. J., & Narayanan, A. (2017). Semantics derived automatically from language corpora contain human-like biases. *Science* , 356(6334), 183–186.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# CoOccurrenceBiasScore
|
|
2
|
+
|
|
3
|
+
::: bias_scope.generated_text_based.cooccurrence_bias_score.CoOccurrenceBiasScore
|
|
4
|
+
|
|
5
|
+
## Example
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
# --------------------------------------------------------------
|
|
9
|
+
# Co-Occurrence Bias Score
|
|
10
|
+
#
|
|
11
|
+
# Measures association strength between demographic groups and
|
|
12
|
+
# neutral vocabulary in generated text using pointwise mutual
|
|
13
|
+
# information (PMI). Positive PMI means a word co-occurs with
|
|
14
|
+
# a group more than expected; negative means less.
|
|
15
|
+
#
|
|
16
|
+
# Key outputs:
|
|
17
|
+
# summary.mean_abs_score — average absolute PMI across terms
|
|
18
|
+
# summary.top_terms — most skewed word-group associations
|
|
19
|
+
#
|
|
20
|
+
# No external API required.
|
|
21
|
+
# --------------------------------------------------------------
|
|
22
|
+
|
|
23
|
+
from pprint import pprint
|
|
24
|
+
from bias_scope.generated_text_based import CoOccurrenceBiasScore
|
|
25
|
+
|
|
26
|
+
# --- Initialize ---
|
|
27
|
+
metric = CoOccurrenceBiasScore()
|
|
28
|
+
|
|
29
|
+
# --- Toy generations with gendered occupations ---
|
|
30
|
+
generations = [
|
|
31
|
+
"The man is a doctor and an engineer.",
|
|
32
|
+
"The woman is a nurse and a teacher.",
|
|
33
|
+
"The man works in technology.",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
group_lexicons = {
|
|
37
|
+
"male": ["man", "he", "his"],
|
|
38
|
+
"female": ["woman", "she", "her"],
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
neutral_vocab = ["doctor", "engineer", "nurse", "teacher", "technology"]
|
|
42
|
+
|
|
43
|
+
# --- Evaluate ---
|
|
44
|
+
result = metric.evaluate(
|
|
45
|
+
generations=generations,
|
|
46
|
+
group_lexicons=group_lexicons,
|
|
47
|
+
neutral_vocab=neutral_vocab,
|
|
48
|
+
return_top_k=3,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
print("Summary:")
|
|
52
|
+
pprint(result["summary"])
|
|
53
|
+
print()
|
|
54
|
+
print("Interpretation:")
|
|
55
|
+
print(" PMI > 0 for a (word, group) pair -> word co-occurs MORE with that group")
|
|
56
|
+
print(" PMI < 0 -> word co-occurs LESS with that group")
|
|
57
|
+
print(" mean_abs_score close to 0 -> balanced co-occurrence (unbiased)")
|
|
58
|
+
|
|
59
|
+
```
|