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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
language: en
|
| 3 |
+
license: apache-2.0
|
| 4 |
+
pipeline_tag: summarization
|
| 5 |
base_model: nsi319/legal-pegasus
|
| 6 |
tags:
|
| 7 |
+
- summarization
|
| 8 |
- legal
|
| 9 |
+
- pegasus
|
| 10 |
- billsum
|
| 11 |
+
- long-document
|
| 12 |
- abstractive-summarization
|
|
|
|
| 13 |
- finetuned
|
| 14 |
+
- legal-nlp
|
| 15 |
+
- domain-adaptation
|
| 16 |
+
datasets:
|
| 17 |
+
- FiscalNote/billsum
|
| 18 |
+
metrics:
|
| 19 |
+
- bertscore
|
| 20 |
+
---
|
| 21 |
+
|
| 22 |
+
# 📘 Legal Pegasus – BillSum Fine-Tuned
|
| 23 |
+
|
| 24 |
+
**Fine-tuned version of NSI’s Legal Pegasus for abstractive summarization of legal and legislative documents.**
|
| 25 |
+
|
| 26 |
+
This model fine-tunes **nsi319/legal-pegasus**, a legally-pretrained Pegasus model, on the **BillSum dataset** and additional cleaned summaries to generate concise, context-aware, and structured legal summaries.
|
| 27 |
+
It improves coherence, domain terminology handling, and section-wise reasoning in long-form legal and policy text.
|
| 28 |
+
|
| 29 |
+
---
|
| 30 |
+
|
| 31 |
+
# 🧠 Base Model
|
| 32 |
+
|
| 33 |
+
This model builds on:
|
| 34 |
+
|
| 35 |
+
👉 **[nsi319/legal-pegasus](https://huggingface.co/nsi319/legal-pegasus)**
|
| 36 |
+
Pretrained on large-scale legal corpora including:
|
| 37 |
+
|
| 38 |
+
- Statutes
|
| 39 |
+
- Case law
|
| 40 |
+
- Legislative documents
|
| 41 |
+
- Regulatory material
|
| 42 |
+
|
| 43 |
+
This provides strong legal-domain grounding before fine-tuning.
|
| 44 |
+
|
| 45 |
+
---
|
| 46 |
+
|
| 47 |
+
# 📚 Fine-Tuning Dataset
|
| 48 |
+
|
| 49 |
+
- **BillSum** (US Congressional + California bills)
|
| 50 |
+
- Additional cleaned legal-style summaries
|
| 51 |
+
- Documents range from **2k to 12k+ tokens**
|
| 52 |
+
|
| 53 |
+
---
|
| 54 |
+
|
| 55 |
+
# ⚙️ Training Configuration
|
| 56 |
+
|
| 57 |
+
| Setting | Value |
|
| 58 |
+
|--------|--------|
|
| 59 |
+
| Base model | nsi319/legal-pegasus |
|
| 60 |
+
| Epochs | 8 |
|
| 61 |
+
| Learning rate | 2e-5 |
|
| 62 |
+
| Optimizer | AdamW |
|
| 63 |
+
| Weight decay | 0.01 |
|
| 64 |
+
| Batch size | 1 |
|
| 65 |
+
| Gradient accumulation | 4 |
|
| 66 |
+
| Max input length | 1024 tokens |
|
| 67 |
+
| Max summary length | 256 tokens |
|
| 68 |
+
| FP16 | Yes |
|
| 69 |
+
| Warmup | 500 steps |
|
| 70 |
+
| Scheduler | Linear |
|
| 71 |
+
|
| 72 |
+
Training was performed on **Kaggle T4 GPU (16GB)**.
|
| 73 |
+
|
| 74 |
+
---
|
| 75 |
+
|
| 76 |
+
# 🧪 Evaluation Metrics
|
| 77 |
+
|
| 78 |
+
## **ROUGE Scores (Test Set)**
|
| 79 |
+
| Metric | F1 |
|
| 80 |
+
|--------|------|
|
| 81 |
+
| ROUGE-1 | ~0.55 |
|
| 82 |
+
| ROUGE-2 | ~0.35 |
|
| 83 |
+
| ROUGE-L | ~0.41 |
|
| 84 |
+
|
| 85 |
+
## **BERTScore (Semantic Similarity)**
|
| 86 |
+
| Metric | Score |
|
| 87 |
+
|--------|--------|
|
| 88 |
+
| Precision | 0.884 |
|
| 89 |
+
| Recall | 0.894 |
|
| 90 |
+
| F1 | 0.886 |
|
| 91 |
+
|
| 92 |
+
**BERTScore** is emphasized since legal summarization requires semantic preservation rather than lexical overlap.
|
| 93 |
+
|
| 94 |
+
---
|
| 95 |
+
|
| 96 |
+
# 🏗️ Long-Document Summarization Strategy
|
| 97 |
+
|
| 98 |
+
Pegasus supports ~1024 tokens, so long legal documents (3k–30k tokens) were handled using:
|
| 99 |
+
|
| 100 |
+
- Sentence/paragraph splitting
|
| 101 |
+
- Token-based chunking
|
| 102 |
+
- Sliding-window segmentation
|
| 103 |
+
- Chunk-wise summarization
|
| 104 |
+
- Second-pass “summary-of-summaries” rewriting
|
| 105 |
+
|
| 106 |
+
This enables effective summarization far beyond the backbone context limit.
|
| 107 |
+
|
| 108 |
+
---
|
| 109 |
+
|
| 110 |
+
# 📌 Intended Use
|
| 111 |
+
|
| 112 |
+
This model is intended for:
|
| 113 |
+
|
| 114 |
+
- Legal document summarization
|
| 115 |
+
- Bill/policy analysis
|
| 116 |
+
- Legislative NLP pipelines
|
| 117 |
+
- AI assistants for law students
|
| 118 |
+
- Preprocessing for downstream legal reasoning tasks
|
| 119 |
+
|
| 120 |
+
---
|
| 121 |
+
|
| 122 |
+
# ⚠️ Limitations
|
| 123 |
+
|
| 124 |
+
- English only
|
| 125 |
+
- Long documents require external chunking
|
| 126 |
+
- May simplify dense legal definitions
|
| 127 |
+
- Not suitable for legal citations or case-law cross referencing
|
| 128 |
+
- Not intended for production-grade legal decisions
|
| 129 |
+
|
| 130 |
+
---
|
| 131 |
+
|
| 132 |
+
# 🔧 Usage Example
|
| 133 |
+
|
| 134 |
+
```python
|
| 135 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 136 |
+
|
| 137 |
+
model_name = "Anurag33Gaikwad/legal-pegasus-billsum-summarization"
|
| 138 |
+
|
| 139 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 140 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
| 141 |
+
|
| 142 |
+
text = """Your long legal or legislative text here…"""
|
| 143 |
+
|
| 144 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=1024)
|
| 145 |
+
|
| 146 |
+
summary_ids = model.generate(
|
| 147 |
+
inputs["input_ids"],
|
| 148 |
+
num_beams=5,
|
| 149 |
+
max_length=256,
|
| 150 |
+
early_stopping=True
|
| 151 |
+
)
|
| 152 |
+
|
| 153 |
+
print(tokenizer.decode(summary_ids[0], skip_special_tok_
|