Downloads · 30 days
8
15% of all-time downloads
siddheshtv/bart-multi-lexsum
bart-multi-lexsum is a machine learning model from siddheshtv. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for transformers.
Downloads · 30 days
8
15% of all-time downloads
All-time downloads
54
Public
Parameters
406M
1.6 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors1.6 GB · 100%
From the Hugging Face model README
Source code: Google Colab
Can do abstractive summarization of legal/contractual documents. Fine tuned on BART-LARGE-CNN.
Load model config and safetensors:
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
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
generated_summary = generate_summary(model, tokenizer, example_text)
print("Generated Summary:")
print(generated_summary)