This repository contains the official PyTorch implementation of FA-BUHS (Fairness-Aware Biased User History Synthesis), an advanced long-tail recommendation framework.
FA-BUHS introduces a paradigm shift from post-hoc correction to upstream fairness intervention. By actively synthesizing a fairness-constrained interaction history, it mitigates popularity and demographic biases at their source before latent embeddings are formed. It further utilizes conditional adversarial debiasing to scrub demographic leakage from representations while strictly preserving collaborative filtering signals.
- Upstream Fairness Intervention: Modifies the user interaction history prior to representation learning, acting as a structural causal intervention.
- Fairness-Constrained Sampling: Generates synthetic interaction histories that balance long-tail exposure with demographic group representation.
- History Synthesis Variants: Supports multiple aggregation mechanisms including
Mean,Attention, andGRU-based temporal modeling. - Conditional Adversarial Debiasing: Employs Gradient Reversal Layers (GRL) conditioned on the interaction label to remove sensitive attributes without destroying utility.
- Post-Hoc Fairness Re-ranking: (Optional) A lightweight exposure-aware re-ranking step for inference-time fairness guarantees.
- Built-in Evaluation: Computes Position-Discounted Gini index, Demographic Parity, and Exposure Fairness alongside standard recommendation metrics (HR@K, NDCG@K).
├── main.py # Main training and evaluation loop
├── fairness_utils.py # Core fairness logic (Sampling, Metrics, GRL, Re-ranking)
├── model/
│ ├── __init__.py # Model configurations and registry
│ └── sparsenn.py # Two-tower Neural architectures and Synthesis modules
├── data/
│ ├── dataloader.py # PyTorch Dataset and Collator classes
│ ├── datareader.py # Raw dataset parsers (ML-1M, BookCrossing)
│ └── structs.py # Interaction graph structures and data splits
└── README.md
git clone [https://github.com/prateek4ai/fairnessawarebuhs.git](https://github.com/prateek4ai/fairnessawarebuhs.git)
cd fairnessawarebuhspip install torch numpy pandas scipy sentence-transformers wandb absl-py tqdmThe framework is highly configurable via command-line flags powered by absl-py. Experiment tracking is integrated natively with Weights & Biases (wandb).
To run the standard long-tail synthesis without fairness constraints on MovieLens-1M:
python main.py \
--dataset_dir="./datasets" \
--dataset="ml" \
--enable_fairness=False \
--synthesis_type="gru" \
--sample_size=15 \
--epochs=50 \
--batch_size=2048 \
--device="cuda"To enable the full FA-BUHS pipeline (Fairness-Constrained Sampling + Conditional Adversarial Debiasing):
python main.py \
--dataset_dir="./datasets" \
--dataset="ml" \
--enable_fairness=True \
--fairness_sampling=True \
--synthesis_type="gru" \
--sample_size=15 \
--adversarial_lambda_user=0.1 \
--adversarial_lambda_item=0.1 \
--fairness_weight=0.5 \
--epochs=50 \
--device="cuda"You can apply the optional fairness-aware re-ranking during the evaluation phase:
python main.py \
--dataset="ml" \
--enable_fairness=True \
--rerank_fair=True \
--rerank_alpha=0.2 \
--exposure_floor=0.1| Flag | Type | Default | Description |
|---|---|---|---|
--dataset |
str | "ml" |
Dataset to use (ml for MovieLens, bx for BookCrossing). |
--enable_fairness |
bool | False |
Enable the overarching fairness framework. |
--fairness_sampling |
bool | False |
Enable upstream fairness-constrained sampling. |
--synthesis_type |
str | "mean" |
User history synthesis method (mean, attention, or gru). |
--sample_size |
int | 15 |
Synthesis horizon (N). Optimal recommended value is 15. |
--adversarial_lambda_user |
float | 0.1 |
Weight for the user-side conditional adversarial loss (λ_u). |
--adversarial_lambda_item |
float | 0.1 |
Weight for the item-side conditional adversarial loss (λ_i). |
--fairness_weight |
float | 0.5 |
Interpolation weight (α) controlling catalog vs. group parity. |
If you use this code or framework in your research, please cite our paper:
@article{FA_BUHS_2026,
author = {},
title = {When Popularity Fails: Fair and Equitable Long-Tail Recommendation with Fairness-Constrained Learning},
journal = {....},
year = {2026}
}Note: Please update the citation block with the exact publication details once officially published.
This project is licensed under the MIT License — see the LICENSE file for details.