gaur3009 commited on
Commit
c588c93
Β·
verified Β·
1 Parent(s): 399f464

Update summarizer.py

Browse files
Files changed (1) hide show
  1. summarizer.py +20 -6
summarizer.py CHANGED
@@ -1,10 +1,24 @@
1
  from transformers import pipeline
2
 
3
- summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
 
 
 
 
 
4
 
5
  def summarize_text(text, max_length=100):
6
- """Summarize long text into shorter summary."""
7
- # BART supports about 1024 tokens. Let's truncate text to ~1500 characters
8
- truncated = text[:1500]
9
- summary = summarizer(truncated, max_length=max_length, min_length=30, do_sample=False)[0]['summary_text']
10
- return summary
 
 
 
 
 
 
 
 
 
 
1
  from transformers import pipeline
2
 
3
+ # Use distilled summarization model
4
+ summarizer = pipeline(
5
+ "summarization",
6
+ model="sshleifer/distilbart-cnn-12-6",
7
+ tokenizer="sshleifer/distilbart-cnn-12-6"
8
+ )
9
 
10
  def summarize_text(text, max_length=100):
11
+ """Efficient CPU summarization"""
12
+ if len(text) < 200:
13
+ return text
14
+
15
+ # Truncate to model's max capacity
16
+ truncated = text[:1024]
17
+
18
+ return summarizer(
19
+ truncated,
20
+ max_length=max_length,
21
+ min_length=30,
22
+ do_sample=False, # Faster without sampling
23
+ truncation=True
24
+ )[0]['summary_text']