This repo is a lightweight ML/NLP exploration for studying bias/fairness in:
- Structured sentencing outcomes (tabular ML):
DISPOSIT(disposition) andSENTTOT(sentence length) - Judicial text/opinion data (NLP): CAP (Caselaw Access Project) HTML/JSON + metadata
The project includes both notebook exploration and reusable pipeline components under src/ and scripts/.
src/- reusable components (paths, fairness metrics, USSC row→text serialization, multi-task DistilBERT)
scripts/- runnable CLI scripts to train/evaluate models and build datasets
cap_data/html/: CAP opinion HTML (extractable opinion text)json/: CAP opinion JSON (case metadata + citations + structure)metadata/: CAP metadata (CasesMetadata.jsonis a list;VolumeMetadata.jsonis a dict)
notebooks/: analysis pipeline
notebooks/2_Data_Exploration_Final.ipynbnotebooks/3_Feature_Engineering.ipynbnotebooks/4_Baseline_Modeling.ipynb- Baseline classification/regression + simple group metrics
notebooks/6_NLP_CAP.ipynb- Extracts CAP metadata + opinion text, basic NLP exploration
notebooks/5_Advanced_Modeling_and_Fairness_Techniques.ipynb- Guarded scaffold (only runs sections if required inputs exist)
- Multi-task DistilBERT on sentencing data: joint trial occurrence classification + sentence length regression, with group fairness slices (demographic parity, TPR/FPR). See
scripts/train_multitask_ussc.pyandsrc/models/multitask_distilbert.py. - Judicial text NLP on CAP opinions: dataset build from CAP artifacts, plus sentiment + LDA topic modeling and an optional DistilBERT classifier. See
scripts/build_legal_text_dataset.py,notebooks/6_NLP_CAP.ipynb, andscripts/judicial_text_bert_classifier.py.
Install dependencies:
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtNotes:
- NLP components (
transformers,torch,spacy,xgboost) are optional but included. - If running BERT sections, you may need model downloads/caches.