Update README.md
Browse files
README.md
CHANGED
@@ -22,6 +22,51 @@ Can do abstractive summarization of legal/contractual documents. Fine tuned on B
|
|
22 |
|
23 |
- Abstractive summarization for legal docs (Banking, Legal, Contractual, etc.)
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
## Training Data
|
26 |
|
27 |
- **Dataset URL:** [Multi-Lexsum](https://multilexsum.github.io/)
|
|
|
22 |
|
23 |
- Abstractive summarization for legal docs (Banking, Legal, Contractual, etc.)
|
24 |
|
25 |
+
## Sample Usage
|
26 |
+
|
27 |
+
Load model config and safetensors:
|
28 |
+
```python
|
29 |
+
from transformers import BartForConditionalGeneration, BartTokenizer
|
30 |
+
import torch
|
31 |
+
|
32 |
+
|
33 |
+
model_name = "siddheshtv/bart-multi-lexsum"
|
34 |
+
|
35 |
+
model = BartForConditionalGeneration.from_pretrained(model_name)
|
36 |
+
tokenizer = BartTokenizer.from_pretrained(model_name)
|
37 |
+
|
38 |
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
39 |
+
model = model.to(device)
|
40 |
+
```
|
41 |
+
|
42 |
+
Generate Summary Function
|
43 |
+
```python
|
44 |
+
def generate_summary(model, tokenizer, text, max_length=512):
|
45 |
+
device = next(model.parameters()).device
|
46 |
+
inputs = tokenizer.encode("summarize: " + text, return_tensors="pt", max_length=1024, truncation=True)
|
47 |
+
inputs = inputs.to(device)
|
48 |
+
summary_ids = model.generate(
|
49 |
+
inputs,
|
50 |
+
max_length=max_length,
|
51 |
+
min_length=40,
|
52 |
+
length_penalty=2.0,
|
53 |
+
num_beams=4,
|
54 |
+
early_stopping=True,
|
55 |
+
no_repeat_ngram_size=3,
|
56 |
+
forced_bos_token_id=0,
|
57 |
+
forced_eos_token_id=2
|
58 |
+
)
|
59 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
60 |
+
return summary
|
61 |
+
```
|
62 |
+
|
63 |
+
Generate summary
|
64 |
+
```python
|
65 |
+
generated_summary = generate_summary(model, tokenizer, example_text)
|
66 |
+
print("Generated Summary:")
|
67 |
+
print(generated_summary)
|
68 |
+
```
|
69 |
+
|
70 |
## Training Data
|
71 |
|
72 |
- **Dataset URL:** [Multi-Lexsum](https://multilexsum.github.io/)
|