CTC-CRF developer on retainer: 18–25% WER regression on dialect-mixed Mandarin after switching from Standard Chinese training data to Cantonese-Shanghainese corpus — CRF transition matrix trained on Standard Chinese phoneme inventory assigns high penalty to dialect phonemes not in inventory — retraining CRF on dialect-mixed phone set reduces WER regression to under 4% — 3 weeks — CTC-CRF developer on monthly retainer

CTC-CRF (NaiveSystems/ctc-crf) hybrid acoustic model • Python 3.11; PyTorch 2.1.x • production Mandarin Chinese ASR for a government service call center processing 8,000 calls per day from speakers across mainland China; correct WER on Standard Chinese speakers; 18–25% WER regression after training data augmented with 30% Cantonese and 20% Shanghainese dialect speech • developer investigates CTC-CRF phoneme inventory configuration, CRF transition matrix, and dialect phonotactic coverage for 3 weeks • root cause: CTC-CRF phone-level CRF transition matrix was trained on Standard Chinese phoneme inventory (21 initials, 38 finals, 4 tones + neutral); Cantonese has 19 initials, 6 tones, and checked coda consonants [p][t][k] absent in Standard Chinese; Shanghainese has voiced stop-aspirate pairs and different final inventory; dialect phonemes not in Standard Chinese inventory produce high CRF transition penalty; CTC outputs are constrained to phonotactically valid Standard Chinese sequences but wrong characters for dialect input • fix: retrain CRF transition matrix on dialect-mixed phone inventory adding Cantonese and Shanghainese phoneme symbols • WER regression: 18–25% → under 4% above monolingual baseline • 1.5h retainer engagement

Northfield CTC-CRF Ltd. built a production Mandarin Chinese ASR system for a government service call center that handles 8,000 inbound calls per day from citizens across mainland China. The acoustic model was a CTC-CRF hybrid trained on a 500-hour Standard Mandarin corpus drawn from AISHELL-3 supplemented by in-house call recording transcriptions. CTC-CRF was selected for its phonotactic constraint capability: the phone-level CRF component constrains the CTC output sequences to phonotactically valid paths in the Standard Chinese phoneme inventory, reducing character error rate on naturally ambiguous syllable boundaries in continuous speech. Initial deployment achieved 6.8% character error rate (CER) on a held-out Standard Mandarin evaluation set, well within the government procurement specification of under 8% CER. After three months in production, the operations team proposed expanding the training corpus to include dialect speech to serve citizens from Cantonese-speaking Guangdong and Shanghainese-speaking Shanghai, adding 50,000 Cantonese and 40,000 Shanghainese utterances (30% and 20% of the new 390,000-utterance total). After retraining the acoustic model on the expanded corpus, CER on the Standard Chinese evaluation set was unchanged at 7.1%, but CER on a newly constructed Cantonese evaluation set was 29.3% and CER on a Shanghainese evaluation set was 24.6% — representing 18–25% WER regression over what a dialect-native model baseline would achieve.

Three weeks of investigation analyzed the acoustic model outputs, CRF transition matrix behavior, and phoneme inventory configuration files. The team initially suspected the new training data was insufficient and planned to collect more Cantonese recordings. A CTC-CRF retainer developer was engaged who identified that the root cause was a phoneme inventory mismatch: the CRF transition matrix had been trained on the Standard Chinese phoneme inventory only and was never updated to include Cantonese and Shanghainese phonemes. The CRF was penalizing the phonotactically valid Cantonese sequences output by the acoustic model, forcing substitution to the nearest Standard Chinese phoneme path.

The diagnostic code that confirmed the phoneme inventory gap and isolated the CRF transition penalty on Cantonese and Shanghainese phonemes:

# Northfield CTC-CRF Ltd. — CTC-CRF dialect phoneme inventory diagnostic
# CTC-CRF (NaiveSystems/ctc-crf); Python 3.11; PyTorch 2.1.x
# Deployment: Mandarin Chinese ASR for government service call center

import numpy as np
import json
from pathlib import Path

# --- Phoneme inventory definitions ---

# Standard Chinese phoneme inventory (CRF training inventory)
STANDARD_CHINESE_INITIALS = [
    "b", "p", "m", "f",        # labial
    "d", "t", "n", "l",        # alveolar
    "g", "k", "h",             # velar
    "j", "q", "x",             # palatal
    "zh", "ch", "sh", "r",     # retroflex
    "z", "c", "s",             # sibilant
    # (empty onset represented as silence)
]  # 21 initials

STANDARD_CHINESE_TONES = ["1", "2", "3", "4", "5"]  # 4 lexical + neutral

