File size: 3,518 Bytes
2e511b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env bash
# Reproduce every generated table and figure of the LEGEX paper from the
# published JSONL bundles (goldensets + inference-results).
#
# Inputs (auto-detected, or override via env):
#   GOLD_DIR     goldenset data dir   (submission/goldensets/data, else ../goldensets/data)
#   INF_DIR      inference data dir   (submission/inference-results/data, else ../inference-results/data)
#   ALTTEST_DIR  optional clone of https://github.com/nitaytech/AltTest — reruns
#                the Alternative Annotator Test (alt_test_pooled.csv + the
#                per-field reference CSVs; skipped when unset)
#
# Every artifact is regenerated in place under data/analysis/, so a clean
# `git status` after a run is the verification that the shipped numbers
# reproduce.
set -euo pipefail
cd "$(dirname "$0")/.."

if [[ -z "${GOLD_DIR:-}" ]]; then
  for c in goldensets/data submission/goldensets/data ../goldensets/data; do
    [[ -d "$c" ]] && GOLD_DIR="$c" && break
  done
fi
if [[ -z "${INF_DIR:-}" ]]; then
  for c in inference-results/data submission/inference-results/data ../inference-results/data; do
    [[ -d "$c" ]] && INF_DIR="$c" && break
  done
fi
if [[ -z "${GOLD_DIR:-}" || -z "${INF_DIR:-}" ]]; then
  echo "error: published data not found — clone legexbenchmark/goldensets and" >&2
  echo "legexbenchmark/inference-results next to this repository, or set GOLD_DIR/INF_DIR." >&2
  exit 1
fi
echo "gold: $GOLD_DIR"
echo "inference: $INF_DIR"

RUN="uv run --extra plots"
IAA_DIR="data/analysis/iaa"
# Byte-stable matplotlib PDF metadata across runs.
export SOURCE_DATE_EPOCH=0

# Clean first so dropped inputs can't leave stale rows behind. The AAT CSVs
# are only regenerated when ALTTEST_DIR is set (they need the upstream clone).
rm -f "$IAA_DIR"/pairwise_agreement.csv "$IAA_DIR"/kappa_audit.csv \
      "$IAA_DIR"/ANALYSIS.md "$IAA_DIR"/alt_test_decomposition.csv

echo "== Table 3 inputs: human-human agreement (pairwise_agreement.csv, kappa_audit.csv)"
$RUN legex-iaa --gold-dir "$GOLD_DIR" --out "$IAA_DIR"

echo "== Table 5: AAT win/tie/loss decomposition (alt_test_decomposition.csv)"
$RUN python scripts/alt_test_decomposition.py \
    --gold-dir "$GOLD_DIR" --inference-dir "$INF_DIR" --out "$IAA_DIR"

echo "== Scoring aggregates (per_*.csv, tables/headline.tex, tables/per_field.tex)"
$RUN legex-analysis --gold-dir "$GOLD_DIR" --inference-dir "$INF_DIR" \
    --country am au be br ch de es fr ge hk in np nz ph rs sg tw uk us

echo "== Table 4: headline metrics (quant_results.tex)"
$RUN legex-quant-results

echo "== Tables 7/8: by-jurisdiction and by-field metrics (paper_tables.tex)"
$RUN python scripts/paper_tables.py > data/analysis/paper_tables.tex

echo "== Table 9 + word cloud: diversity stats"
$RUN python scripts/diversity_stats.py --gold-dir "$GOLD_DIR"

echo "== Table 10 + Figure 5: currency and ISIC frequencies"
$RUN python scripts/appendix_frequencies.py --gold-dir "$GOLD_DIR"

echo "== Figure 3: hallucination category shares"
$RUN python scripts/hallucination_stats.py

if [[ -n "${ALTTEST_DIR:-}" ]]; then
  echo "== AAT (alt_test_pooled.csv + alt_test_reference_*.csv)"
  $RUN python scripts/alt_test_reference.py --alttest "$ALTTEST_DIR" --per-field \
      --gold-dir "$GOLD_DIR" --inference-dir "$INF_DIR" --out "$IAA_DIR"
else
  echo "== AAT skipped (set ALTTEST_DIR to a clone of nitaytech/AltTest to rerun it)"
fi

echo "== ANALYSIS.md (renders all CSVs above)"
$RUN legex-analysis-report

echo "done — verify with: git status data/analysis"