Update paraphraser.py
Browse files- paraphraser.py +6 -6
paraphraser.py
CHANGED
@@ -9,7 +9,7 @@ def paraphrase_comment(comment):
|
|
9 |
"""
|
10 |
try:
|
11 |
start_time = time.time()
|
12 |
-
print(f"Starting paraphrasing for comment: {comment[:50]}...")
|
13 |
|
14 |
# Access the model and tokenizer
|
15 |
model = paraphraser_model.model
|
@@ -33,16 +33,16 @@ def paraphrase_comment(comment):
|
|
33 |
return_tensors="pt",
|
34 |
truncation=True,
|
35 |
padding=True,
|
36 |
-
max_length=256,
|
37 |
return_attention_mask=True
|
38 |
).to(model.device)
|
39 |
|
40 |
-
# Generate the paraphrased comment
|
41 |
outputs = model.generate(
|
42 |
input_ids=inputs["input_ids"],
|
43 |
attention_mask=inputs["attention_mask"],
|
44 |
-
|
45 |
-
num_beams=2,
|
46 |
no_repeat_ngram_size=2,
|
47 |
early_stopping=True
|
48 |
)
|
@@ -59,5 +59,5 @@ def paraphrase_comment(comment):
|
|
59 |
return paraphrased_comment if paraphrased_comment else "Error: Unable to generate paraphrase."
|
60 |
|
61 |
except Exception as e:
|
62 |
-
print(f"Error during paraphrasing: {str(e)}")
|
63 |
return f"Error: Unable to generate paraphrase: {str(e)}"
|
|
|
9 |
"""
|
10 |
try:
|
11 |
start_time = time.time()
|
12 |
+
print(f"Starting paraphrasing for comment: {comment[:50]}...")
|
13 |
|
14 |
# Access the model and tokenizer
|
15 |
model = paraphraser_model.model
|
|
|
33 |
return_tensors="pt",
|
34 |
truncation=True,
|
35 |
padding=True,
|
36 |
+
max_length=256,
|
37 |
return_attention_mask=True
|
38 |
).to(model.device)
|
39 |
|
40 |
+
# Generate the paraphrased comment using max_new_tokens
|
41 |
outputs = model.generate(
|
42 |
input_ids=inputs["input_ids"],
|
43 |
attention_mask=inputs["attention_mask"],
|
44 |
+
max_new_tokens=50, # Generate up to 50 new tokens
|
45 |
+
num_beams=2,
|
46 |
no_repeat_ngram_size=2,
|
47 |
early_stopping=True
|
48 |
)
|
|
|
59 |
return paraphrased_comment if paraphrased_comment else "Error: Unable to generate paraphrase."
|
60 |
|
61 |
except Exception as e:
|
62 |
+
print(f"Error during paraphrasing: {str(e)}")
|
63 |
return f"Error: Unable to generate paraphrase: {str(e)}"
|