Repository navigation
Closed
Labels
feature requestFeature request pending on roadmap
Description
Hey!
I'm using unsloth to fine tune gemma3-270m model for task of converting Hebrew into IPA phonemes (G2P).
It's similar task like translating Hebrew into English.
I have 5 million pairs of Hebrew <> IPA phonemes and I use the default training recipe
I tried to use this compute_metrics approrch:
def compute_metrics(eval_pred, tokenizer):
predictions, labels = eval_pred
breakpoint()
# Convert logits to token IDs (take argmax)
if predictions.ndim == 3: # (batch_size, seq_len, vocab_size)
predictions = np.argmax(predictions, axis=-1)
# Decode predictions
decoded_preds = tokenizer.batch_decode(predictions, skip_special_tokens=True)
# Replace -100 in labels (used for padding) with pad_token_id
labels = np.where(labels != -100, labels, tokenizer.pad_token_id)
decoded_labels = tokenizer.batch_decode(labels, skip_special_tokens=True)
wer_score = wer.compute(predictions=decoded_preds, references=decoded_labels)
cer_score = cer.compute(predictions=decoded_preds, references=decoded_labels)
wer_acc = (1 - wer_score) * 100
cer_acc = (1 - cer_score) * 100
return {
"wer": wer_score,
"cer": cer_score,
"wer_acc": wer_acc,
"cer_acc": cer_acc,
}But it seems like the decoded predictions/labels are invalid. it contains non readable characters.
How can I correctly compute WER/CER during training? this is very important evaluation for such tasks since the loss doesn't tell much about the performance.
This is the training code I use:
should be comfortable reproducible code. It takes few minutes to setup the full training including the 100MB data I trained on
Thank you!
Related
Reacted by thewh1teagle
Metadata
Metadata
Assignees
Labels
feature requestFeature request pending on roadmap
Activity
Fix evaluate() under auto padding-free and keep compute_metrics rows …
danielhanchen commentedon Oct 9, 2026
Fixed! Sorry on the delay. Two things were going on.
eval_pred.predictionsis a single teacher-forced forward pass, soargmax(logits)at positiontis the guess for tokent + 1, and decoding it unshifted (and over the prompt tokens too) gives garbage even with plain transformers. Shift by one and keep only the labelled positions:For true WER / CER on G2P, run
model.generateon the eval prompts (for example in aTrainerCallback.on_evaluate), since the shifted predictions are still teacher-forced.compute_metricsset, Unsloth still enabled padding-free batching, so each row ofpredictionsheld a whole batch concatenated instead of one example; andtrainer.evaluate()called outsidetrain()reported a wrong loss on packed batches (Gemma 3 270M eval loss 3.82 instead of 2.37). On a Hebrew to IPA setup like yours, Gemma 3 270M now gets eval loss 0.822 and CER 0.209 with the shifted decoding, matching plain transformers (0.819, 0.209).To update:
uv pip install --upgrade unsloth unsloth_zoo --force-reinstall --no-cache-dir(if it's not in the current release yet it'll be in the next one). Reopen if it still happens.