-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
511 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Minimal makefile for Sphinx documentation | ||
# | ||
|
||
# You can set these variables from the command line, and also | ||
# from the environment for the first two. | ||
SPHINXOPTS ?= | ||
SPHINXBUILD ?= sphinx-build | ||
SOURCEDIR = source | ||
BUILDDIR = build | ||
|
||
# Put it first so that "make" without argument is like "make help". | ||
help: | ||
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) | ||
|
||
.PHONY: help Makefile | ||
|
||
# Catch-all target: route all unknown targets to Sphinx using the new | ||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). | ||
%: Makefile | ||
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
@ECHO OFF | ||
|
||
pushd %~dp0 | ||
|
||
REM Command file for Sphinx documentation | ||
|
||
if "%SPHINXBUILD%" == "" ( | ||
set SPHINXBUILD=sphinx-build | ||
) | ||
set SOURCEDIR=source | ||
set BUILDDIR=build | ||
|
||
%SPHINXBUILD% >NUL 2>NUL | ||
if errorlevel 9009 ( | ||
echo. | ||
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx | ||
echo.installed, then set the SPHINXBUILD environment variable to point | ||
echo.to the full path of the 'sphinx-build' executable. Alternatively you | ||
echo.may add the Sphinx directory to PATH. | ||
echo. | ||
echo.If you don't have Sphinx installed, grab it from | ||
echo.https://www.sphinx-doc.org/ | ||
exit /b 1 | ||
) | ||
|
||
if "%1" == "" goto help | ||
|
||
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% | ||
goto end | ||
|
||
:help | ||
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% | ||
|
||
:end | ||
popd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
alabaster==0.7.12 | ||
Sphinx==5.1.0 | ||
sphinx-rtd-theme==1.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Configuration file for the Sphinx documentation builder. | ||
# | ||
# For the full list of built-in configuration values, see the documentation: | ||
# https://www.sphinx-doc.org/en/master/usage/configuration.html | ||
|
||
# -- Project information ----------------------------------------------------- | ||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information | ||
import os | ||
import sys | ||
import sphinx_rtd_theme | ||
|
||
html_theme = "sphinx_rtd_theme" | ||
|
||
sys.path.insert(0, os.path.abspath("../../src/")) | ||
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] | ||
|
||
project = "fairgrad" | ||
copyright = "2022, Gaurav Maheshwari, Michael Perrot" | ||
author = "Gaurav Maheshwari, Michael Perrot" | ||
release = "0.1.1" | ||
|
||
# -- General configuration --------------------------------------------------- | ||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration | ||
|
||
extensions = [ | ||
"sphinx.ext.autodoc", | ||
"sphinx.ext.coverage", | ||
"sphinx.ext.napoleon", | ||
"sphinx.ext.intersphinx", | ||
] | ||
|
||
templates_path = ["_templates"] | ||
exclude_patterns = [] | ||
|
||
html_static_path = ["_static"] | ||
|
||
intersphinx_mapping = {"python": ("http://docs.python.org/3", None)} | ||
|
||
autodoc_typehints = "description" | ||
|
||
|
||
# -- Options for HTML output ------------------------------------------------- | ||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output | ||
|
||
html_theme = "alabaster" | ||
html_static_path = ["_static"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
Welcome to fairgrad's documentation! | ||
==================================== | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
:caption: Contents: | ||
|
||
introduction.rst | ||
reference.rst | ||
|
||
Indices and tables | ||
================== | ||
|
||
* :ref:`genindex` | ||
* :ref:`modindex` | ||
* :ref:`search` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
Introduction | ||
------------ | ||
|
||
FairGrad, is an easy to use general purpose approach to enforce | ||
fairness for gradient descent based methods. The core idea is to enforce fairness by iteratively learns | ||
group specific weights based on whether they are advantaged or not. FairGrad is: | ||
|
||
* Simple and easy to integrate with no significant overhead | ||
* Supports Multiclass problems and can work with any gradient based methods | ||
* Supports various group fairness notions including exact and approximate fairness | ||
* Is competitive on various tasks including complex NLP and CV ones | ||
|
||
|
||
Installation | ||
------------ | ||
|
||
You can install FairGrad from PyPI with `pip` or your favorite package manager:: | ||
|
||
pip install fairgrad | ||
|
||
|
||
Quick Start | ||
------------ | ||
|
||
To use fairgrad simply replace your pytorch cross entropy loss with | ||
fairgrad cross entropy loss. Alongside, regular pytorch cross entropy arguments, | ||
it expects following *extra* arguments:: | ||
|
||
y_train (np.asarray[int], Tensor, optional): All train example's corresponding label | ||
s_train (np.asarray[int], Tensor, optional): All train example's corresponding sensitive attribute. This means if there | ||
are 2 sensitive attributes, with each of them being binary. For instance gender - (male and female) and | ||
age (above 45, below 45). Total unique sentive attributes are 4. | ||
fairness_measure (string): Currently we support "equal_odds", "equal_opportunity", and "accuracy_parity". | ||
epsilon (float, optional): The slack which is allowed for the final fairness level. | ||
fairness_rate (float, optional): Parameter which intertwines current fairness weights with sum of previous fairness rates. | ||
|
||
Usage Example | ||
------------- | ||
|
||
Below is a simple example:: | ||
|
||
>>> from fairgrad.torch import CrossEntropyLoss | ||
>>> input = torch.randn(10, 5, requires_grad=True) | ||
>>> target = torch.empty(10, dtype=torch.long).random_(2) | ||
>>> s = torch.empty(10, dtype=torch.long).random_(2) # protected attribute | ||
>>> loss = CrossEntropyLoss(y_train = target, s_train = s, fairness_measure = 'equal_odds') | ||
>>> output = loss(input, target, s, mode='train') | ||
>>> output.backward() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Reference | ||
========= | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
:caption: Contents: | ||
|
||
reference/fairness_function.rst | ||
reference/torch/cross_entropy.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
fairness.functions | ||
======================== | ||
.. automodule:: fairgrad.fairness_functions | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
fairgrad.torch.cross_entropy | ||
============================= | ||
.. automodule:: fairgrad.torch.cross_entropy | ||
:members: |
Oops, something went wrong.