The dataset viewer is not available because its heuristics could not detect any supported data files. You can try uploading some data files, or configuring the data files location manually.
YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
π Contract Analysis AI
Fine-tuned LLM pipeline that extracts clauses, identifies legal entities, and performs risk analysis on multi-hundred-page contracts β cutting review time by 84% for autonomous vehicle firms.
π Key Results
| Metric | Result |
|---|---|
| Analysis Time Reduction | 40% faster with fine-tuned LLaMA-7B |
| Contract Parsing | 500-page contracts parsed in 2 minutes |
| Legal NER F1-Score | 87% (+23 points over base model) |
| Review Time Savings | 84% reduction for AV firm legal teams |
ποΈ Architecture
The pipeline follows a 5-stage extraction and analysis workflow:
- PDF Ingestion β Multi-format parsing via
pdfplumber,PyMuPDF, with Tesseract OCR fallback - Chunking & Preprocessing β Recursive 512-token splitting with 50-token overlap using LangChain
- Fine-tuned LLM Inference β LoRA-adapted LLaMA-7B (rank-16, 4-bit quantized) for clause classification
- NER & Clause Extraction β Custom legal NER identifying parties, dates, obligations, liability clauses
- Risk Analysis & Output β Structured JSON with risk scores, flagged clauses, and summary reports
π§ Model Details
Fine-Tuning Configuration
from peft import LoraConfig, TaskType
lora_config = LoraConfig(
task_type=TaskType.CAUSAL_LM,
r=16,
lora_alpha=32,
lora_dropout=0.05,
target_modules=["q_proj", "v_proj", "k_proj", "o_proj"]
)
- Base Model: LLaMA-2-7B (
meta-llama/Llama-2-7b-hf) - Training Data: 5,000+ annotated legal documents
- Quantization: 4-bit via
bitsandbytesfor efficient GPU inference - Adapter: LoRA rank-16 on all attention projection layers
Performance vs Base Model
| Task | Base LLaMA-7B | Fine-tuned (LoRA) | Improvement |
|---|---|---|---|
| Legal Entity Recognition | 64% F1 | 87% F1 | +23 pts |
| Clause Classification | 58% Acc | 91% Acc | +33 pts |
| Obligation Detection | 52% F1 | 83% F1 | +31 pts |
| Risk Flag Precision | 45% Prec | 79% Prec | +34 pts |
π― Interactive Demo
The project includes a live demo where you can paste contract text and see clause extraction with risk analysis in real-time.
Features:
- Paste any contract text or load a sample
- Clause type classification (Indemnification, Liability Cap, etc.)
- Risk scoring (High / Medium / Low)
- Named entity extraction (parties, dates, monetary values)
- Processing time benchmarks
π§ Tech Stack
| Category | Technologies |
|---|---|
| LLM | LLaMA-2-7B, LoRA, PEFT, bitsandbytes |
| ML Framework | PyTorch, HuggingFace Transformers |
| NLP Pipeline | LangChain, spaCy, tiktoken |
| PDF Processing | pdfplumber, PyMuPDF, Tesseract OCR |
| Data Validation | Pydantic |
| API | FastAPI |
| Frontend | React, TypeScript, Tailwind CSS, Framer Motion |
π Project Structure
βββ model/
β βββ fine_tune.py # LoRA fine-tuning script
β βββ config.yaml # Training hyperparameters
β βββ evaluate.py # Benchmark evaluation
βββ pipeline/
β βββ extract_clauses.py # Clause extraction pipeline
β βββ ner_model.py # Legal NER module
β βββ risk_scorer.py # Risk analysis engine
β βββ pdf_loader.py # PDF ingestion utilities
βββ api/
β βββ main.py # FastAPI endpoints
βββ data/
β βββ train/ # Training dataset (5,000+ docs)
β βββ eval/ # Evaluation benchmark
βββ frontend/ # React demo application
π’ Business Impact
Client: Autonomous vehicle manufacturing firms
- Reduced legal contract review time from ~6 hours to under 1 hour per contract
- Enabled legal teams to process 5x more contracts per quarter
- Automated flagging of high-risk clauses (indemnification, liability caps)
- Extracted and structured key entities across 500-page procurement agreements
π¬ Contact
Built as part of my AI Engineering portfolio. Open to discussing the technical implementation, model architecture decisions, or potential applications.
Built with PyTorch Β· HuggingFace Β· LangChain Β· LoRA
- Downloads last month
- 132


