A Python-based project for identifying possible gender bias in sentences by comparing gender-related subjects and their associated objects using natural language processing and similarity analysis.
This project analyzes text to detect whether a sentence may contain gender bias. It uses:
- text preprocessing
- subject and object extraction
- gender-related word detection
- word similarity comparison using CBOW and Skip-Gram models
The goal is to estimate whether the language in a sentence leans toward a male or female association based on contextual similarity.
Gender_bias.py– main bias detection logicData analysis code.py– data analysis and experimentation scriptspractice.py– additional exploratory codetext-and-id.txt– dataset used for sentence analysispairs-label-training (1).txt– label data used for evaluationREADME.md– project documentation
- Python 3.9 or later
- pip
pip install -r requirements.txt
python -m spacy download en_core_web_sm
python -c "import nltk; nltk.download('punkt')"python "Gender_bias.py"You can also run the analysis script:
python "Data analysis code.py"Some scripts contain hard-coded Windows file paths to local dataset files. Before running them, update those paths to match your machine or dataset location.
Example:
file_name = 'D:\\Python\\Data sets\\...\\text-and-id.txt'Replace this with the correct path for your environment.
The project follows a basic NLP workflow:
- Clean the text and remove punctuation.
- Extract sentence tokens.
- Identify subject and object phrases.
- Detect gender-related terms.
- Compare similarity between gender-related terms and object terms.
- Evaluate bias based on the difference in similarity scores.
The dataset contains sentence-level text and associated labels used for evaluating bias detection. The project also compares model outputs with training labels to estimate accuracy.
This is a research-oriented prototype and is not a production-grade fairness model. It depends heavily on:
- dataset quality
- language coverage
- word embeddings
- hard-coded preprocessing rules
No license has been added to this repository yet.