File size: 2,530 Bytes
927c319 30caee4 927c319 30caee4 927c319 30caee4 927c319 30caee4 927c319 30caee4 927c319 30caee4 927c319 30caee4 927c319 30caee4 927c319 30caee4 927c319 30caee4 927c319 30caee4 927c319 30caee4 927c319 30caee4 927c319 |
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 |
---
library_name: transformers
tags:
- legal-qa
- lora
- mistral-7b
- huggingface
- langchain
- faiss
- legal-tech
- retrieval-augmented-generation
datasets:
- theatticusproject/cuad
- jhu-clsp/SARA
language:
- en
base_model:
- mistralai/Mistral-7B-Instruct-v0.2
---
# π§ LexiQ β Legal Document QA using LoRA-Finetuned Mistral-7B
> **Authors**: Nishad Kookana, Ishita, Milan Agarwal, and Sushant Bhatia
> **License**: Apache 2.0
> **Base model**: [mistralai/Mistral-7B-Instruct-v0.2](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2)
LexiQ is a domain-specific Legal Question-Answering model built on top of Mistral 7B. It is fine-tuned using **LoRA** on two legal datasets: **CUAD** (Contract Understanding Atticus Dataset) and **SARA** (Summarization of Appellate Court Rulings). The model supports question answering from legal documents with Retrieval-Augmented Generation (RAG).
---
## π Use Cases
### β
Direct Use:
- Legal document understanding
- Question answering over case files, legal summaries, contracts
- Legal education, research, and policy drafting
### β Out-of-Scope Use:
- Not suitable for non-English documents
- Not trained on international law β Indian and US law concepts dominate
- Not intended for legal advice in real-world litigation
---
## π§ͺ Model Details
- **Model Type**: Causal Language Model (LLM) with LoRA fine-tuning
- **Languages**: English
- **Quantization**: 4-bit (`bnb` nf4) via `bitsandbytes`
- **Training Precision**: Mixed FP16
- **Training Datasets**: CUAD, SARA
- **Tokenizer**: AutoTokenizer (fast)
- **Training Framework**: Transformers + PEFT + Accelerate
---
## π¦ How to Use
```python
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
import torch
tokenizer = AutoTokenizer.from_pretrained("NishKook/legal-qa-lora")
base_model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-Instruct-v0.2", device_map="auto", torch_dtype=torch.float16)
model = PeftModel.from_pretrained(base_model, "NishKook/legal-qa-lora", device_map="auto")
question = "What are the four elements of negligence?"
context = "Negligence requires a duty, a breach of that duty, causation, and damages."
prompt = f"### Question:\n{question}\n\n### Context:\n{context}\n\n### Answer:\n"
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens=256)
print(tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)) |