g2pW: Mandarin Grapheme-to-Phoneme Converter
Authors: Yi-Chang Chen, Yu-Chuan Chang, Yen-Cheng Chang and Yi-Ren Yeh
This is the official repository of our paper g2pW: A Conditional Weighted Softmax BERT for Polyphone Disambiguation in Mandarin (INTERSPEECH 2022).
News
- g2pW is included in PaddlePaddle/PaddleSpeech
- g2pW is included in mozillazg/pypinyin-g2pW
Getting Started
Dependency / Install
(This work was tested with PyTorch 1.7.0, CUDA 10.1, python 3.6 and Ubuntu 16.04.)
-
Install PyTorch
-
$ pip install g2pw
Quick Demo
>>> from g2pw import G2PWConverter
>>> conv = G2PWConverter()
>>> sentence = '上校請技術人員校正FN儀器'
>>> conv(sentence)
[['ㄕㄤ4', 'ㄒㄧㄠ4', 'ㄑㄧㄥ3', 'ㄐㄧ4', 'ㄕㄨ4', 'ㄖㄣ2', 'ㄩㄢ2', 'ㄐㄧㄠ4', 'ㄓㄥ4', None, None, 'ㄧ2', 'ㄑㄧ4']]
>>> sentences = ['銀行', '行動']
>>> conv(sentences)
[['ㄧㄣ2', 'ㄏㄤ2'], ['ㄒㄧㄥ2', 'ㄉㄨㄥ4']]
Load Offline Model
conv = G2PWConverter(model_dir='./G2PWModel-v2-onnx/', model_source='./path-to/bert-base-chinese/')
Support Simplified Chinese and Pinyin
>>> from g2pw import G2PWConverter
>>> conv = G2PWConverter(style='pinyin', enable_non_tradional_chinese=True)
>>> conv('然而,他红了20年以后,他竟退出了大家的视线。')
[['ran2', 'er2', None, 'ta1', 'hong2', 'le5', None, None, 'nian2', 'yi3', 'hou4', None, 'ta1', 'jing4', 'tui4', 'chu1', 'le5', 'da4', 'jia1', 'de5', 'shi4', 'xian4', None]]
Scripts
$ git clone https://github.com/GitYCC/g2pW.git
Train Model
For example, we train models on CPP dataset as follows:
$ bash cpp_dataset/download.sh
$ python scripts/train_g2p_bert.py --config configs/config_cpp.py
Testing
$ python scripts/test_g2p_bert.py \
--config saved_models/CPP_BERT_M_DescWS-Sec-cLin-B_POSw01/config.py \
--checkpoint saved_models/CPP_BERT_M_DescWS-Sec-cLin-B_POSw01/best_accuracy.pth \
--sent_path cpp_dataset/test.sent \
--output_path output_pred.txt
Prediction
$ python scripts/predict_g2p_bert.py \
--config saved_models/CPP_BERT_M_DescWS-Sec-cLin-B_POSw01/config.py \
--checkpoint saved_models/CPP_BERT_M_DescWS-Sec-cLin-B_POSw01/best_accuracy.pth \
--sent_path cpp_dataset/test.sent \
--lb_path cpp_dataset/test.lb
Checkpoints
Citation
To cite the code/data/paper, please use this BibTex
@inproceedings{chen22d_interspeech,
title = {g2pW: A Conditional Weighted Softmax BERT for Polyphone Disambiguation in Mandarin},
author = {Yi-Chang Chen and Yu-Chuan Steven and Yen-Cheng Chang and Yi-Ren Yeh},
year = {2022},
booktitle = {Interspeech 2022},
pages = {1926--1930},
doi = {10.21437/Interspeech.2022-216},
issn = {2958-1796},
}
Star History
Metadata
Release files for g2pw 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| g2pw-0.1.2.tar.gz | 270.3 kB | Without provenance | Details for g2pw-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| g2pw-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for g2pw-0.1.2-py3-none-any.whl |
Total release size: 554.0 kB
Release files / g2pw-0.1.2.tar.gz
| Download URL | g2pw-0.1.2.tar.gz |
|---|---|
| Size | 270.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
71b1b4b6123fc85ddde806fe32bb52a249420eb60e54f098dfc5a96b34dfb538
|
|
BLAKE2b-256 checksum How to use checksums |
5d4c935efbf7c1a0d9055d727601c9f23a3eb93c30b4d24fc7d31b0fb78cbc24
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.16
|
Release files / g2pw-0.1.2-py3-none-any.whl
| Download URL | g2pw-0.1.2-py3-none-any.whl |
|---|---|
| Size | 283.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
88e1252efbdc56fe7efef6368266129628926afac2797f87cb5a059ce4b3ff65
|
|
BLAKE2b-256 checksum How to use checksums |
6c9b36aa8e799bc0834acc18f73f11c1740ec17b75b532743a3d83f06f4e6885
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.16
|
Security for g2pw 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.