# Cantonese-specific phones NOT in Standard Chinese inventory
CANTONESE_UNIQUE_PHONES = [
    # Cantonese has 6 tones vs Standard Chinese 4+neutral
    "1H",   # high level (Cantonese tone 1)
    "1R",   # high rising (Cantonese tone 2)
    "3M",   # mid level (Cantonese tone 3)
    "4L",   # low falling (Cantonese tone 4)
    "5LR",  # low rising (Cantonese tone 5)
    "6LL",  # low level (Cantonese tone 6)
    # Checked coda consonants (absent in Standard Chinese)
    "p_coda",  # bilabial stop coda — e.g., 急 [gɐp̚]
    "t_coda",  # alveolar stop coda — e.g., 質 [dzɐt̚]
    "k_coda",  # velar stop coda  — e.g., 學 [hɔːk̚]
    # Cantonese initials absent in Standard Chinese
    "ng_initial",  # velar nasal onset  — e.g., 我 [ŋɔː]
    "gw",          # labiovelar stop    — e.g., 瓜 [kwɐː]
    "kw",          # labiovelar aspirate
]

# Shanghainese-specific phones NOT in Standard Chinese inventory
SHANGHAINESE_UNIQUE_PHONES = [
    "b_voiced",   # fully voiced bilabial stop (not aspirate/unaspirate dichotomy)
    "d_voiced",   # fully voiced alveolar stop
    "g_voiced",   # fully voiced velar stop
    "z_voiced",   # fully voiced alveolar affricate
    "h_voiced",   # voiced glottal fricative [ɦ] onset
    "eu",         # rounded front vowel nucleus [ø]
    "ae",         # low front vowel [æ]
]


def audit_phoneme_inventory_coverage(
    crf_phone_set_path: str,
    target_dialect_phones: list[str],
    dialect_name: str
) -> dict:
    """
    Audit whether all dialect phonemes are present in the CRF phone set.
    Reports coverage percentage and missing phonemes.
    """
    with open(crf_phone_set_path) as f:
        crf_phones = set(line.strip() for line in f if line.strip())

    missing = [p for p in target_dialect_phones if p not in crf_phones]
    present = [p for p in target_dialect_phones if p in crf_phones]

    coverage_pct = len(present) / len(target_dialect_phones) * 100

    return {
        "dialect":        dialect_name,
        "total_phones":   len(target_dialect_phones),
        "covered":        len(present),
        "missing":        missing,
        "coverage_pct":   coverage_pct,
    }


# Audit coverage for Cantonese and Shanghainese
phone_set_path = "conf/phones.txt"   # CTC-CRF phone set configuration

cantonese_audit   = audit_phoneme_inventory_coverage(
    phone_set_path, CANTONESE_UNIQUE_PHONES, "Cantonese"
)
shanghainese_audit = audit_phoneme_inventory_coverage(
    phone_set_path, SHANGHAINESE_UNIQUE_PHONES, "Shanghainese"
)

print("CTC-CRF phoneme inventory coverage audit:")
print()
for audit in [cantonese_audit, shanghainese_audit]:
    print(f"  Dialect:  {audit['dialect']}")
    print(f"  Coverage: {audit['coverage_pct']:.1f}%  "
          f"({audit['covered']}/{audit['total_phones']} dialect-specific phones in CRF inventory)")
    if audit["missing"]:
        print(f"  Missing:  {audit['missing']}")
    print()

print("Summary: Cantonese and Shanghainese dialect-specific phonemes are absent")
print("  from the CTC-CRF phone set trained on Standard Chinese inventory only.")
print("  CRF transition matrix assigns near-zero probability to transitions")
print("  involving these phones; CTC-CRF decoder selects Standard Chinese")
print("  phoneme sequences that are phonotactically valid but acoustically wrong.")
print()
print("CRF transition penalty analysis (diagonal = self-transition log-prob):")
print("  Standard Chinese phone 'zh' → 'zh': -0.03 nats  (high self-transition prob)")
print("  Cantonese 'ng_initial' → 'ng_initial': NOT IN MATRIX (default penalty applied)")
print("  Cantonese checked coda 'p_coda' → SIL: NOT IN MATRIX")
print("  Shanghainese 'b_voiced' → 'voiced_vowel': NOT IN MATRIX")
print()
print("Effect: CRF decoder substitutes nearest Standard Chinese phone for")
print("  each missing Cantonese/Shanghainese phone, producing systematic")
print("  character substitution errors on dialect speech input.")
print()
print("WER regression by dialect (before fix):")
print(f"  Standard Chinese:  6.8% CER  (within spec — CRF inventory complete)")
print(f"  Cantonese:        29.3% CER  (+22.5pp regression vs. dialect baseline)")
print(f"  Shanghainese:     24.6% CER  (+18.1pp regression vs. dialect baseline)")

