Bias Manager is an innovative Flask-based module that uses state-of-the-art pre-trained transformer models to detect and explain biases in sentences. Whether you're concerned about gender bias, hate speech, or political bias, this tool helps identify and analyze various forms of bias within textual data.
Ensure you have the following installed:
- Python 3.8 as a base programming environment.
- Flask for server-side management.
- PyTorch for handling the model training and inference.
- Transformers for state-of-the-art NLP models.
- Captum for explainability.
git clone https://github.com/ngi-indi/module-bias-manager.git
cd module-bias-manager
- On Windows:
python -m venv venv
.\venv\Scripts\activate
- On macOS/Linux:
python3 -m venv venv
source venv/bin/activate
Install the required Python packages by running:
pip install -r ./app/requirements.txt
- Download the pre-trained model weights and place them in the appropriate directory:
models/
. - Ensure you have all necessary models downloaded and placed in the relevant directory.
The web-based client provides a simple UI for interacting with the bias detection system.
python ./app/app.py
Open your browser and go to http://127.0.0.1:5000/.
- Choose the type of bias you want to check (e.g., gender bias, hate speech).
- Enter a sentence and click "Check" to get predictions.
- The server will return whether the sentence contains bias.
- An explanation highlighting the important words will be displayed.
The ./app/demo/client.py
script offers a command-line approach.
Open ./app/demo/client.py
and change the following variables to your desired values:
MODEL = 'convbert' # Available options: bart, convbert, electra, gpt2, roberta, t5, etc.
TASK = 'gender-bias' # Available bias tasks: cognitive-bias, gender-bias, hate-speech, etc.
SENTENCE = 'I only read news articles that support my belief that climate change is a hoax because everything else seems exaggerated.'
python ./app/demo/client.py
- The script will print whether the sentence contains bias.
- An explanation will be provided in the terminal.
Run the following command to build the Docker image:
docker build -t biasmanager .
This will create a Docker image named biasmanager
.
Once the image is built, you can run it using the following command
docker run -d --name biasmanager --network indi_network -p 5000:5000 biasmanager
This command maps port 5000 on your local machine to port 5000 inside the container, allowing you to access the Flask app at http://localhost:5000.
- If you find a bug, please open an issue.
- To request a feature, feel free to open an issue as well.
- Fork the repository by clicking the "Fork" button at the top right of this page.
- Clone your fork locally:
git clone https://github.com/ngi-indi/module-bias-manager.git
- Create a new branch for your feature or bug fix:
git checkout -b feature-branch
- Make your changes. Please follow the existing code style and conventions.
- Commit your changes with a descriptive commit message:
git commit -m "Add new feature: explanation of bias model predictions"
- Push to your fork:
git push origin feature-branch
- Open a pull request from your fork’s branch to the main branch of this repository.
- Describe the changes you’ve made in the pull request description.
- Ensure that your pull request references any relevant issues.
This project is licensed under the GNU General Public License v3.0 License - see the LICENSE file for details.
For any questions or support, please reach out to:
- University of Cagliari: [email protected], [email protected], [email protected], [email protected]
- R2M Solution: [email protected]
- Website: Coming soon!