Skip to content
How-to GuideUnreviewed

Train the onset/rime recognizer

Prepare normalized Mandarin singing annotations, extract frozen SSL features, train temporal onset/rime recognizers, and run text-free evaluation or Pinyin forced alignment. Before starting, set up the isolated local/third_party/phonespam-env environment from Run phone recognition inference and alignment and configure infra/runtime/local.toml.

Two recognizer variants share the same frozen feature cache:

  • Model A: Trains directly on frozen SSL representations.
  • Model B: Combines frozen SSL representations with calibrated SPAM articulatory feature projections.

For duration-budgeted comparisons, extract the full cache (local/data/phone-recognition/onset-rime/manifest.json) once, then create a subset manifest (such as local/data/phone-recognition/few-shot/5m-seed42/manifest.json) in Run few-shot recognition experiments before calibrating and training.

Prepare annotations

Normalize annotations across corpora into the shared onset/rime inventory while holding out songs and official test sets across all sources:

uv run --project research/phone-recognition phone-recognition recognizer prepare \
  --source opencpop \
  --source m4singer \
  --source gtsinger \
  --runtime infra/runtime/local.toml \
  --output local/data/phone-recognition/onset-rime \
  --annotations-only

Pass --source opencpop=local/data/custom/opencpop to override dataset directories, --validation-speaker opencpop:singer1 to hold out individual singers, or --count to cap recordings per partition for quick checks. Include human-corrected bundles with --bundle. Bundles without song metadata stay grouped within one partition.

Extract features and calibrate SPAM

Feature extraction reads 16 kHz audio at the encoder’s native stride by using local/third_party/phonespam-env (pass --python to use another environment). For XEUS, follow Extract XEUS features and train recognizers, which uses the native ESPnet extractor and reuses the cache for SPAM calibration.

Extract frozen SSL features once from the prepared jobs.json (for MMS, pass --backbone facebook/mms-300m --layer-index -1):

uv run --project research/phone-recognition phone-recognition recognizer extract \
  local/data/phone-recognition/onset-rime/jobs.json \
  --backbone microsoft/wavlm-large \
  --layer-index -1 \
  --device cpu

Calibrate a SPAM projection if you plan to train Model B (Model A does not require calibration). Calibration reads only the training partition of the feature cache, excludes compounds and breaths, and inherits the encoder selection and timing without rerunning the encoder:

uv run --project research/phone-recognition phone-recognition calibrate \
  --dataset local/data/phone-recognition/onset-rime/manifest.json \
  --output local/assets/spam/onset-rime.pt \
  --count 500

Corpus names, annotation jobs, and bundles also work directly with calibrate when no feature cache exists.

Train recognizers

The default temporal network (research/phone-recognition/configs/base.toml) trains CTC sequence, segment-balanced frame, and boundary heads. Set --device cuda or --device mps when available, and pass --resume to continue an interrupted run in place.

Train Model A on the full extracted manifest (or pass a few-shot subset manifest such as local/data/phone-recognition/few-shot/5m-seed42/manifest.json):

uv run --project research/phone-recognition phone-recognition recognizer train \
  local/data/phone-recognition/onset-rime/manifest.json \
  --config research/phone-recognition/configs/base.toml \
  --output local/runs/phone-recognition/a

To run a single-objective baseline without the frame and boundary heads, pass --config research/phone-recognition/configs/ctc.toml. That profile trains only the CTC phone sequence and aligns predictions with CTC Viterbi, testing whether the extra heads help under low-data budgets.

Train Model B by passing the calibrated SPAM checkpoint from the same feature cache:

uv run --project research/phone-recognition phone-recognition recognizer train \
  local/data/phone-recognition/onset-rime/manifest.json \
  --config research/phone-recognition/configs/base.toml \
  --output local/runs/phone-recognition/b \
  --use-spam-features \
  --spam-checkpoint local/assets/spam/onset-rime.pt

Train a separate boundary model

To fit a separate timestamp model without retraining the phone classifier, supply a --sequence-checkpoint from a joint recognizer that uses the exact same encoder and phone vocabulary. This example trains the boundary head on a five-minute few-shot subset manifest (local/data/phone-recognition/few-shot/5m-seed42/manifest.json), optimizing boundary BCE only and selecting its checkpoint by validation F1@20ms:

uv run --project research/phone-recognition phone-recognition recognizer train \
  local/data/phone-recognition/few-shot/5m-seed42/manifest.json \
  --config research/phone-recognition/configs/boundary.toml \
  --sequence-checkpoint local/runs/phone-recognition/a/best.pt \
  --output local/runs/phone-recognition/a-boundary \
  --device mps

During frame decoding, the phone checkpoint supplies CTC and frame scores while the boundary checkpoint supplies boundary scores.

Evaluate and align

Evaluate a trained checkpoint on a held-out split to report PER, content phone substitutions, deletions, insertions, boundary F1, and onset timing error:

uv run --project research/phone-recognition phone-recognition recognizer evaluate \
  local/data/phone-recognition/onset-rime/manifest.json \
  --checkpoint local/runs/phone-recognition/a/best.pt \
  --split validation \
  --output local/runs/phone-recognition/a/validation.json

For a joint recognizer, evaluate with --decoder frame-align to search complete phone paths using frame scores, boundary evidence, legal onset/rime transitions, and optional CTC phone-vs-blank evidence before realigning boundaries:

uv run --project research/phone-recognition phone-recognition recognizer evaluate \
  local/data/phone-recognition/onset-rime/manifest.json \
  --checkpoint local/runs/phone-recognition/a/best.pt \
  --split validation \
  --decoder frame-align \
  --frame-ctc-weight 2 \
  --boundary-weight 0.3 \
  --transition-penalty 5

Run text-free inference against an evaluation bundle for inspection on the Dashboard (add --decoder frame-align --frame-ctc-weight 2 --boundary-weight 0.3 to use the experimental joint decoder):

uv run --project research/phone-recognition phone-recognition infer \
  local/data/phone-recognition/custom/manifest.json \
  --model recognizer \
  --checkpoint local/runs/phone-recognition/a/best.pt \
  --track-id onset-rime-a \
  --runtime infra/runtime/local.toml

Force-align an audio recording by using reference Pinyin (leading, trailing, and inter-syllable pauses are automatically absorbed as SP):

uv run --project research/phone-recognition phone-recognition recognizer align \
  local/data/recordings/sample.wav \
  --pinyin "xiang liang" \
  --checkpoint local/runs/phone-recognition/a/best.pt \
  --output local/data/phone-recognition/aligned.json

Type to search…

↑↓ navigate↵ selectEsc close