EE21 commited on
Commit
f25eb0c
1 Parent(s): e7f0f03

Update abstractive_summarization.py

Browse files
Files changed (1) hide show
  1. abstractive_summarization.py +20 -17
abstractive_summarization.py CHANGED
@@ -1,22 +1,25 @@
1
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
2
 
3
- # Load the fine-tuned BART tokenizer and model
4
- tokenizer = AutoTokenizer.from_pretrained("EE21/BART-ToSSimplify")
5
- model = AutoModelForSeq2SeqLM.from_pretrained("EE21/BART-ToSSimplify")
 
 
6
 
7
- # Load BART-large-cnn
8
- 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=1024, 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=1024, truncation=False)
20
- summary_ids = model.generate(inputs, max_length=600, min_length=300, num_beams=2, early_stopping=False, length_penalty=1)
21
- summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
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']