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("Starting paraphrasing...")
|
| 13 |
|
| 14 |
# Access the model and tokenizer
|
| 15 |
model = paraphraser_model.model
|
|
@@ -33,7 +33,7 @@ def paraphrase_comment(comment):
|
|
| 33 |
return_tensors="pt",
|
| 34 |
truncation=True,
|
| 35 |
padding=True,
|
| 36 |
-
max_length=512
|
| 37 |
return_attention_mask=True
|
| 38 |
).to(model.device)
|
| 39 |
|
|
@@ -41,8 +41,8 @@ def paraphrase_comment(comment):
|
|
| 41 |
outputs = model.generate(
|
| 42 |
input_ids=inputs["input_ids"],
|
| 43 |
attention_mask=inputs["attention_mask"],
|
| 44 |
-
max_length=512
|
| 45 |
-
num_beams=5
|
| 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 "Error: Unable to generate paraphrase
|
|
|
|
| 9 |
"""
|
| 10 |
try:
|
| 11 |
start_time = time.time()
|
| 12 |
+
print(f"Starting paraphrasing for comment: {comment[:50]}...") # Log the start with a snippet of the comment
|
| 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, # Reduced from 512 to 256
|
| 37 |
return_attention_mask=True
|
| 38 |
).to(model.device)
|
| 39 |
|
|
|
|
| 41 |
outputs = model.generate(
|
| 42 |
input_ids=inputs["input_ids"],
|
| 43 |
attention_mask=inputs["attention_mask"],
|
| 44 |
+
max_length=256, # Reduced from 512 to 256
|
| 45 |
+
num_beams=2, # Reduced from 5 to 2 for faster inference
|
| 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)}") # Improved error logging
|
| 63 |
+
return f"Error: Unable to generate paraphrase: {str(e)}"
|