Skip to content

HrishikeshVish/Fairpy

Repository files navigation

Python Huggingface Pytorch Cuda SkLearn Scipy Keras Tensorflow NLTK

Fairpy is an open source Toolkit for measuring and mitigating biases in large pretrained language models. It currently supports a wide range of bias detection tools and Bias Mitigation techniques along with interfaces for augmenting corpus, plugging in custom language models and extending the package to include new techniques.

Paper Link https://arxiv.org/abs/2302.05508

Features

  • Bias Detection Methods
    • Top K Overlap
    • Hellinger Distance
    • F1 Score
    • Honest
    • Log Probability
    • StereoSet
    • WEAT/SEAT Score
  • Bias Mitigation Methods
    • DiffPruning
    • Entropy Attention Regularization
    • Counter Factual Data Augmentation
    • Null Space Projection
    • Self Debias (Incomplete)
    • Dropout Regularization
  • Models
    • CTRL
    • GPT-2
    • OpenAI-GPT
    • TransfoXL
    • BERT
    • DistilBERT
    • RoBERTa
    • AlBERT
    • XLM
    • XLNet

Usage

Bias Detection in Masked Language Models

from fairpy import BiasDetection.BiasDetectionMetrics as BiasDetectionMetrics
maskedObj = BiasDetectionMetrics.MaskedLMBiasDetection(model_class = 'bert-base-uncased')
maskedObj.WeatScore(bias_type='health')

Bias Detection in Causal Language Models

from fairpy import BiasDetection.BiasDetectionMetrics as BiasDetectionMetrics
causalObj = BiasDetectionMetrics.CausalLMBiasDetection(model_class = 'gpt2')
causalObj.stereoSetScore(bias_type='gender')

Bias Mitigation in Masked Language Models

from fairpy import BiasMitigation.BiasMitigationMethods as BiasMitigationMethods
MaskedMitObj = BiasMitigationMethods.MaskedLMBiasMitigation(model_class='bert-base-uncased')
model, tokenizer = MaskedMitObj.NullSpaceProjection('bert-base-uncased', 'BertForMaskedLM', 'race', train_data='yelp_sm')

Bias Detection in Causal Language Models

from fairpy import BiasMitigation.BiasMitigationMethods as BiasMitigationMethods
CausalMitObj = BiasMitigationMethods.CausalLMBiasMitigation(model_class='gpt2')
model, tokenizer = CausalMitObj.DropOutDebias('gpt2', 'religion', train_data='yelp_sm')

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published