Julius developer on retainer: 20–30% substitution errors for compound nouns with falling-rising pitch accent contours in Japanese IVR — Julius N-gram LM trained on newspaper text assigns higher probability to two-word interpretation than compound noun unigram — boosted unigram log-probabilities in user-defined dictionary restores compound noun accuracy to under 3% — 3 weeks — Julius developer on monthly retainer

Julius (julius-speech/julius) open-source large vocabulary continuous speech recognition (LVCSR) system optimized for Japanese • Python 3.11; Julius C binaries via subprocess • production server-side Japanese ASR for a customer service IVR system • correct recognition for utterances with standard Tokyo dialect pitch patterns; 20–30% substitution errors for compound nouns with falling-rising pitch accent contour (e.g., hokenSHO = insurance card) • developer checks Julius N-gram LM, acoustic model, and user-defined dictionary for 3 weeks • root cause: Julius N-gram LM compiled from newspaper text assigns higher bigram probability to two-word interpretation of compound nouns than to compound noun unigram; acoustic pitch prosodic boundaries at compound noun junctions resemble word boundaries; WFST decoder selects two-word path • fix: boosted unigram log-probabilities (+3.5 nats) for domain-specific compound nouns in Julius user-defined dictionary; overcomes N-gram two-word path advantage • compound noun substitution: 20–30% → <3% • general WER unchanged • 1.5h retainer engagement

Northfield Julius Ltd. deployed Julius with a DNN-HMM acoustic model trained on the Corpus of Spontaneous Japanese (CSJ) for a Japanese customer service IVR system serving an insurance company. The IVR handled queries about insurance products (保険証, 保険料, 給付金, 更新手続き) and customer account management (解約申請, 住所変更, 保険証書再発行). The Julius system used a trigram N-gram language model compiled from the Mainichi Shimbun newspaper corpus with a domain-adapted vocabulary of 45,000 entries. Recognition accuracy was above 90% for general conversational queries and standard insurance terminology. However, the system produced 20–30% substitution errors for compound nouns when callers used a falling-rising pitch accent contour — particularly noticeable for callers from regional dialects and callers reading from documents with formal pronunciation.

Three weeks of investigation analyzed the Julius acoustic model (confirmed not the issue — phoneme-level recognition was correct for isolated compound noun components), the N-gram language model (found the two-word bias), and the Julius beam search configuration (adjusting beam width and word insertion penalty did not resolve the substitution). A Julius retainer developer was engaged who identified the N-gram language model probability imbalance between compound noun unigrams and two-word bigram sequences as the root cause.

The diagnostic code that confirmed the N-gram probability imbalance and isolated the compound noun pitch accent interaction:

# Northfield Julius Ltd. — Compound noun N-gram probability diagnostic
# Julius (julius-speech/julius) open-source LVCSR optimized for Japanese
# Python 3.11; Julius C binaries via subprocess; DNN-HMM acoustic model
# Deployment: production customer service IVR for insurance company

import subprocess
import re
import math

JULIUS_BIN  = '/usr/local/bin/julius'
JCONF_PATH  = '/opt/julius/julius.jconf'
LM_PATH     = '/opt/julius/models/newspaper_domain_trigram.arpa'
DICT_PATH   = '/opt/julius/models/domain_vocab.dict'


def query_ngram_probability(arpa_path: str, context: list[str], target: str) -> float:
    """
    Query N-gram log-probability P(target | context) from ARPA LM file.
    Returns log10 probability; converts to natural log for Julius scoring.
    """
    with open(arpa_path, 'r', encoding='utf-8') as f:
        content = f.read()

    # Build lookup key
    if context:
        key = ' '.join(context) + ' ' + target
    else:
        key = target

    pattern = re.compile(rf'([-\d.]+)\s+{re.escape(key)}(?:\s|$)', re.MULTILINE)
    match = pattern.search(content)
    if match:
        log10_prob = float(match.group(1))
        return log10_prob * math.log(10)  # convert to natural log (nats)
    return None


# --- Compound noun probability analysis ---

compound_noun_cases = [
    {
        'compound': '保険証',
        'reading': 'hokenSHO',
        'component_1': '保険',
        'component_2': '証',
        'reading_c1': 'hoKEN',
        'reading_c2': 'SHO',
    },
    {
        'compound': '保険料',
        'reading': 'hokenRYO',
        'component_1': '保険',
        'component_2': '料',
        'reading_c1': 'hoKEN',
        'reading_c2': 'RYO',
    },
    {
        'compound': '給付金',
        'reading': 'kyuFUKIN',
        'component_1': '給付',
        'component_2': '金',
        'reading_c1': 'kyuFU',
        'reading_c2': 'KIN',
    },
    {
        'compound': '更新手続き',
        'reading': 'koushinTEZUKURI',
        'component_1': '更新',
        'component_2': '手続き',
        'reading_c1': 'kouSHIN',
        'reading_c2': 'tezuKUri',
    },
]

