Automatic Speech Recognition
Transformers
Safetensors
Japanese
dual_ctc
feature-extraction
ctc
wavlm
japanese
hiragana
phoneme
custom_code
Instructions to use TylorShine/wavlm-base-plus-hiragana-ctc-v2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use TylorShine/wavlm-base-plus-hiragana-ctc-v2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("automatic-speech-recognition", model="TylorShine/wavlm-base-plus-hiragana-ctc-v2", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("TylorShine/wavlm-base-plus-hiragana-ctc-v2", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
| language: | |
| - ja | |
| license: cc-by-sa-3.0 | |
| library_name: transformers | |
| tags: | |
| - automatic-speech-recognition | |
| - ctc | |
| - wavlm | |
| - japanese | |
| - hiragana | |
| - phoneme | |
| - custom_code | |
| pipeline_tag: automatic-speech-recognition | |
| base_model: microsoft/wavlm-base-plus | |
| # wavlm-base-plus-hiragana-ctc | |
| WavLMをベースに、ひらがなと音素のデュアルCTC(Dual CTC)ヘッドを搭載した軽量な日本語音声認識(ASR)モデルです。 | |
| 自己回帰デコーダを持たないため繰り返すハルシネーションを起こさず、ひらがな(および音素)のみを安定して出力します。 | |
| 前バージョンの [`wavlm-base-plus-hiragana-ctc`](https://huggingface.co/TylorShine/wavlm-base-plus-hiragana-ctc) から、音素CTCとかなCTCのHead両方をMLPに変更しています。 | |
| このモデルはカスタムアーキテクチャを採用しており、Hugging Faceの `AutoModel` (`trust_remote_code=True`) を使用して簡単に読み込むことができます。 | |
| ## 🚀 元モデルからの変更点 | |
| オリジナルである [`japanese-wav2vec2-large-hiragana-ctc`](https://huggingface.co/sakasegawa/japanese-wav2vec2-large-hiragana-ctc) から以下の点を変更しています。 | |
| 1. **ベースモデルを WavLM に変更** | |
| よりノイズに強く、幅広い音声表現を獲得できる [WavLM-Base-Plus](https://huggingface.co/microsoft/wavlm-base-plus) をエンコーダに採用しました。 | |
| 2. **Head位置の変更** | |
| [WavLM: Large-Scale Self-Supervised Pre-Training for Full Stack Speech Processing](https://arxiv.org/abs/2110.13900) のデータを参考に、音素CTCとかなCTCのHead位置を変更しました。 | |
| 3. **Hugging Face `AutoModel` ネイティブ対応** | |
| カスタムモジュール (`modeling_dual_ctc.py`) を同梱したため、ローカルのチェックポイントファイルを意識することなく、`transformers` から直接モデルをロードして推論できるようになりました。 | |
| ## 🏗 Architecture | |
| ```text | |
| Audio (16kHz) → WavLM Encoder | |
| ├── Intermediate Layer 9 → Kana CTC Head (84 classes) | |
| └── Intermediate Layer 11 → Phoneme CTC Head (44 classes) | |
| ``` | |
| ## 💻 Usage | |
| 本モデルはカスタムコード(`DualCTCModel`)を使用しているため、ロード時に `trust_remote_code=True` を指定する必要があります。 | |
| ### インストール | |
| ```bash | |
| pip install torch torchaudio transformers | |
| ``` | |
| ### 推論コードの例 | |
| ```python | |
| import torch | |
| import torchaudio | |
| from transformers import AutoFeatureExtractor, AutoModel, PreTrainedTokenizerFast | |
| model_id = "TylorShine/wavlm-base-plus-hiragana-ctc" | |
| # 特徴量抽出器とモデルのロード | |
| processor = AutoFeatureExtractor.from_pretrained(model_id) | |
| model = AutoModel.from_pretrained(model_id, trust_remote_code=True) | |
| model.eval() | |
| # トークナイザーのロード | |
| kana_tokenizer = PreTrainedTokenizerFast.from_pretrained(model_id, subfolder="kana_tokenizer") | |
| phoneme_tokenizer = PreTrainedTokenizerFast.from_pretrained(model_id, subfolder="phoneme_tokenizer") | |
| # 音声ファイルの読み込み (16kHzにリサンプリング) | |
| waveform, sample_rate = torchaudio.load("nihongo_no_onsei.wav") | |
| if sample_rate != 16000: | |
| resampler = torchaudio.transforms.Resample(orig_freq=sample_rate, new_freq=16000) | |
| waveform = resampler(waveform) | |
| # 前処理 | |
| inputs = processor(waveform.squeeze().numpy(), sampling_rate=16000, return_tensors="pt") | |
| # 推論 | |
| with torch.no_grad(): | |
| outputs = model(**inputs) | |
| # ひらがなと音素のロジットを取得 | |
| kana_logits = outputs["kana_logits"] | |
| phoneme_logits = outputs["phoneme_logits"] | |
| # Greedy Decoding | |
| kana_preds = torch.argmax(kana_logits, dim=-1).tolist() | |
| phoneme_preds = torch.argmax(phoneme_logits, dim=-1).tolist() | |
| # print("Kana Token IDs:", kana_preds[0]) | |
| # print("Phoneme Token IDs:", phoneme_preds[0]) | |
| # `model.ctc_decode()` でトークンをテキストに変換 | |
| kana_text = model.ctc_decode(kana_preds, kana_tokenizer, is_kana=True) | |
| phoneme_text = model.ctc_decode(phoneme_preds, phoneme_tokenizer, is_kana=False) | |
| print("Kana:", kana_text) | |
| print("Phoneme:", phoneme_text) | |
| ``` | |
| ## 📊 Model Details & Evaluation | |
| | Property | Value | | |
| |----------|-------| | |
| | Architecture | WavLM + Dual CTC (Kana & Phoneme) | | |
| | Precision | BF16 | | |
| | Kana vocab | 84 tokens | | |
| | Phoneme vocab | 44 tokens | | |
| | Dataset | Condition | KER | PER | | |
| |---------|-----------|-----|-----| | |
| | JSUT-BASIC5000 | スタジオ収録、単一話者 | 3.97% | 3.33% | | |
| | JVS pallarel100 | 100話者 | 5.46% | 4.35% | | |
| | JVS whisper10 | 100話者、ささやき声 | 11.6% | 7.51% | | |
| | ReazonSpeech (20k samples from `medium` subset) | TV音声 | 17.5% | 14.7% | | |
| ## 📜 License | |
| Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) license. See [LICENSE](LICENSE) for details. | |
| (CC BY-SA 3.0 ライセンスはWavLMから継承しています。) | |
| ## 🎓️ References / Acknowledgements | |
| 本モデルのベースとさせていただいたプロジェクト(Wav2Vec 2.0版)に関する詳細は、以下をご参照ください。 | |
| - Sakasegawa. (2026). "hiragana-asr: Lightweight Japanese ASR with Dual CTC". [github.com/nyosegawa/hiragana-asr](https://github.com/nyosegawa/hiragana-asr) | |