Instructions to use alirezaaminzadeh/contractguard-clause-analyzer with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Scikit-learn
How to use alirezaaminzadeh/contractguard-clause-analyzer with Scikit-learn:
from huggingface_hub import hf_hub_download import joblib model = joblib.load( hf_hub_download("alirezaaminzadeh/contractguard-clause-analyzer", "sklearn_model.joblib") ) # only load pickle files from sources you trust # read more about it here https://skops.readthedocs.io/en/stable/persistence.html - Notebooks
- Google Colab
- Kaggle
ContractGuard Clause Analyzer
Bilingual (English/Persian) contract clause classifier and risk-detection engine by Aria AI.
Model Description
ContractGuard classifies contract clauses into 12 business categories and feeds a deterministic 14-rule risk engine. The shipped classifier is a hybrid ensemble:
| Component | Detail |
|---|---|
| ML model | scikit-learn TF-IDF (word 1-2 + char_wb 2-4) → Logistic Regression (C=4) |
| Keyword prior | Specificity-weighted bilingual legal lexicon per category |
| Blend | 0.65 × P(ml) + 0.35 × P(keyword) |
| Artifact | clause_classifier.joblib (pipeline + labels bundle) |
| Fallback | Keyword-only heuristics when the artifact is absent |
Categories: payment, delivery, warranty, confidentiality, termination, liability, penalty, intellectual_property, dispute_resolution, force_majeure, compliance, general.
Evaluation (template-disjoint — unseen phrasings)
Whole templates are held out of training, so the test set contains only phrasings the model has never seen. This avoids the template leakage that would otherwise report a misleading 100%.
| Metric | Raw ML | Hybrid (shipped) |
|---|---|---|
| Accuracy | 70.0% | 92.1% |
| Macro F1 | 0.697 | 0.918 |
| EN accuracy | — | 95.8% |
| FA accuracy | — | 88.3% |
Per-category F1 (hybrid): payment 1.00 · liability 1.00 · penalty 1.00 · IP 1.00 · force majeure 1.00 · dispute resolution 0.98 · warranty 0.91 · delivery 0.89 · compliance 0.86 · confidentiality 0.86 · termination 0.82 · general 0.71.
Risk engine (deterministic, not learned)
| Metric | Result |
|---|---|
| Recall on 140 seeded risky clauses (14 rules, EN+FA) | 100% |
| High-severity false-positive rate (735 clean clauses) | 0.68% |
Full reproducible reports: eval_results.json and benchmark_report.json in the dataset repo.
Usage
import joblib
bundle = joblib.load("clause_classifier.joblib")
pipeline, labels = bundle["pipeline"], bundle["labels"]
proba = pipeline.predict_proba(["The Client shall pay each invoice within 30 days."])[0]
print(labels[proba.argmax()], proba.max()) # payment 0.9…
For the full hybrid path (recommended) use ClauseClassifier from the project source (see the Space files).
Intended Uses
- Pre-screening commercial contracts before legal review (procurement, sales, EPC, NDAs)
- Clause inventory/triage for contract migration projects
- Counsel-in-the-loop review workflows (the shipped product includes an RBAC review queue)
Out-of-Scope Uses
- Autonomous contract approval without qualified human review
- Legal advice of any kind
- Scanned/handwritten contracts without an OCR + LayoutLM upgrade (documented roadmap)
Training Data
875 synthetic bilingual clauses (contractguard-clause-samples) — template-generated, no real contracts or PII.
Limitations & Bias
- Trained on synthetic commercial-contract phrasing; niche domains (insurance, construction claims) may need lexicon extension.
- Persian coverage is strong on formal contract register; colloquial drafting reduces accuracy.
generalis the hardest category (F1 0.71) — boilerplate overlaps with every other class.
Demo
Interactive Space: contractguard-clause-analyzer
Citation
@misc{contractguard_clause_analyzer_2026,
title={ContractGuard: Bilingual Contract Clause Analysis and Risk Detection},
author={Aria AI Engineering Team},
year={2026},
url={https://huggingface.co/alirezaaminzadeh/contractguard-clause-analyzer}
}
License
Apache 2.0
- Downloads last month
- -