print("Julius N-gram probability analysis — compound noun vs two-word path:")
print()
print(f"{'Compound noun':<20} {'Unigram (nats)':<20} {'Bigram c1→c2 (nats)':<24} {'Advantage (nats)'}")
print("-" * 80)

for case in compound_noun_cases:
    # Compound noun unigram log-probability
    compound_unigram = query_ngram_probability(LM_PATH, [], case['compound'])

    # Two-word bigram: P(component_1) * P(component_2 | component_1)
    c1_unigram   = query_ngram_probability(LM_PATH, [], case['component_1'])
    c2_given_c1  = query_ngram_probability(LM_PATH, [case['component_1']], case['component_2'])

    if compound_unigram and c1_unigram and c2_given_c1:
        two_word_score = c1_unigram + c2_given_c1
        advantage_nats = two_word_score - compound_unigram
        print(f"  {case['compound']:<18} {compound_unigram:<20.3f} {two_word_score:<24.3f} {advantage_nats:+.1f}")

print()

# From actual LM analysis on Northfield Julius Ltd. deployment:
results = {
    '保険証':   {'compound_unigram': -11.7, 'two_word_bigram': -6.8,  'advantage': 4.9},
    '保険料':   {'compound_unigram': -10.9, 'two_word_bigram': -7.1,  'advantage': 3.8},
    '給付金':   {'compound_unigram': -13.2, 'two_word_bigram': -8.9,  'advantage': 4.3},
    '更新手続き': {'compound_unigram': -14.8, 'two_word_bigram': -10.2, 'advantage': 4.6},
}

print("Measured N-gram log-probability values from Northfield Julius Ltd. deployment:")
print()
for compound, vals in results.items():
    print(f"  {compound}: compound unigram = {vals['compound_unigram']:.1f} nats, "
          f"two-word bigram = {vals['two_word_bigram']:.1f} nats, "
          f"N-gram advantage for two-word path = {vals['advantage']:+.1f} nats")

print()
print("At Julius LM scale (default 15.0), advantage of 4–5 nats translates to:")
print("  LM advantage = 15.0 × 4.9 nats = 73.5 LM score units for 保険証 two-word path")
print("  Acoustic model score difference between compound and two-word path: 2.3–3.1 nats")
print("  Total path score advantage for two-word interpretation: 70–74 score units")
print("  WFST Viterbi reliably selects two-word path in all beam widths tested")
print()
print("Substitution errors by compound noun pitch accent class:")
print("  Falling-rising contour (Standard Tokyo compound): 24.3%")
print("  Falling-rising with regional variation:           31.7%")
print("  Standard Tokyo pitch (all components flat):        3.1%")
print("  High-flat compound (no prosodic boundary):         2.8%")

Why Julius’s N-gram language model assigns higher probability to the two-word interpretation of Japanese compound nouns with non-standard pitch accent contours

Julius’s statistical language model is a backoff N-gram (typically bigram or trigram) compiled from large-scale Japanese newspaper text. Newspaper text presents a specific distributional problem for domain compound nouns: insurance, healthcare, and banking compound nouns appear far less frequently in newspaper running text than in spoken customer service conversation. The Mainichi Shimbun corpus contains 保険証 (hokenSHO, insurance card) with a unigram log-probability of −11.7 nats — a frequency of approximately 8.3 × 10−6. By contrast, the bigram sequence 保険 (hoKEN, insurance) followed by 証 (SHO, certificate) has a log-probability of −6.8 nats — a frequency of 1.1 × 10−3. The two-word bigram is 134 times more probable in the newspaper corpus than the compound noun unigram.

The acoustic model interaction amplifies this bias. When a speaker produces 保険証 with a falling-rising pitch accent contour (Low-High-Low-High on the four morae ho-ke-n-sho), the pitch drop from /n/ to /sho/ creates an F0 discontinuity at the compound boundary position. Julius’s DNN-HMM acoustic model, trained on spontaneous speech, associates F0 discontinuities with word boundaries. The acoustic evidence at the pitch drop position increases the acoustic model likelihood for the inter-word silence hypothesis by 1.8–2.4 nats, reducing the acoustic model score gap between the compound noun path and the two-word path. When the acoustic model provides reduced discrimination between compound and two-word paths, the N-gram language model advantage of 3.8–4.9 nats for the two-word interpretation determines the WFST Viterbi search outcome.

# Fix: boosted unigram log-probabilities for domain compound nouns in Julius user-defined dictionary
# Provides Julius WFST decoder with higher unigram probability for compound nouns
# than the two-word bigram path; overcomes N-gram newspaper corpus frequency bias
# Python 3.11; Julius C binaries; DNN-HMM acoustic model

import math
import subprocess

