GitYCC/g2pW
Chinese Mandarin Grapheme-to-Phoneme Converter. 中文轉注音或拼音 (INTERSPEECH 2022)
What it solves
Mandarin Chinese has many polyphonic characters—characters that have multiple pronunciations depending on context. This project, g2pW, provides a model that automatically determines the correct pronunciation for each character in a sentence, converting the text into phonetic output (Zhuyin or Pinyin). This is essential for text-to-speech systems, language learning tools, and any application that needs accurate Mandarin pronunciation.
How it works
It uses a BERT-based architecture with a custom "conditional weighted softmax" layer, trained specifically to disambiguate polyphonic characters. The model processes a sequence of Chinese characters and outputs the phonetic representation for each one. The project includes pre-trained model checkpoints (both PyTorch and ONNX versions), a Python package that can be pip-installed, and scripts for training, testing, and prediction. Users can load the model via the G2PWConverter class and feed it sentences or lists of sentences. It also supports simplified Chinese and can output Pinyin with tone numbers.
Who it's for
Developers and researchers working on Mandarin text-to-speech, pronunciation learning, or any system that needs accurate character-to-phoneme conversion. The package is designed to be easy to use—just install and run—and also provides the codebase and configuration files for those who want to train custom models on their own datasets.
Highlights
- Easy-to-use Python package:
pip install g2pw, thenG2PWConverter()gives immediate results. - Supports both traditional and simplified Chinese, and outputs either Zhuyin (Bopomofo) or Pinyin with tone numbers.
- Pre-trained models available for fast inference, including an ONNX version for efficient deployment.
- Includes training, testing, and prediction scripts, plus dataset download instructions for the CPP dataset.
- Backed by a peer-reviewed paper (INTERSPEECH 2022) and already integrated into PaddleSpeech and pypinyin-g2pW.
Related
- Project
- Project
- Project
- Project