Skip to main content
The normalizers module provides utilities for normalizing and standardizing text output from Whisper models. These tools help compare transcriptions by removing formatting differences, converting numbers, and standardizing spellings.

BasicTextNormalizer

Basic text normalizer that lowercases text, removes brackets/parentheses content, and optionally removes diacritics.

Initialization

bool
default:"False"
If True, removes diacritical marks from characters (e.g., “café” → “cafe”)
bool
default:"False"
If True, splits text into individual Unicode grapheme clusters (useful for character-level analysis)

Normalization Process

The BasicTextNormalizer performs the following operations:
  1. Converts text to lowercase
  2. Removes content within angle brackets or square brackets: <...>, [...]
  3. Removes content within parentheses: (...)
  4. Optionally removes diacritics and symbols (if remove_diacritics=True)
  5. Optionally splits into individual letters/graphemes (if split_letters=True)
  6. Collapses multiple whitespace characters into single spaces

Examples

Basic Usage

With Diacritics Removal

With Letter Splitting

EnglishTextNormalizer

Comprehensive English text normalizer that expands contractions, standardizes numbers, and normalizes spellings.

Normalization Process

The EnglishTextNormalizer performs extensive normalization:
  1. Converts text to lowercase
  2. Removes content in brackets/parentheses: <...>, [...], (...)
  3. Removes filler words: “hmm”, “mm”, “mhm”, “uh”, “um”
  4. Expands contractions: “can’t” → “can not”, “won’t” → “will not”
  5. Expands titles and abbreviations: “Mr.” → “mister”, “Dr.” → “doctor”
  6. Standardizes numbers: converts spelled-out numbers to digits
  7. Normalizes spellings: British to American English
  8. Removes symbols and punctuation (keeping numeric symbols during processing)
  9. Collapses whitespace

Examples

Contraction Expansion

Title and Abbreviation Expansion

Number Normalization

Spelling Normalization

Complete Example

EnglishNumberNormalizer

Specialized normalizer for converting spelled-out numbers to Arabic numerals.

Features

  • Converts spelled-out numbers to digits
  • Removes commas from numbers
  • Preserves suffixes: “1960s”, “21st”, “32nd”
  • Handles currency symbols: “$20 million” → “20000000 dollars”
  • Interprets successive single digits: “one oh one” → “101”
  • Supports special patterns: “double three” → “33”, “triple five” → “555”

Examples

Basic Number Conversion

Ordinals and Cardinals

Currency and Symbols

Special Patterns

Signs and Prefixes

EnglishSpellingNormalizer

Normalizes British English spellings to American English.

Examples

Utility Functions

remove_symbols_and_diacritics()

Removes symbols, punctuation, and diacritical marks from text.
str
required
Input text to process
str
default:"\"\""
String of characters to preserve (e.g., ”.$” to keep dollar signs and periods)
str
Text with symbols and diacritics removed (replaced with spaces), except for characters in keep

remove_symbols()

Removes symbols and punctuation while preserving diacritics.
str
required
Input text to process
str
Text with symbols and punctuation removed (replaced with spaces), but diacritics preserved

Use Cases

Comparing Transcriptions

Calculating Word Error Rate (WER)

Multilingual Text Cleaning

Preprocessing for Search/Indexing

Diacritics Mapping

The following special characters are mapped when remove_diacritics=True: Additionally, all Unicode characters with the “Mn” (Mark, nonspacing) category are removed.