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6 |
+
- onnx
|
| 7 |
+
- bert
|
| 8 |
+
- cross-encoder
|
| 9 |
+
- legal
|
| 10 |
+
- contract-understanding
|
| 11 |
+
- reranking
|
| 12 |
+
- cuad
|
| 13 |
+
base_model: cross-encoder/ms-marco-MiniLM-L-6-v2
|
| 14 |
+
pipeline_tag: text-ranking
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# cuad-cross-encoder-v10
|
| 18 |
+
|
| 19 |
+
A cross-encoder reranker fine-tuned for **legal clause retrieval** in contract review workflows. Built on top of [`cross-encoder/ms-marco-MiniLM-L-6-v2`](https://huggingface.co/cross-encoder/ms-marco-MiniLM-L-6-v2) and fine-tuned on a combination of CUAD, ACCORD, LEDGAR, ContractNLI, and EDGAR-sourced contract pairs.
|
| 20 |
+
|
| 21 |
+
Deployed as **ONNX INT8** for in-browser inference via [WebAssembly / ONNX Runtime Web](https://onnxruntime.ai/docs/tutorials/web/).
|
| 22 |
+
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
## Intended Use
|
| 26 |
+
|
| 27 |
+
- **Primary:** Reranking retrieved contract chunks against natural-language clause queries (e.g. *"What are the governing law provisions?"*, *"What IP does each party retain?"*)
|
| 28 |
+
- **Domains covered:** Joint Venture, Intellectual Property, Non-Compete / Non-Solicit, Non-Disclosure Agreement (NDA)
|
| 29 |
+
- **Not intended for:** General-purpose document retrieval, non-legal domains, or as a standalone legal advisor
|
| 30 |
+
|
| 31 |
+
---
|
| 32 |
+
|
| 33 |
+
## Training Data
|
| 34 |
+
|
| 35 |
+
| Source | Description | Pairs |
|
| 36 |
+
|--------|-------------|-------|
|
| 37 |
+
| CUAD v1 | 510 contracts, 41 clause categories (Atticus Project) | ~30,000 |
|
| 38 |
+
| ACCORD | 3,931 annotated legal passages | ~6,000 |
|
| 39 |
+
| LEDGAR | SEC EDGAR provisions, 14 labels filtered for JV/NC/IP | ~4,000 |
|
| 40 |
+
| ContractNLI / LegalBench | 14 NLI tasks over contract text | ~3,000 |
|
| 41 |
+
| EDGAR scraped (default) | SC 13D + 8-K NC/IP exhibits, live EDGAR data | ~2,500 |
|
| 42 |
+
| EDGAR JV | 8-K joint venture exhibit filings | ~1,500 |
|
| 43 |
+
| EDGAR Sino-JV | 20-F chapter-format Sino-JV agreements | ~4,272 |
|
| 44 |
+
| Pipeline hard negatives | Clause queries where v9 failed — reranked negatives | 254 |
|
| 45 |
+
| Eval positives | Full-chunk positives extracted from passing eval cases | ~200 |
|
| 46 |
+
|
| 47 |
+
**Total: ~48,268 training pairs** · **5,612 validation pairs**
|
| 48 |
+
|
| 49 |
+
Pairs are `(query, positive_chunk, negative_chunk)` triplets. Negatives are a mix of hard negatives (wrong clause from same contract) and random negatives (chunks from other contracts).
|
| 50 |
+
|
| 51 |
+
---
|
| 52 |
+
|
| 53 |
+
## Training Details
|
| 54 |
+
|
| 55 |
+
| Hyperparameter | Value |
|
| 56 |
+
|----------------|-------|
|
| 57 |
+
| Base model | `cross-encoder/ms-marco-MiniLM-L-6-v2` |
|
| 58 |
+
| Epochs | 3 |
|
| 59 |
+
| Batch size | 32 |
|
| 60 |
+
| Learning rate | 2e-5 |
|
| 61 |
+
| Max sequence length | 512 tokens |
|
| 62 |
+
| Warmup steps | 10% of total steps |
|
| 63 |
+
| Loss | Cross-entropy (sentence-transformers `CrossEncoderTrainer`) |
|
| 64 |
+
| Hardware | NVIDIA RTX 3090 / A10 (RunPod) |
|
| 65 |
+
| Training time | ~45–60 min |
|
| 66 |
+
|
| 67 |
+
---
|
| 68 |
+
|
| 69 |
+
## Evaluation
|
| 70 |
+
|
| 71 |
+
Evaluated on a held-out set of 16 contracts across 4 clause domains. Each contract is queried with 3–8 clause-type questions; the top-ranked chunk is scored as **pass** (correct clause returned), **partial** (correct section but wrong chunk boundary), or **fail**.
|
| 72 |
+
|
| 73 |
+
| Suite | Contracts | Queries | Pass | Partial | Fail |
|
| 74 |
+
|-------|-----------|---------|------|---------|------|
|
| 75 |
+
| Joint Venture | 9 | 51 | 9 (18%) | 26 (51%) | 16 (31%) |
|
| 76 |
+
| Intellectual Property | 4 | 49 | 17 (35%) | 20 (41%) | 12 (24%) |
|
| 77 |
+
| Non-Compete / Non-Solicit | 3 | 13 | 5 (38%) | 8 (62%) | 0 (0%) |
|
| 78 |
+
| NDA | 3 | 19 | 8 (42%) | 9 (47%) | 2 (11%) |
|
| 79 |
+
|
| 80 |
+
**Test contracts (JV):** MightyCell Batteries, BorrowMoney.com, Galera Therapeutics, MINDA IMPCO Technologies, Kiromic Biopharma, Novo Integrated Sciences, Transphorm / Aizu Fujitsu, Valence Technology / Baoding Fengfan, Veoneer
|
| 81 |
+
|
| 82 |
+
**Test contracts (IP):** Armstrong Flooring, Cerence Inc, Garrett Motion, Rare Element Resources
|
| 83 |
+
|
| 84 |
+
**Test contracts (NDA):** Kite Pharma / Gilead Sciences, Fortune Brands / Norcraft Companies, Aspect Medical Systems / Tyco Healthcare
|
| 85 |
+
|
| 86 |
+
---
|
| 87 |
+
|
| 88 |
+
## Usage
|
| 89 |
+
|
| 90 |
+
### ONNX Runtime (recommended for browser / edge)
|
| 91 |
+
|
| 92 |
+
```python
|
| 93 |
+
import onnxruntime as ort
|
| 94 |
+
from transformers import AutoTokenizer
|
| 95 |
+
import numpy as np
|
| 96 |
+
|
| 97 |
+
tokenizer = AutoTokenizer.from_pretrained("datgacon/cuad-cross-encoder-v10")
|
| 98 |
+
session = ort.InferenceSession("model_quantized.onnx")
|
| 99 |
+
|
| 100 |
+
query = "What governing law applies to this agreement?"
|
| 101 |
+
passage = "This Agreement shall be governed by and construed in accordance with the laws of the State of Delaware."
|
| 102 |
+
|
| 103 |
+
inputs = tokenizer(query, passage, return_tensors="np", max_length=512, truncation=True, padding=True)
|
| 104 |
+
outputs = session.run(None, {k: v for k, v in inputs.items() if k in ["input_ids", "attention_mask", "token_type_ids"]})
|
| 105 |
+
score = outputs[0][0][0]
|
| 106 |
+
print(f"Relevance score: {score:.4f}")
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
### sentence-transformers (PyTorch)
|
| 110 |
+
|
| 111 |
+
```python
|
| 112 |
+
from sentence_transformers.cross_encoder import CrossEncoder
|
| 113 |
+
|
| 114 |
+
model = CrossEncoder("datgacon/cuad-cross-encoder-v10")
|
| 115 |
+
|
| 116 |
+
query = "What governing law applies to this agreement?"
|
| 117 |
+
passages = [
|
| 118 |
+
"This Agreement shall be governed by the laws of the State of Delaware.",
|
| 119 |
+
"Each party shall maintain the confidentiality of the other party's information.",
|
| 120 |
+
"The term of this Agreement shall commence on the Effective Date.",
|
| 121 |
+
]
|
| 122 |
+
|
| 123 |
+
scores = model.predict([(query, p) for p in passages])
|
| 124 |
+
ranked = sorted(zip(scores, passages), reverse=True)
|
| 125 |
+
for score, passage in ranked:
|
| 126 |
+
print(f"{score:.4f} {passage[:80]}")
|
| 127 |
+
```
|
| 128 |
+
|
| 129 |
+
---
|
| 130 |
+
|
| 131 |
+
## Limitations
|
| 132 |
+
|
| 133 |
+
- Trained on US commercial contracts (CUAD corpus); may underperform on EU, UK, or public-sector agreements
|
| 134 |
+
- Partial matches are common at clause-boundary edges — chunk size and overlap in the retrieval pipeline significantly affect results
|
| 135 |
+
- Not a legal advisor — scores indicate retrieval relevance, not legal interpretation
|
| 136 |
+
- Performance on clause types outside the four trained domains (JV, IP, NC, NDA) is untested
|
| 137 |
+
|
| 138 |
+
---
|
| 139 |
+
|
| 140 |
+
## Citation
|
| 141 |
+
|
| 142 |
+
If you use this model, please cite the underlying datasets:
|
| 143 |
+
|
| 144 |
+
```bibtex
|
| 145 |
+
@article{hendrycks2021cuad,
|
| 146 |
+
title={CUAD: An Expert-Annotated NLP Dataset for Legal Contract Review},
|
| 147 |
+
author={Hendrycks, Dan and others},
|
| 148 |
+
journal={arXiv preprint arXiv:2103.06268},
|
| 149 |
+
year={2021}
|
| 150 |
+
}
|
| 151 |
+
```
|