This project implements and trains Word2Vec models (CBOW and Skip-gram) from scratch and performs gender bias analysis on word embeddings using GloVe embeddings.
The project is divided into two parts:
- CBOW (Continuous Bag of Words): Predicts center words from surrounding context
- Skip-gram: Predicts surrounding words from center words
- Both models use shared embedding weights between input and output layers
- Models are trained from scratch on a text corpus
-
Gender Subspace Identification: Uses PCA to identify gender bias direction in embedding space
-
Direct Bias Measurement: Quantifies gender bias in profession embeddings
-
Hard Debiasing: Removes gender bias from embeddings using subspace projection
-
WEAT (Word Embedding Association Test): Measures implicit bias in word associations
Both CBOW and Skip-gram share the same underlying architecture:
- Embedding Layer: Maps word indices to dense vectors (300 dimensions)
- Projection Layer: Maps embeddings to vocabulary logits (shared weights with embedding)
- No Hidden Layers: Simplified NNLM architecture without hidden layers
- Input: Lists of surrounding word indices (window size = 3)
- Processing: Sums embeddings of surrounding words
- Output: Predicts center word
- Loss: Cross-entropy over vocabulary
-
Input: Center word indices
-
Processing: Direct embedding lookup
-
Output: Predicts surrounding words
-
Loss: Cross-entropy over vocabulary
- Initial Loss: 60.22
- Final Loss: 4.81
-
Initial Loss: 10.16
-
Final Loss: 5.53
CBOW Results: ['woman', 'a', 'another', 'in', 'is']
Skip-gram Results: ['a', 'woman', 'is', 'in', 'and']
Expected Answer: 'boy'
CBOW Results: ['boy', 'little', 'a', 'young', 'is']
Skip-gram Results: ['boy', 'little', 'young', 'is', 'a']
-
Both models successfully solve the analogy task
-
Skip-gram shows slightly better ranking of semantically related words
-
Function words still appear but don't dominate the results
-
Models capture gender relationships (man vs woman) and age relationships (girl vs boy)
- Dimension: (1, 300) - Single principal component extracted
- Method: PCA on normalized gender attribute word pairs
- Purpose: Identifies the primary direction of gender bias in embedding space
Word "man" onto Gender Direction: -1.5679 -> association with masculine direction
Most Feminine Professions :
- dietitian
- housekeeper
- receptionist
- childcare worker
- paralegal
- registered nurse
- vocational nurse
- hairdresser
- dental hygienist
- salesperson
Most Masculine Professions :
- operating engineer
- secretary
- conductor
- crossing guard
- director of religious activities
- mobile equipment mechanic
- lodging manager
- security system installer
- judge
- mining machine operator
Direct Bias Metric: 0.5261
-
Scale: 0 (no bias) to 1 (maximum bias)
-
Interpretation: High gender bias detected in profession embeddings
- Method: Subtracts projections onto gender subspace from all embeddings
Direct Bias (Debiased): 0.00
- Reduction: From 0.5261 -> 0.00
- Success: Hard debiasing effectively neutralizes gender bias in embeddings
Test Configuration:
- Target Sets: X = [math, algebra, geometry, ...], Y = [poetry, art, dance, ...]
- Purpose: Tests for math-male/arts-female stereotype after debiasing
P-value: 0.03
- Interpretation: Statistically significant association remains (p < 0.05)
Test Configuration:
- Target Sets: X = ["doctor", "mechanic", "engineer"], Y = ["nurse", "artist", "teacher"]
- Attribute Sets: A = ["male", "man", "boy", ...], B = ["female", "woman", "girl", ...]
Results:
- WEAT Association (doctor): 0.0175
- Positive value indicates 'doctor' is more associated with masculine attributes
- WEAT Differential Association: 0.3557
- Strong positive value indicates systematic bias
- X words (doctor, mechanic, engineer) are more associated with masculine attributes
- Y words (nurse, artist, teacher) are more associated with feminine attributes
- Word2Vec: Mikolov et al., "Efficient Estimation of Word Representations in Vector Space", 2013. https://arxiv.org/abs/1301.3781
- GloVe: Pennington et al., "GloVe: Global Vectors for Word Representation", 2014. https://nlp.stanford.edu/projects/glove/
- WinoBias: Zhao et al., "Gender Bias in Coreference Resolution: Evaluation and Debiasing Methods", 2018. https://aclanthology.org/N18-2003/
- BERT Gender Bias: Bartl et al., "Unmasking Contextual Stereotypes: Measuring and Mitigating BERT's Gender Bias", 2020. https://arxiv.org/abs/2010.14534