Spaces:
Running
Running
Update abstractive_summarization.py
Browse files- abstractive_summarization.py +11 -6
abstractive_summarization.py
CHANGED
|
@@ -4,27 +4,32 @@ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
|
| 4 |
tokenizer = AutoTokenizer.from_pretrained("EE21/BART-ToSSimplify")
|
| 5 |
model = AutoModelForSeq2SeqLM.from_pretrained("EE21/BART-ToSSimplify")
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
# Function to summarize using the fine-tuned BART model
|
| 8 |
def summarize_with_bart_ft(input_text):
|
| 9 |
inputs = tokenizer.encode("summarize: " + input_text, return_tensors="pt", max_length=1024, truncation=True)
|
| 10 |
-
summary_ids = model.generate(inputs, max_length=300, min_length=100, num_beams=
|
| 11 |
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
| 12 |
return summary
|
| 13 |
|
| 14 |
-
# Function to summarize using
|
| 15 |
def summarize_with_bart_cnn(input_text):
|
| 16 |
-
|
| 17 |
-
|
|
|
|
| 18 |
return summary
|
| 19 |
|
| 20 |
# Function to summarize using led-base-book-summary
|
| 21 |
def summarize_with_led(input_text):
|
| 22 |
pipe_led = pipeline("summarization", model="pszemraj/led-base-book-summary")
|
| 23 |
-
summary = pipe_led(input_text, max_length=300, min_length=100, num_beams=
|
| 24 |
return summary[0]['summary_text']
|
| 25 |
|
| 26 |
# Function to summarize using long-t5-tglobal-base-sci-simplify
|
| 27 |
def summarize_with_t5(input_text):
|
| 28 |
pipe_t5 = pipeline("summarization", model="pszemraj/long-t5-tglobal-base-sci-simplify")
|
| 29 |
-
summary = pipe_t5(input_text, max_length=300, min_length=100, num_beams=
|
| 30 |
return summary[0]['summary_text']
|
|
|
|
| 4 |
tokenizer = AutoTokenizer.from_pretrained("EE21/BART-ToSSimplify")
|
| 5 |
model = AutoModelForSeq2SeqLM.from_pretrained("EE21/BART-ToSSimplify")
|
| 6 |
|
| 7 |
+
# Load the BART-large-cnn tokenizer and model
|
| 8 |
+
tokenizer_cnn = BartTokenizer.from_pretrained("facebook/bart-large-cnn")
|
| 9 |
+
model_cnn = BartForConditionalGeneration.from_pretrained("facebook/bart-large-cnn")
|
| 10 |
+
|
| 11 |
# Function to summarize using the fine-tuned BART model
|
| 12 |
def summarize_with_bart_ft(input_text):
|
| 13 |
inputs = tokenizer.encode("summarize: " + input_text, return_tensors="pt", max_length=1024, truncation=True)
|
| 14 |
+
summary_ids = model.generate(inputs, max_length=300, min_length=100, num_beams=1, early_stopping=False, length_penalty=1)
|
| 15 |
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
| 16 |
return summary
|
| 17 |
|
| 18 |
+
# Function to summarize using bart-large-cnn model
|
| 19 |
def summarize_with_bart_cnn(input_text):
|
| 20 |
+
inputs = tokenizer_cnn.encode("summarize: " + input_text, return_tensors="pt", max_length=1024, truncation=True)
|
| 21 |
+
summary_ids = model_cnn.generate(inputs, max_length=300, min_length=100, num_beams=1, early_stopping=True, length_penalty=1)
|
| 22 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
| 23 |
return summary
|
| 24 |
|
| 25 |
# Function to summarize using led-base-book-summary
|
| 26 |
def summarize_with_led(input_text):
|
| 27 |
pipe_led = pipeline("summarization", model="pszemraj/led-base-book-summary")
|
| 28 |
+
summary = pipe_led(input_text, max_length=300, min_length=100, num_beams=1, early_stopping=False, length_penalty=1)
|
| 29 |
return summary[0]['summary_text']
|
| 30 |
|
| 31 |
# Function to summarize using long-t5-tglobal-base-sci-simplify
|
| 32 |
def summarize_with_t5(input_text):
|
| 33 |
pipe_t5 = pipeline("summarization", model="pszemraj/long-t5-tglobal-base-sci-simplify")
|
| 34 |
+
summary = pipe_t5(input_text, max_length=300, min_length=100, num_beams=1, early_stopping=False, length_penalty=1)
|
| 35 |
return summary[0]['summary_text']
|