# Supplementary Code and Data

This package accompanies the manuscript "Quantifying and Mitigating Gender Bias in
Legal Large Language Models: A Counterfactual Fairness Framework".

## Contents

- `00_data_collection/` - scripts for collecting and processing source legal
  judgments (CAIL dataset download, court-decision scraping, preprocessing)
- `01_bias_detection.py` - runs the counterfactual gender-substitution audit
  across the evaluated LLMs and computes the Bias Shift Rate (Delta)
- `02_data_debiasing.py` - constructs the data-aligned and KL-regularised
  training sets used in the Fairness-Constrained Fine-Tuning (FCFT) ablation
- `03_model_finetune.py` - fine-tunes the base model under the FCFT ablation
  conditions (A-D)
- `04_evaluation.py` - evaluates fine-tuned model checkpoints on the audit set
- `05_visualization.py` - generates the manuscript figures (fig1-fig6)
- `05b_csc_analysis.py` - Counterfactual Symmetric Calibration (CSC)
  post-processing analysis
- `06_frp_experiment.py` - formula-anchoring / robustness probe experiment
- `config.py` - shared configuration (model lists, prompt templates, paths).
  All API keys are read from environment variables and are not included.
- `data/` - intermediate and final result tables (bias detection results,
  counterfactual matrices, debiasing training pairs)
- `figures/` - generated figures corresponding to the manuscript
- `results/` - evaluation and ablation result tables
- `requirements.txt` - Python package dependencies

## Reproducing the results

1. Install dependencies: `pip install -r requirements.txt`
2. Set the required API keys as environment variables (see comments in
   `config.py`)
3. Run scripts `01` through `06` in numerical order; each script reads its
   inputs from `data/` and writes outputs back to `data/`, `results/`, or
   `figures/`

## Notes on anonymisation

This package has been prepared for double-blind review. Author-identifying
information has been removed from filenames, code comments, and configuration
files. No personal API credentials are included; all keys must be supplied by
the user via environment variables.