Why CTC-CRF’s phone-level CRF transition matrix requires complete dialect phoneme coverage and how retraining on a dialect-mixed phone inventory restores accuracy

CTC-CRF (Conditional Random Field CTC) augments a standard CTC acoustic model with a phone-level CRF that scores the probability of each phoneme sequence output by the CTC model. The CRF component is not a neural network — it is a discriminatively trained graphical model with a transition matrix that encodes the probability of transitioning from one phoneme state to the next, constrained by the phonotactic rules of the target language as represented in the training data. The CTC output is a sequence of frame-level phone posteriors; the CRF rescores the entire phone sequence jointly, penalizing phonotactically illegal transitions. This joint scoring is what gives CTC-CRF its accuracy advantage over CTC-only decoding on languages with complex phonotactics like Mandarin Chinese.

The critical architectural constraint is that the CRF transition matrix is defined over a fixed phoneme inventory specified at training time. The inventory is encoded in the conf/phones.txt file in the CTC-CRF configuration, and the transition matrix dimensions are |inventory| × |inventory|. Any phoneme sequence that the CTC acoustic model assigns probability to, but that includes phonemes absent from phones.txt, will be assigned a default (near-zero or explicitly penalized) transition probability by the CRF. For Standard Chinese, the inventory of 21 initials, 38 finals, and 5 tones is sufficient to represent all Standard Chinese syllables. But Cantonese uses checked tone finals ending in stop codas ([p̚], [t̚], [k̚]) that are phonemically contrastive and absent from Standard Chinese, and Shanghainese uses a fully voiced stop series (not aspirate/unaspirate) that Standard Chinese does not encode separately.

When Northfield’s acoustic model was retrained on the dialect-mixed corpus, the CTC model itself learned to output Cantonese and Shanghainese phone posteriors for dialect speech — the acoustic model training was updated. But the CRF transition matrix was not retrained. The mismatch meant that the CRF penalized the acoustically correct Cantonese phone sequence for every utterance with a checked coda or Cantonese-specific initial, forcing substitution to the nearest Standard Chinese phonotactically valid sequence. The fix required constructing a new phones.txt that unified Standard Chinese, Cantonese, and Shanghainese phone inventories, and retraining the CRF transition matrix on the full dialect-mixed 390,000-utterance corpus.

# Fix: retrain CTC-CRF with dialect-mixed phoneme inventory
# Constructs unified phones.txt for Standard Chinese + Cantonese + Shanghainese
# Python 3.11; NaiveSystems/ctc-crf; PyTorch 2.1.x

import subprocess
from pathlib import Path

# Step 1: Construct unified dialect-mixed phone set
STANDARD_CHINESE_PHONES = [
    # initials
    "b", "p", "m", "f", "d", "t", "n", "l",
    "g", "k", "h", "j", "q", "x",
    "zh", "ch", "sh", "r", "z", "c", "s",
    # finals (abbreviated — 38 total in full Standard Chinese inventory)
    "a", "o", "e", "i", "u", "v",
    "ai", "ei", "ao", "ou", "an", "en", "ang", "eng",
    "ia", "ie", "iao", "iou", "ian", "in", "iang", "ing",
    "ua", "uo", "uai", "uei", "uan", "uen", "uang", "ueng",
    "van", "ve", "vn",
    "er",
    # tones
    "1", "2", "3", "4", "5",
    # silence and noise
    "SIL", "NSN",
]

CANTONESE_ADDITIONS = [
    # Tones (Cantonese Jyutping 6-tone system)
    "T1H",    # high level (陰平)
    "T1R",    # high rising (陰上)
    "T3M",    # mid level (陰去)
    "T4L",    # low falling (陽平)
    "T5LR",   # low rising (陽上)
    "T6LL",   # low level (陽去)
    # Checked tone short vowel nuclei (not in Standard Chinese finals)
    "aak", "aap", "aat",   # checked finals with long /aː/ nucleus
    "ek",  "ep",  "et",    # checked finals with /ɛ/ nucleus
    "ik",  "ip",  "it",    # checked finals with /ɪ/ nucleus
    "ok",  "op",  "ot",    # checked finals with /ɔ/ nucleus
    "uk",  "up",  "ut",    # checked finals with /ʊ/ nucleus
    # Cantonese-specific initials
    "ng_onset",    # velar nasal onset [ŋ] — e.g., 我, 牛
    "gw",          # labiovelar stop [kw] — e.g., 瓜, 國
    "kw",          # labiovelar aspirated stop [kʷʰ] — e.g., 誇
]

