File size: 1,905 Bytes
9e15576
 
 
 
 
 
 
2d8056d
9e15576
 
 
 
 
 
2d8056d
9e15576
2d8056d
 
 
9e15576
 
 
2d8056d
9e15576
8996870
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2d8056d
9e15576
2d8056d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
---
library_name: transformers
tags: []
---

# Model Card for Model ID

Source code: [Google Colab](https://colab.research.google.com/drive/1qnocYiNrF3udkxx1YRwyxTSaeN7F35DK)


## Model Details

### Model Description

Can do abstractive summarization of legal/contractual documents. Fine tuned on BART-LARGE-CNN.

- **Developed by:** [Siddhesh Kulthe](https://huggingface.co/siddheshtv)
- **License:** MIT
- **Finetuned from model:** [Facebook/BART-LARGE-CNN](https://huggingface.co/facebook/bart-large-cnn)

## Uses

- Abstractive summarization for legal docs (Banking, Legal, Contractual, etc.)

## Sample Usage

Load model config and safetensors:
```python
from transformers import BartForConditionalGeneration, BartTokenizer
import torch


model_name = "siddheshtv/bart-multi-lexsum"

model = BartForConditionalGeneration.from_pretrained(model_name)
tokenizer = BartTokenizer.from_pretrained(model_name)

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model = model.to(device)
```

Generate Summary Function
```python
def generate_summary(model, tokenizer, text, max_length=512):
    device = next(model.parameters()).device
    inputs = tokenizer.encode("summarize: " + text, return_tensors="pt", max_length=1024, truncation=True)
    inputs = inputs.to(device)
    summary_ids = model.generate(
        inputs,
        max_length=max_length,
        min_length=40,
        length_penalty=2.0,
        num_beams=4,
        early_stopping=True,
        no_repeat_ngram_size=3,
        forced_bos_token_id=0,
        forced_eos_token_id=2
    )
    summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
    return summary
```

Generate summary
```python
generated_summary = generate_summary(model, tokenizer, example_text)
print("Generated Summary:")
print(generated_summary)
```

## Training Data

- **Dataset URL:** [Multi-Lexsum](https://multilexsum.github.io/)