File size: 1,218 Bytes
2f8382c
ccd2173
2f8382c
bf2b9e4
 
a5dca46
2f8382c
 
 
 
 
72c8f79
cfc79e8
717319d
2f8382c
 
 
 
 
 
 
bf2b9e4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline

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

# Load BART-large-cnn
pipe = pipeline("summarization", model="facebook/bart-large-cnn")

# Define the abstractive summarization function (fine-tuned BART)
def summarize_with_bart_ft(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

# Define the abstractive summarization function (BART-large-cnn)
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, length_penalty=2.0, num_beams=2, early_stopping=True)
    summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
    return summary