Skip to content

Commit 5a0de95

Browse files
committed
fix(evaluate): slice generated tokens correctly and use greedy decoding
1 parent 5000443 commit 5a0de95

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/darija_translator/evaluate.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ def generate_translations(model, tokenizer, sources: list[str],
3030
return_tensors="pt",
3131
return_dict=True,
3232
).to(model.device)
33+
input_len = inputs["input_ids"].shape[1]
3334
outputs = model.generate(**inputs,
3435
max_new_tokens=128,
35-
temperature=0.7,
36+
do_sample=False,
3637
use_cache=True)
37-
decoded = tokenizer.batch_decode(outputs, skip_special_tokens=True)
38+
new_tokens = outputs[:, input_len:]
39+
decoded = tokenizer.batch_decode(new_tokens, skip_special_tokens=True)
3840
predictions.append(decoded[0])
3941
return predictions

0 commit comments

Comments
 (0)