Spaces:
Sleeping
Sleeping
Update abstractive_summarization.py
Browse files- abstractive_summarization.py +20 -17
abstractive_summarization.py
CHANGED
|
@@ -1,22 +1,25 @@
|
|
| 1 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
def
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
summary
|
| 15 |
-
return summary
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
def
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
summary
|
| 22 |
-
return summary
|
|
|
|
| 1 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
| 2 |
|
| 3 |
+
# Function to summarize using the fine-tuned BART model
|
| 4 |
+
def summarize_with_bart_ft(input_text):
|
| 5 |
+
pipe_bart_ft = pipeline("summarization", model="EE21/BART-ToSSimplify")
|
| 6 |
+
summary = pipe_bart_ft(input_text, max_length=300, min_length=100, num_beams=1, early_stopping=False, length_penalty=1)
|
| 7 |
+
return summary[0]['summary_text']
|
| 8 |
|
| 9 |
+
# Function to summarize using BART-large-cnn
|
| 10 |
+
def summarize_with_bart_cnn(input_text):
|
| 11 |
+
pipe = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 12 |
+
summary = pipe(input_text, max_length=300, min_length=100, num_beams=1, early_stopping=False, length_penalty=1)
|
| 13 |
+
return summary[0]['summary_text']
|
| 14 |
|
| 15 |
+
# Function to summarize using led-base-book-summary
|
| 16 |
+
def summarize_with_led(input_text):
|
| 17 |
+
pipe_led = pipeline("summarization", model="pszemraj/led-base-book-summary")
|
| 18 |
+
summary = pipe_led(input_text, max_length=300, min_length=100, num_beams=1, early_stopping=False, length_penalty=1)
|
| 19 |
+
return summary[0]['summary_text']
|
|
|
|
| 20 |
|
| 21 |
+
# Function to summarize using long-t5-tglobal-base-sci-simplify
|
| 22 |
+
def summarize_with_t5(input_text):
|
| 23 |
+
pipe_t5 = pipeline("summarization", model="pszemraj/long-t5-tglobal-base-sci-simplify")
|
| 24 |
+
summary = pipe_t5(input_text, max_length=300, min_length=100, num_beams=1, early_stopping=False, length_penalty=1)
|
| 25 |
+
return summary[0]['summary_text']
|
|
|