Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -84,24 +84,25 @@ def paraphrase(sentence: str, count: str):
|
|
84 |
text = f"paraphrase: {sentence_input} </s>"
|
85 |
# encoding = tokenizer.encode_plus(text, padding=True, return_tensors="pt")
|
86 |
encoding = tokenizer(text, return_tensors="pt")
|
87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
|
89 |
-
# outputs = model.generate(
|
90 |
-
# input_ids=input_ids, attention_mask=attention_masks,
|
91 |
-
# max_length=512, # 256,
|
92 |
-
# do_sample=True,
|
93 |
-
# top_k=120,
|
94 |
-
# top_p=0.95,
|
95 |
-
# early_stopping=True,
|
96 |
-
# num_return_sequences=p_count
|
97 |
-
# )
|
98 |
-
# res = []
|
99 |
-
# for output in outputs:
|
100 |
-
# line = tokenizer.decode(
|
101 |
-
# output, skip_special_tokens=True, clean_up_tokenization_spaces=True)
|
102 |
-
# res.append(line)
|
103 |
-
print(encoding)
|
104 |
-
print(encoding["input_ids"])
|
105 |
return {
|
106 |
'result': {
|
107 |
'generate_v1':generate_v1(encoding, count),
|
|
|
84 |
text = f"paraphrase: {sentence_input} </s>"
|
85 |
# encoding = tokenizer.encode_plus(text, padding=True, return_tensors="pt")
|
86 |
encoding = tokenizer(text, return_tensors="pt")
|
87 |
+
input_ids, attention_masks = encoding["input_ids"], encoding["attention_mask"]
|
88 |
+
|
89 |
+
outputs = model.generate(
|
90 |
+
input_ids=input_ids, attention_mask=attention_masks,
|
91 |
+
max_length=512, # 256,
|
92 |
+
do_sample=True,
|
93 |
+
top_k=120,
|
94 |
+
top_p=0.95,
|
95 |
+
early_stopping=True,
|
96 |
+
num_return_sequences=p_count
|
97 |
+
)
|
98 |
+
res = []
|
99 |
+
for output in outputs:
|
100 |
+
line = tokenizer.decode(
|
101 |
+
output, skip_special_tokens=True, clean_up_tokenization_spaces=True)
|
102 |
+
res.append(line)
|
103 |
+
|
104 |
+
print(res)
|
105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
return {
|
107 |
'result': {
|
108 |
'generate_v1':generate_v1(encoding, count),
|