Skip to content

Integrate Dynamic WER/CER Evaluation Hooks in Seq2SeqTrainer #9

Description

@purvanshjoshi

Technical Overview

Evaluating speech adaptation using only the training loss can lead to overfitting on accent patterns. We need to calculate and track the Word Error Rate (WER) and Character Error Rate (CER) on accented test sets at regular evaluation intervals.

Affected Modules

  • File: src/train.py
  • Target Classes: Seq2SeqTrainer and its evaluation hooks.

Acceptance Criteria

  1. Automated Computation: Calculates WER and CER metrics automatically at each designated eval_steps interval.
  2. Performance Constraints: Metric evaluation must not increase total step duration by more than 10%.
  3. Accurate Tracking: Decodes model tokens back to clean string predictions to calculate error rates, ignoring special tokens.

Proposed Implementation Approach

Implement a metric calculation function and register it within the trainer constructor:

import evaluate
import numpy as np

wer_metric = evaluate.load("wer")
cer_metric = evaluate.load("cer")

def compute_metrics(pred):
    pred_ids = pred.predictions
    label_ids = pred.label_ids
    
    # Replace -100 to ignore pad tokens
    label_ids[label_ids == -100] = tokenizer.pad_token_id
    
    pred_str = tokenizer.batch_decode(pred_ids, skip_special_tokens=True)
    label_str = tokenizer.batch_decode(label_ids, skip_special_tokens=True)
    
    wer = wer_metric.compute(predictions=pred_str, references=label_str)
    cer = cer_metric.compute(predictions=pred_str, references=label_str)
    
    return {"wer": wer, "cer": cer}

Severity & Priority

  • Severity: Medium (Improves validation monitoring)
  • Priority: P2

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions