Downloads · 30 days
10
8% of all-time downloads
rafiaa/legal-passive-to-active-mistral-7b
legal-passive-to-active-mistral-7b is a text generation model from rafiaa. Use it when you need the model to write or continue text. It is set up for peft. The card lists the license as apache-2.0.
RECOMMENDED MODEL - An advanced LoRA fine-tuned model for transforming legal text from passive voice to active voice, built on Mistral-7B-Instruct. This model demonstrates superior performance in simplifying complex l…
Downloads · 30 days
10
8% of all-time downloads
All-time downloads
133
Public
Repo size
168 MB
Likes
1
Public
Click a slice to open those files.
.safetensors168 MB · 100%
From the Hugging Face model README
RECOMMENDED MODEL - An advanced LoRA fine-tuned model for transforming legal text from passive voice to active voice, built on Mistral-7B-Instruct. This model demonstrates superior performance in simplifying complex legal language while maintaining semantic accuracy and legal precision.
This is the enhanced model for legal passive-to-active transformation. Built on Mistral-7B-Instruct-v0.1, it outperforms comparable models on legal voice transformation tasks. The model was fine-tuned on a curated dataset of 319 legal sentences from authoritative sources including UN documents, GDPR, Fair Work Act, and insurance regulations.
This model is designed for:
# Transform a legal passive sentence to active voice
passive_sentence = "The contract shall be executed by both parties within 30 days."
# Model output: "Both parties shall execute the contract within 30 days."
# Simplify GDPR text
passive_sentence = "Personal data may be processed by the controller for legitimate interests."
# Model output: "The controller may process personal data for legitimate interests."
# Transform UN legal text
passive_sentence = "All necessary measures shall be taken by Member States to ensure compliance."
# Model output: "Member States shall take all necessary measures to ensure compliance."
pip install transformers torch peft accelerate bitsandbytes
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
import torch
# Load base model with 4-bit quantization
base_model = "mistralai/Mistral-7B-Instruct-v0.1"
model = AutoModelForCausalLM.from_pretrained(
base_model,
load_in_4bit=True,
torch_dtype=torch.float16,
device_map="auto"
)
# Load LoRA adapter
model = PeftModel.from_pretrained(model, "rafiaa/legal-passive-to-active-mistral-7b")
tokenizer = AutoTokenizer.from_pretrained(base_model)
# Set pad token
if tokenizer.pad_token is None:
tokenizer.pad_token = tokenizer.eos_token
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
import torch
# Load base model (CPU compatible)
base_model = "mistralai/Mistral-7B-Instruct-v0.1"
model = AutoModelForCausalLM.from_pretrained(
base_model,
torch_dtype=torch.float32,
device_map="cpu"
)
# Load LoRA adapter
model = PeftModel.from_pretrained(model, "rafiaa/legal-passive-to-active-mistral-7b")
tokenizer = AutoTokenizer.from_pretrained(base_model)
# Set pad token
if tokenizer.pad_token is None:
tokenizer.pad_token = tokenizer.eos_token
def transform_passive_to_active(passive_sentence, max_length=512):
# Create instruction prompt
instruction = """You are a legal text transformation expert. Your task is to convert passive voice sentences to active voice while maintaining the exact legal meaning and terminology.
Input: Transform the following legal sentence from passive to active voice.
Legal Sentence: """
prompt = instruction + passive_sentence
inputs = tokenizer(prompt, return_tensors="pt")
with torch.no_grad():
outputs = model.generate(
**inputs,
max_length=max_length,
temperature=0.7,
do_sample=True,
pad_token_id=tokenizer.eos_token_id
)
return tokenizer.decode(outputs[0], skip_special_tokens=True)
# Example usage
passive = "The agreement shall be signed by the authorized representatives."
active = transform_passive_to_active(passive)
print(active)
# Batch processing multiple legal sentences
legal_sentences = [
"The policy was established by the board of directors.",
"All documents must be reviewed by legal counsel.",
"The regulations were enacted by Parliament."
]
for sentence in legal_sentences:
transformed = transform_passive_to_active(sentence)
print(f"Passive: {sentence}")
print(f"Active: {transformed}\n")
| Model | Human Eval Score | BERTScore F1 | Performance |
|---|---|---|---|
| Mistral-7B Base | Baseline | High | Good |
| legal-passive-to-active-mistral-7b | +15% | Higher | Excellent |
| legal-passive-to-active-llama2-7b | +6% | High | Good |
This model demonstrates the best performance among 7B parameter models for legal passive-to-active transformation.
If you use this model in your research, please cite:
@misc{legal-passive-active-mistral,
title={legal-passive-to-active-mistral-7b: An Enhanced LoRA Fine-tuned Model for Legal Voice Transformation},
author={Rafi Al Attrach},
year={2024},
url={https://huggingface.co/rafiaa/legal-passive-to-active-mistral-7b}
}
This model represents advanced research in legal text simplification and accessibility, demonstrating superior performance in passive-to-active voice transformation for legal documents.