Spaces:
Sleeping
Sleeping
Update abstractive_summarization.py
Browse files
abstractive_summarization.py
CHANGED
|
@@ -9,14 +9,14 @@ pipe = pipeline("summarization", model="facebook/bart-large-cnn")
|
|
| 9 |
|
| 10 |
# Define the abstractive summarization function (fine-tuned BART)
|
| 11 |
def summarize_with_bart_ft(input_text):
|
| 12 |
-
inputs = tokenizer.encode("summarize: " + input_text, return_tensors="pt", max_length=
|
| 13 |
summary_ids = model.generate(inputs, max_length=300, min_length=100, num_beams=1, early_stopping=False, length_penalty=1)
|
| 14 |
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=False)
|
| 15 |
return summary
|
| 16 |
|
| 17 |
# Define the abstractive summarization function (BART-large-cnn)
|
| 18 |
def summarize_with_bart(input_text):
|
| 19 |
-
inputs = tokenizer.encode("summarize: " + input_text, return_tensors="pt", max_length=
|
| 20 |
summary_ids = model.generate(inputs, max_length=300, min_length=100, num_beams=1, early_stopping=True, length_penalty=1)
|
| 21 |
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
| 22 |
return summary
|
|
|
|
| 9 |
|
| 10 |
# Define the abstractive summarization function (fine-tuned BART)
|
| 11 |
def summarize_with_bart_ft(input_text):
|
| 12 |
+
inputs = tokenizer.encode("summarize: " + input_text, return_tensors="pt", max_length=2048, truncation=True)
|
| 13 |
summary_ids = model.generate(inputs, max_length=300, min_length=100, num_beams=1, early_stopping=False, length_penalty=1)
|
| 14 |
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=False)
|
| 15 |
return summary
|
| 16 |
|
| 17 |
# Define the abstractive summarization function (BART-large-cnn)
|
| 18 |
def summarize_with_bart(input_text):
|
| 19 |
+
inputs = tokenizer.encode("summarize: " + input_text, return_tensors="pt", max_length=2048, truncation=True)
|
| 20 |
summary_ids = model.generate(inputs, max_length=300, min_length=100, num_beams=1, early_stopping=True, length_penalty=1)
|
| 21 |
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
| 22 |
return summary
|