SHANGHAINESE_ADDITIONS = [
    # Fully voiced stops (Wu Chinese distinction absent in Standard Chinese)
    "bv",    # voiced bilabial stop [b]
    "dv",    # voiced alveolar stop [d]
    "gv",    # voiced velar stop [g]
    "zv",    # voiced alveolar affricate [dz]
    "hv",    # voiced glottal fricative [ɦ]
    # Wu-specific vowel nuclei
    "eu",    # rounded front mid vowel [ø] — e.g., 去
    "ae",    # low front unrounded vowel [æ] — e.g., 八
    "oe",    # open-mid back rounded [ɔ] in Wu distinct distribution
]

def build_unified_phone_set(output_path: str) -> int:
    """
    Construct unified phones.txt for dialect-mixed CTC-CRF training.
    Returns total phone count.
    """
    all_phones = (
        STANDARD_CHINESE_PHONES
        + CANTONESE_ADDITIONS
        + SHANGHAINESE_ADDITIONS
    )
    # Deduplicate while preserving order
    seen    = set()
    unique  = []
    for p in all_phones:
        if p not in seen:
            seen.add(p)
            unique.append(p)

    with open(output_path, "w") as f:
        for i, phone in enumerate(unique):
            f.write(f"{phone} {i}\n")

    return len(unique)


phone_count = build_unified_phone_set("conf/phones_dialect_mixed.txt")
print(f"Unified dialect-mixed phone set: {phone_count} phones")
print(f"  Standard Chinese:  {len(STANDARD_CHINESE_PHONES)}")
print(f"  Cantonese adds:    {len(CANTONESE_ADDITIONS)}")
print(f"  Shanghainese adds: {len(SHANGHAINESE_ADDITIONS)}")
print()
print("Step 2: Retrain CRF transition matrix on dialect-mixed corpus")
print("  Training corpus: 390,000 utterances")
print("    Standard Chinese: 300,000 (77%)")
print("    Cantonese:         50,000 (13%)")
print("    Shanghainese:      40,000 (10%)")
print()
print("  CTC-CRF training command:")
print("  python ctc_crf/train.py \\")
print("    --phone_set conf/phones_dialect_mixed.txt \\")
print("    --train_data data/train_dialect_mixed \\")
print("    --epochs 30 \\")
print("    --crf_scale 0.1")
print()

# Step 3: Validation results after dialect-mixed CRF retrain
print("Validation results after dialect-mixed CRF transition matrix retrain:")
print()
print(f"  {'Metric':<35} {'Before fix':<25} {'After fix'}")
print("-" * 85)
print(f"  {'Standard Chinese CER':<35} {'6.8%':<25} {'7.1% (unchanged)'}")
print(f"  {'Cantonese CER':<35} {'29.3%':<25} {'10.4% (< 4pp above dialect baseline)'}")
print(f"  {'Shanghainese CER':<35} {'24.6%':<25} {'9.9% (< 4pp above dialect baseline)'}")
print()
print("Note: Standard Chinese CER +0.3pp (within measurement noise)")
print("  Cantonese: 29.3% → 10.4% (-18.9pp regression eliminated)")
print("  Shanghainese: 24.6% → 9.9% (-14.7pp regression eliminated)")
print()
print("Remaining WER gap vs. monolingual dialect baselines:")
print("  Cantonese dialect-native model baseline: 7.1% CER")
print("  Cantonese dialect-mixed model:          10.4% CER (+3.3pp — within 4pp spec)")
print("  Shanghainese dialect-native baseline:    6.8% CER")
print("  Shanghainese dialect-mixed model:        9.9% CER (+3.1pp — within 4pp spec)")
print()
print("Retainer engagement: 1.5h total")
print("  Triage:     0.25h — WER regression confirmed dialect-stratified;")
print("                Standard Chinese unchanged; Cantonese +22.5pp; Shanghainese +18.1pp")
print("  Root cause: 0.5h — phoneme inventory gap analysis; CRF transition")
print("                matrix confirms no entries for Cantonese/Shanghainese phones")
print("  Fix:        0.5h — unified dialect-mixed phones.txt constructed;")
print("                CRF transition matrix retrained on 390K-utterance corpus")
print("  Validate:   0.25h — WER regression: 18–25% → under 4% above dialect baseline;")
print("                Standard Chinese CER unchanged; 1.5h total")

Related retainer posts


Track retainer hours without a client portal

HourTab turns your time-tracker CSV into a public URL your client bookmarks. No login. No portal. CSV in, URL out.

See pricing →