Spaces:
Sleeping
Sleeping
Update abstractive_model.py
Browse files- abstractive_model.py +5 -13
abstractive_model.py
CHANGED
@@ -4,17 +4,9 @@ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
|
4 |
tokenizer = AutoTokenizer.from_pretrained("EE21/BART-ToSSimplify")
|
5 |
model = AutoModelForSeq2SeqLM.from_pretrained("EE21/BART-ToSSimplify")
|
6 |
|
7 |
-
# Define
|
8 |
-
def summarize_with_bart(input_text
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
outputs = model.generate(inputs,
|
13 |
-
max_length=max_summary_tokens,
|
14 |
-
min_length=min_summary_tokens,
|
15 |
-
do_sample=do_sample)
|
16 |
-
|
17 |
-
# Decode the generated token IDs back into text
|
18 |
-
summary = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
19 |
-
|
20 |
return summary
|
|
|
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=50, min_length=10, num_beams=8)
|
11 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
return summary
|