Spaces:
Sleeping
Sleeping
Update abstractive_model.py
Browse files- abstractive_model.py +8 -4
abstractive_model.py
CHANGED
@@ -1,8 +1,12 @@
|
|
1 |
from transformers import pipeline
|
2 |
|
3 |
-
|
|
|
|
|
4 |
|
|
|
5 |
def summarize_with_bart(input_text):
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
1 |
from transformers import pipeline
|
2 |
|
3 |
+
# Load the BART tokenizer and model
|
4 |
+
tokenizer = AutoTokenizer.from_pretrained("EE21/BART-ToSSimplify")
|
5 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("EE21/BART-ToSSimplify")
|
6 |
|
7 |
+
# Define the abstractive summarization function
|
8 |
def summarize_with_bart(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=150, min_length=40, length_penalty=2.0, num_beams=4, early_stopping=True)
|
11 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
12 |
+
return summary
|