Spaces:
Runtime error
Runtime error
Shivam29rathore
commited on
Commit
β’
71fdb73
1
Parent(s):
a0c33a2
Update app.py
Browse files
app.py
CHANGED
@@ -78,6 +78,7 @@ def pegasus(text):
|
|
78 |
length = len(sentence)
|
79 |
|
80 |
sentences = [sentence.strip() for sentence in sentences]
|
|
|
81 |
# Append all tokenized sentences
|
82 |
if sentences:
|
83 |
tokenized_sentences.append(sentences)
|
@@ -89,6 +90,11 @@ def pegasus(text):
|
|
89 |
global summary
|
90 |
# Create an empty array for all summaries
|
91 |
summary = []
|
|
|
|
|
|
|
|
|
|
|
92 |
# Loop to encode tokens, to generate abstractive summary and finally decode tokens
|
93 |
for token in tokenized:
|
94 |
# Encoding
|
@@ -97,7 +103,7 @@ def pegasus(text):
|
|
97 |
inputs = inputs.to(device)
|
98 |
# Get summaries from transformer model
|
99 |
all_summary = model2.to(device).generate(inputs,do_sample=True,
|
100 |
-
max_length=
|
101 |
num_beams = 5, early_stopping=True)
|
102 |
# num_return_sequences=5)
|
103 |
# length_penalty=0.2, no_repeat_ngram_size=2
|
|
|
78 |
length = len(sentence)
|
79 |
|
80 |
sentences = [sentence.strip() for sentence in sentences]
|
81 |
+
size = len(sentences)
|
82 |
# Append all tokenized sentences
|
83 |
if sentences:
|
84 |
tokenized_sentences.append(sentences)
|
|
|
90 |
global summary
|
91 |
# Create an empty array for all summaries
|
92 |
summary = []
|
93 |
+
if size <= 4:
|
94 |
+
max_length= size
|
95 |
+
else:
|
96 |
+
max_length = size//4
|
97 |
+
|
98 |
# Loop to encode tokens, to generate abstractive summary and finally decode tokens
|
99 |
for token in tokenized:
|
100 |
# Encoding
|
|
|
103 |
inputs = inputs.to(device)
|
104 |
# Get summaries from transformer model
|
105 |
all_summary = model2.to(device).generate(inputs,do_sample=True,
|
106 |
+
max_length=max_length, top_k=50, top_p=0.95,
|
107 |
num_beams = 5, early_stopping=True)
|
108 |
# num_return_sequences=5)
|
109 |
# length_penalty=0.2, no_repeat_ngram_size=2
|