Implementation:EvolvingLMMs Lab Lmms eval People Speech Utils
Task utility functions for the People Speech benchmark, which evaluates automatic speech recognition across multiple languages and sources using Word Error Rate (WER).
Location
lmms_eval/tasks/people_speech/utils.py
Overview
Provides audio processing, result handling, and WER computation for People Speech tasks. Supports multi-language evaluation (English, Chinese, Yue) with language-specific text normalization and tokenization.
Core Functions
Document Processing
people_speech_doc_to_audio(doc)- Extracts audio from document
- Parameters:
doc- Document with"audio"key - Returns: List containing audio file/data
people_speech_doc_to_text(doc, lmms_eval_specific_kwargs)- Constructs fixed ASR prompt
- Parameters:
doc,lmms_eval_specific_kwargs(with prompts) - Returns:
"{pre_prompt}Please recognize the speech and only output the recognized content:{post_prompt}"
Result Processing
people_speech_process_result(doc, result)- Packages prediction with metadata for WER computation
- Parameters:
doc- Document withgt,source,taskresult- Model prediction list
- Returns: Dictionary with
werentry containing:gt: Ground truth transcriptionpred: Model predictionsource: Data sourcetask: Task identifier (contains language code)
Text Normalization
remove_sp(text, language)- Removes special tokens and normalizes spacing
- Parameters:
text- Input textlanguage- Language code ("zh", "en", etc.)
- Process:
- Removes tokens matching
<|.*|>pattern - Collapses consecutive spaces to single space
- Removes space before punctuation (
!,.?;:) - Left-strips whitespace
- For Chinese ("zh"): removes all remaining spaces
- Removes tokens matching
- Returns: Normalized text string
EvaluationTokenizer Class
Language-aware tokenizer leveraging sacreBLEU tokenizers.
Initialization
EvaluationTokenizer(
tokenizer_type="13a",
lowercase=False,
punctuation_removal=False,
character_tokenization=False
)
Parameters
tokenizer_type: Tokenizer variant - "none", "13a", "intl", "zh", "ja-mecab", "char"lowercase: Apply lowercasingpunctuation_removal: Remove punctuation-only tokenscharacter_tokenization: Character-level tokenization
Class Constants
SPACE = chr(32)SPACE_ESCAPE = chr(9601)
Methods
remove_punctuation(sent)(classmethod)- Removes tokens that are purely punctuation
- Parameters:
sent- Space-separated string - Process: Filters tokens where all characters are Unicode category "P" (punctuation)
- Returns: String with punctuation-only tokens removed
tokenize(sent)- Applies full tokenization pipeline
- Parameters:
sent- Input string - Process:
- Apply sacreBLEU tokenizer
- Optionally remove punctuation
- Optionally tokenize to characters (with space escape)
- Optionally lowercase
- Returns: Tokenized string
WER Computation
compute_wer(refs, hyps, language)
Computes Word Error Rate using edit distance.
Parameters:
refs- List of reference transcriptionshyps- List of hypothesis transcriptionslanguage- Language code
Process:
- For each reference-hypothesis pair:
- Apply language-specific normalization:
yue: Convert to simplified Chinese viazhconv.convert(text, "zh-cn")en: Applyenglish_normalizer(Whisper English normalizer)zh: Applychinese_normalizer(TextNorm with custom config)- Other: Apply
basic_normalizer(Whisper basic normalizer)
- Tokenize using EvaluationTokenizer:
- Type: "none"
- Lowercase: True
- Punctuation removal: True
- Character tokenization: False
- For Chinese/Yue languages:
- Join tokenized items
- Character-level split
- For first pair (i==0): print debug info
- Compute edit distance between token sequences
- Accumulate distance and reference length
- Apply language-specific normalization:
- Return:
total_distance / total_ref_length
Returns: WER as decimal (0-1)
people_speech_wer(results, args)
Aggregates WER across all results with language extraction.
Parameters:
results- List of result dicts withgt,pred,taskargs- Arguments (unused)
Process:
- For each result:
- Extract language code from task field:
task[4:](assumes format "asr_en", "asr_zh", etc.) - Extract ground truth and prediction
- Apply
remove_spnormalization - Append to refs/hyps lists
- Extract language code from task field:
- Compute WER via
compute_wer(refs, hyps, lan) - Multiply by 100 for percentage
Returns: WER percentage (0-100)
Global Normalizers
Initialized at module level:
english_normalizer:EnglishTextNormalizer()chinese_normalizer:TextNorm(...)with specific configurationbasic_normalizer:BasicTextNormalizer()
Chinese Normalizer Configuration:
TextNorm(
to_banjiao=False,
to_upper=False,
to_lower=False,
remove_fillers=False,
remove_erhua=False,
check_chars=False,
remove_space=False,
cc_mode=""
)
Dependencies
os,re,unicodedataeditdistanceased- Edit distance computationzhconv- Chinese variant conversion (simplified/traditional)lmms_eval.tasks.librispeech.cn_tn.TextNorm- Chinese text normalizationlmms_eval.tasks.librispeech.whisper_normalizer.basic.BasicTextNormalizerlmms_eval.tasks.librispeech.whisper_normalizer.english.EnglishTextNormalizersacrebleu.tokenizers.*- Multiple tokenizer implementations
Constants
PUNCS = "!,.?;:"- Punctuation characters for normalizationdir_name- Absolute path to module directory
Design Differences from Open ASR
While similar to Open_ASR_Utils, this implementation:
- Extracts language from
taskfield (format: "asr_{lang}") - Includes
sourceandtaskin result dictionaries - Assumes specific task naming convention for language extraction
- Single WER computation across all results (no per-source breakdown)
Related
- Task_Utility_Functions - General task utility pattern
- Open_ASR_Utils - Similar ASR utilities
- LibriSpeech_Utils - Speech recognition utilities
- WER_Metric - Word Error Rate metric details
- Multi_Language_Evaluation - Multi-language evaluation patterns