EmreYY20 commited on
Commit
a5dca46
1 Parent(s): 989abb3
Files changed (1) hide show
  1. abstractive_model.py +8 -5
abstractive_model.py CHANGED
@@ -1,7 +1,10 @@
1
- from transformers import pipeline
2
- import torch
3
 
4
- def summarize_with_bart(text):
5
- pipe = pipeline("text2text-generation", model="EE21/Fine-tuned-BART-ToS-Summarization")
6
- summary = pipe(text, max_length=130, min_length=30, do_sample=False)[0]['generated_text']
 
 
 
 
7
  return summary
 
1
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
 
2
 
3
+ tokenizer = AutoTokenizer.from_pretrained("EE21/Fine-tuned-BART-ToS-Summarization")
4
+ model = AutoModelForSeq2SeqLM.from_pretrained("EE21/Fine-tuned-BART-ToS-Summarization")
5
+
6
+ def summarize_with_bart(input_text):
7
+ inputs = tokenizer.encode("summarize: " + input_text, return_tensors="pt", max_length=1024, truncation=True)
8
+ summary_ids = model.generate(inputs, max_length=150, min_length=40, length_penalty=2.0, num_beams=4, early_stopping=True)
9
+ summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
10
  return summary