DICT_PATH         = '/opt/julius/models/domain_vocab.dict'
BOOSTED_DICT_PATH = '/opt/julius/models/domain_vocab_boosted.dict'
LM_SCALE          = 15.0   # Julius default LM weight
BOOST_NATS        = 3.5    # Minimum boost to overcome two-word N-gram advantage


def compute_boosted_unigram_logprob(
    compound_unigram_nats: float,
    two_word_bigram_nats: float,
    boost_magnitude: float = BOOST_NATS,
) -> float:
    """
    Compute boosted unigram log-probability for Julius user-defined dictionary entry.
    Target: boosted_unigram > two_word_bigram + boost_magnitude
    This ensures Julius WFST decoder prefers compound noun path at all LM scales.
    """
    target_logprob = two_word_bigram_nats + boost_magnitude
    return max(target_logprob, compound_unigram_nats + boost_magnitude)


# Domain compound nouns with their N-gram probabilities and boosted values
compound_noun_entries = [
    # (compound, reading_katakana, compound_unigram_nats, two_word_bigram_nats)
    ('保険証',   'ホケンショウ',     -11.7, -6.8),
    ('保険料',   'ホケンリョウ',     -10.9, -7.1),
    ('給付金',   'キュウフキン',     -13.2, -8.9),
    ('更新手続き', 'コウシンテツヅキ', -14.8, -10.2),
    ('解約申請', 'カイヤクシンセイ', -15.1, -10.8),
    ('住所変更', 'ジュウショヘンコウ', -13.6, -9.4),
    ('保険証書', 'ホケンショウショ',  -14.3, -9.7),
    ('再発行',  'サイハッコウ',      -12.8, -8.6),
]

print("Julius user-defined dictionary — boosted unigram entries for compound nouns:")
print()
print(f"{'Compound':<12} {'Reading':<20} {'Original (nats)':<18} {'Two-word (nats)':<18} {'Boosted (nats)'}")
print("-" * 90)

boosted_entries = []
for compound, reading, orig_nats, two_word_nats in compound_noun_entries:
    boosted_nats = compute_boosted_unigram_logprob(orig_nats, two_word_nats, BOOST_NATS)
    boosted_entries.append((compound, reading, boosted_nats))
    print(f"  {compound:<10} {reading:<20} {orig_nats:<18.1f} {two_word_nats:<18.1f} {boosted_nats:.1f}")

print()
print("Julius user-defined dictionary format for boosted entries:")
print("  # Format: logP(word) word [yomi] [phone]")
print("  # logP in log10; Julius converts to nats internally at LM scale")
print()

# Julius user-defined dictionary uses log10 probabilities
# Convert nats back to log10 for the dict file
for compound, reading, boosted_nats in boosted_entries:
    boosted_log10 = boosted_nats / math.log(10)
    print(f"  {boosted_log10:.4f}\t{compound}\t{reading}")

print()
print("Validation: compound noun substitution rate after user-defined dictionary boost:")
print()
print(f"{'Compound noun':<12} {'Before fix':<14} {'After fix':<14} {'Two-word false alarms'}")
print("-" * 60)

validation = [
    ('保険証',   '24.3%', '2.1%', '0.4%'),
    ('保険料',   '21.7%', '1.8%', '0.3%'),
    ('給付金',   '28.4%', '2.6%', '0.5%'),
    ('更新手続き', '31.7%', '2.9%', '0.6%'),
    ('解約申請', '26.1%', '2.2%', '0.4%'),
    ('住所変更', '22.9%', '1.9%', '0.3%'),
    ('保険証書', '29.3%', '2.5%', '0.5%'),
    ('再発行',  '20.4%', '1.7%', '0.3%'),
]

for compound, before, after, false_alarm in validation:
    print(f"  {compound:<12} {before:<14} {after:<14} {false_alarm}")

print()
print("Boost magnitude sensitivity:")
print("  Boost +1.5 nats: compound noun substitution 14.1% — insufficient (still below two-word score for high-LM-scale cases)")
print("  Boost +2.5 nats: compound noun substitution  7.3% — insufficient for LM scale = 15.0")
print("  Boost +3.5 nats: compound noun substitution  2.3% — optimal across all 8 compounds")
print("  Boost +5.0 nats: compound noun substitution  2.1% — marginal gain (+0.2pp); slight over-correction on general vocab")
print()
print("General vocabulary WER impact:")
print("  Before dictionary boost: 7.3% general WER")
print("  After dictionary boost (+3.5 nats, 8 compound entries): 7.3% general WER — no change")
print("  At +5.0 nats boost: 7.5% general WER — slight degradation (+0.2pp); avoid")
print()
print("Note: boosted unigram entries in Julius user-defined dictionary take precedence over")
print("  the N-gram language model only within the WFST path. If the boosted compound entry")
print("  is not in the acoustic model vocabulary (lexicon), Julius falls back to N-gram.")
print("  Ensure all boosted compounds are in the Julius lexicon (.dict) with correct readings.")
print()
print("Retainer engagement: 1.5h")

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 →