File size: 653 Bytes
19e7d09
ccd2173
bf2b9e4
 
 
a5dca46
72c8f79
 
 
cfc79e8
717319d
bf2b9e4
1
2
3
4
5
6
7
8
9
10
11
12
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

# Load the BART tokenizer and model
tokenizer = AutoTokenizer.from_pretrained("EE21/BART-ToSSimplify")
model = AutoModelForSeq2SeqLM.from_pretrained("EE21/BART-ToSSimplify")

# Define the abstractive summarization function
def summarize_with_bart(input_text):
    inputs = tokenizer.encode("summarize: " + input_text, return_tensors="pt", max_length=1024, truncation=True)
    summary_ids = model.generate(inputs, max_length=200, min_length=50, num_beams=1, early_stopping=False, length_penalty=1)
    summary = tokenizer.decode(summary_ids[0], skip_special_tokens=False)
    return summary