Downloads · 30 days
14
14% of all-time downloads
rafiaa/legal-passive-to-active-llama-7b
legal-passive-to-active-llama-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.
A specialized LoRA fine-tuned model for transforming legal text from passive voice to active voice, built on Llama-2-7b-Chat. This model simplifies complex legal language while maintaining semantic accuracy and legal…
Downloads · 30 days
14
14% of all-time downloads
All-time downloads
102
Public
Repo size
160 MB
Likes
0
Public
Click a slice to open those files.
.safetensors160 MB · 100%
From the Hugging Face model README
A specialized LoRA fine-tuned model for transforming legal text from passive voice to active voice, built on Llama-2-7b-Chat. This model simplifies complex legal language while maintaining semantic accuracy and legal precision.
This model is a LoRA (Low-Rank Adaptation) fine-tuned version of Llama-2-7b-Chat-hf, specifically optimized for passive-to-active voice transformation in legal documents. It was trained on a curated dataset of 319 legal sentences from authoritative sources including UN documents, GDPR, Fair Work Act, and insurance regulations to understand legal syntax, passive constructions, and voice transformation patterns.
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."
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 = "meta-llama/Llama-2-7b-chat-hf"
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-llama-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 = "meta-llama/Llama-2-7b-chat-hf"
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-llama-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)
The model was evaluated using both automatic metrics (BERTScore - Precision, Recall, F1) and human evaluation:
If you use this model in your research, please cite:
@misc{legal-passive-active-llama2,
title={legal-passive-to-active-llama2-7b: A LoRA Fine-tuned Model for Legal Voice Transformation},
author={Rafi Al Attrach},
year={2024},
url={https://huggingface.co/rafiaa/legal-passive-to-active-llama-7b}
}
This model is part of a research project on legal text simplification and accessibility, focusing on passive-to-active voice transformation in legal documents.