File size: 3,514 Bytes
287e418 6f5156a 287e418 6f5156a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | ---
license: mit
pretty_name: "LEGEX Code: Scrapers, Inference and Evaluation Pipeline"
tags:
- legal
- benchmark
- code
- llm-evaluation
- information-extraction
---
# LEGEX Code, Scrapers, Inference and Evaluation Pipeline
Python source for the LEGEX benchmark of civil-judgment review-table
extraction. This repository contains:
- Scrapers for 19 jurisdictions (per-court HTML / API / HuggingFace
pull) in [`legex/scrapers/`](legex/scrapers/).
- Inference pipeline that calls Harvey, Gemini and OpenAI APIs against
a schema-constrained 14-field review table
([`legex/inference.py`](legex/inference.py),
[`legex/harvey.py`](legex/harvey.py),
[`legex/models/classification.py`](legex/models/classification.py)).
- Evaluation that compares system outputs against expert-coded gold
cells ([`legex/evaluation.py`](legex/evaluation.py)), aggregates across
jurisdictions ([`legex/analysis.py`](legex/analysis.py)), and renders
paper tables ([`legex/quant_results.py`](legex/quant_results.py)).
- Conversion script [`convert_goldenset_to_jsonl.py`](convert_goldenset_to_jsonl.py)
— turns the source XLSX goldensets into the JSONL format used by
[`legexbenchmark/goldensets`](https://huggingface.co/datasets/legexbenchmark/goldensets).
## Setup
```bash
git clone https://huggingface.co/datasets/legexbenchmark/code legex-code
cd legex-code
uv sync
cp .env.template .env
```
Required tokens depend on which scrapers / models you run, see
[`.env.template`](.env.template).
## End-to-end workflow
```bash
# Acquire raw judgments per jurisdiction.
uv run legex-run
# Run inference for one system on one jurisdiction, Harvey has do be done separately as this is a commercial tool
uv run legex-classify --country us --model gpt-5.4-mini --full_text
# Evaluate one system on one jurisdiction.
uv run legex-evaluate --country us --system gpt
# Aggregate across all 12 evaluated jurisdictions and 3 systems.
uv run legex-analysis --out data/analysis
# Render the paper-headline LaTeX table.
uv run legex-quant-results \
--input data/analysis/per_country_per_column.csv \
--out data/analysis/quant_results.tex
```
To evaluate against the published goldensets and inference outputs, pull
the two data repos into the expected layout:
```bash
huggingface-cli download legexbenchmark/goldensets --repo-type dataset --local-dir data --include "data/*"
huggingface-cli download legexbenchmark/inference-results --repo-type dataset --local-dir data --include "data/*"
# After these, data/<cc>/ contains goldenset_<cc>.jsonl + inference_*.csv
uv run legex-analysis --out data/analysis
```
## CLI entrypoints
| Command | Module | Purpose |
|---|---|---|
| `legex-run` | `legex.main:main` | Top-level scrape + filter + sample pipeline. |
| `legex-classify` | `legex.inference:main` | Run an LLM over the goldenset and write predictions to CSV. |
| `legex-harvey-ingest` | `legex.harvey:main` | Ingest a Harvey Vault Review export into the per-jurisdiction CSV format. |
| `legex-evaluate` | `legex.evaluation:main` | Per-country, per-field bucket counts and recall / hallucination. |
| `legex-analysis` | `legex.analysis:main` | Cross-jurisdiction analysis → CSV + LaTeX tables. |
| `legex-quant-results` | `legex.quant_results:main` | Paper-headline summary from the analysis CSV. |
| `legex-pdf` | `legex.pdf_export.cli:main` | Render per-row PDFs from a goldenset workbook. |
| `legex-plots` | `legex.plots:main` | Plot helpers used in the paper. |
## License
MIT.
|