pile-of-law/pile-of-law
Updated • 7.61k • 284
How to use Nahla-yasmine/legal-bert-peft-eurlex with PEFT:
Task type is invalid.
A BERT model fine-tuned on EU legal documents from the Pile of Law dataset using Parameter-Efficient Fine-Tuning (PEFT).
bert-base-uncased| Metric | Base Model | Fine-tuned Model | Improvement |
|---|---|---|---|
| Test Loss | 1.9327 | 0.6580 | 66.69% |
| Perplexity | 6.91 | 1.93 | 72.07% |
| Parameter | Value |
|---|---|
| Learning Rate | 2e-4 |
| Batch Size | 16 (8 × gradient accumulation 2) |
| Epochs | 3 |
| Max Sequence Length | 512 |
| Warmup Steps | 500 |
| Weight Decay | 0.01 |
Example 1: Legal Judgment
Input: "The court found the defendant [MASK] of all charges."
Predictions: ["guilty", "innocent", "acquitted", "free", "liable"]
Example 2: Contract Law
Input: "The contract was declared [MASK] due to fraudulent activities."
Predictions: ["void", "invalid", "null", "bankrupt", "cancelled"]
Example 3: Civil Law
Input: "The plaintiff sought [MASK] for damages incurred."
Predictions: ["compensation", "damages", "only", "insurance", "forgiveness"]
from transformers import AutoModelForMaskedLM, AutoTokenizer
# Load model and tokenizer
model = AutoModelForMaskedLM.from_pretrained("Nahla-yasmine/legal-bert-peft-eurlex")
tokenizer = AutoTokenizer.from_pretrained("Nahla-yasmine/legal-bert-peft-eurlex")
# Example: Masked language prediction
text = "The court found the defendant [MASK] of all charges."
inputs = tokenizer(text, return_tensors="pt")
outputs = model(**inputs)
# Get top predictions
mask_token_index = torch.where(inputs["input_ids"] == tokenizer.mask_token_id)[1]
logits = outputs.logits[0, mask_token_index, :]
top_tokens = torch.topk(logits, 5, dim=1).indices[0].tolist()
for i, token_id in enumerate(top_tokens):
predicted_token = tokenizer.decode([token_id])
print(f"{i+1}. {predicted_token}")
from peft import PeftModel, PeftConfig
from transformers import AutoModelForMaskedLM
# Load base model
base_model = AutoModelForMaskedLM.from_pretrained("bert-base-uncased")
# Load PEFT adapter
model = PeftModel.from_pretrained(base_model, "Nahla-yasmine/legal-bert-peft-eurlex")
@software{legal_bert_peft_2024, title = {Legal-BERT-PEFT-EURLEX}, author = {Nahla-yasmine}, year = {2024}, url = {https://huggingface.co/Nahla-yasmine/legal-bert-peft-eurlex} }
Base model
google-bert/bert-base-uncased