--- library_name: pytorch tags: - legal-nlp - catala - statutory-ast - continual-learning - onnx license: apache-2.0 --- # MudraForge `law2code` Downstream Parser Stages — 15.9M Total (Stage 1: 4.6M, Stage 1.5: 6.3M, Stage 2: 4.6M, Stage 2B: 0.47M) Supervised multi-stage statutory parsing stack (**15.93M parameters total**, `15,933,743` params across all 4 neural stages) for **law2code** ([Live Space](https://huggingface.co/spaces/yamero999/law2code)). These downstream parser models are trained on **annotated statutory ground truth**, separate from the unlabeled MLM encoder pretraining corpora. ## Stage 0 Encoder Lineage - **Initialized from:** [`MudraForge/law2code-tax-t1-encoder`](https://huggingface.co/MudraForge/law2code-tax-t1-encoder) (Tax T1 backbone) and compatible with [`MudraForge/law2code-corporate-f1-encoder`](https://huggingface.co/MudraForge/law2code-corporate-f1-encoder) (Corporate F1 unified tax & corporate-finance backbone). ## Training & Evaluation Data - **Annotated Training Corpus:** 250 annotated statutory provisions (`ground_truth_250.json`, 2.33 MB) evaluated under 5-fold cross-validation and full-corpus training. - **Unseen OOD Evaluation Set:** 7 unseen US Internal Revenue Code provisions (`sara_gold_eval_20.json`, 951 atomic spans & 137 operand spans). ## Per-Stage Architecture, Inputs/Outputs & Internal Scores ### 1. Stage 1 — Atomic Non-Operand Parser (`stage1_non_operands` · 4.62M params) - **Task:** Extracts 9 statutory constant & operator classes (`MONEY`, `RATE`, `DATE`, `DURATION`, `COUNT`, `ACTOR_SCOPE`, `DEFINED_TERM`, `OP`, `XREF`) across 37 BILOU tags. - **Inputs:** Tokenized word/char/subword IDs + 36D discourse geometry + clause indices. - **Outputs:** `hidden_states` `[1, seq_len, 256]` and `flat_log_probs` `[1, seq_len, 37]`. - **Internal Scores:** - 5-Fold Blind OOF Exact F1: **91.97%** (Precision: 90.48%, Recall: 93.52%) - Full-Corpus Exact F1: **99.17%** (Relaxed F1: 99.36%, Precision: 99.26%, Recall: 99.08%) - **Files:** `pytorch/stage1_non_operands_tree_cl_v6_full.pt` (19.4 MB) | `onnx/stage1_non_operands.onnx` (19.10 MB, ORT max diff `3.05e-05`) ### 2. Stage 1.5 — Catala Operand Specialist & Entropy Gate (`stage1_5_operands` · 6.26M params) - **Task:** Extracts algebraic operands & conditions across 4 Catala root branches (`NUMERIC_METRIC`, `CATEGORY_FILTER`, `DOC_POINTER`, `COMPLIANCE_ATTESTATION`) and routes OOD phrases (entropy `H >= 0.50`) to human/CA review via prototype memory (`stage1_5_leaf_prototypes_v2.json`). - **Inputs:** Token features + 10-channel coarse Stage 1 conditioning (`s1_coarse`). - **Outputs:** `hidden_states` `[1, seq_len, 256]` and `flat_log_probs` `[1, seq_len, 17]`. - **Internal Scores:** - Blind Fold-1 Untyped F1 (IoU@50): **85.41%** (`NUMERIC_METRIC`: 88.2%, `COMPLIANCE_ATTESTATION`: 76.2%, Router Branch Acc: 94.8%, Catala Leaf Exact: 97.3%) - Full-Corpus Exact F1: **98.52%** (Precision: 97.49%, Recall: 99.57%, Catala Leaf Exact: 97.6%) - **Files:** `pytorch/stage1_5_operands_catala_tree_v2_full.pt` (26.0 MB) | `onnx/stage1_5_operands.onnx` (22.91 MB, ORT max diff `1.34e-05`) ### 3. Stage 2 — Clause Scope Specialist (`stage2_clauses` · 4.58M params) - **Task:** Factors statutes into executable clause scopes (`COND`, `EXCEPTION`, `RULE_EFFECT`, `INLINE_DEF`) using the 41-tag Stage 1 + Stage 1.5 bridge. - **Inputs:** Token features + 41-channel Stage 1/1.5 tag logits (`s1_logits_41`). - **Outputs:** Encoder hidden states `h2`, clause representations `ca2`, and boundary anchor logits `s_logits`, `e_logits`. - **Internal Scores:** - Full-Corpus IoU@50 F1: **97.05%** (Exact F1: 87.73%, Precision: 95.0%, Recall: 99.2%) - **Files:** `pytorch/stage2_clauses_v2_full.pt` (18.9 MB) | `onnx/stage2_clauses.onnx` (17.64 MB, ORT max diff `7.63e-06`) ### 4. Stage 2B — Clause Boundary Pointer Refiner (`stage2_refiner` · 0.47M params) - **Task:** Snaps Stage 2 clause start/end boundaries within a +/-6 token window. - **Internal Scores:** - Refined Exact F1: **94.93%** (+7.20 Exact F1 over Stage 2 base 87.73%, Overlap F1: 97.05%, 0.0% recall loss) - **File:** `pytorch/stage2_refiner_noppo_v2_full.pt` (1.89 MB) ## Deterministic Post-Processing & Versioning Stage 3 (Reflexion Critic & Catala/AST Emitter) runs deterministically over the outputs above with `isAuthorizedToDisburse: false`. Both PyTorch and ONNX outputs support `teach-leaf` prototype memory updates without retraining weights. - **Base neural checkpoints** follow public naming & semantic versioning: encoder families increment by domain tier (`t1`, `t2`, ...; `f1`, `f2`, ...), parser stages increment by semantic version (`v1.0.0`, `v1.1.0`, `v2.0.0` published as `-v1`, `-v2`, ...), and parameter counts (`3.41M` / `15.93M`) are documented in the model card rather than the version tag. - **Continual Learning (CL) memory snapshots** (`M1` / `M1.5` / `M2` episodic deltas and `teach-leaf` prototype banks) are versioned by **Year-Month (`YYYY-MM`, e.g. `2026-11`)** to track monthly Finance Act & statutory updates without re-uploading base weights.