fix: always left-pad inputs, and avoid optimizing for empty responses

Fixes #70

Co-authored-by: arnomatic <acc@eml.cc>
This commit is contained in:
Philipp Emanuel Weidmann
2025-12-06 06:31:09 +05:30
parent baf5b0b0d1
commit da27ba8054
2 changed files with 9 additions and 1 deletions
+4
View File
@@ -37,6 +37,10 @@ class Evaluator:
)
def is_refusal(self, response: str) -> bool:
# Classify empty responses as refusals to avoid optimizing for them.
if not response.strip():
return True
# Remove emphasis (e.g. "I *will not*...").
response = response.lower().replace("*", "")
+4
View File
@@ -46,6 +46,10 @@ class Model:
# Fallback for tokenizers that don't declare a special pad token.
if self.tokenizer.pad_token is None:
self.tokenizer.pad_token = self.tokenizer.eos_token
# CRITICAL: Always use left-padding for decoder-only models during generation.
# Right-padding causes empty outputs because the model sees PAD tokens
# after the prompt and thinks the sequence is complete.
self.tokenizer.padding_side = "left"
self.model = None