Skip to main content

G2P+

This repository contains scripts for converting various corpora to a unified IPA format, with marked word and utterance boundaries, to prepare them for training and evaluating small transformer-based language models. Read our paper here.

It leverages four existing G2P tools (two statistical tools and two pronunciation dictionaries) to support a wide variety of languages:

Backend Languages
phonemizer 100+ languages/accents
epitran 149 languages/scripts
pinyin-to-ipa 1 (Mandarin)
pingyam 1 (Cantonese)

G2P+ ensures that regardless of the backend chosen, the output is in a unified format. Each utterance is output using phonemes represented in IPA, separated by spaces, possibly with WORD_BOUNDARY tokens to separate words. The phonemes symbols match those in Phoible.

In addition to a unified format, we ensure that the phoneme inventories produced by G2P+ align with established phoneme inventories in Phoible. This is done using dedicated folding maps. Read FOLDING.md for an overview of implemented folding maps and for details on how to contribute your own.

Read more about G2P+ in our paper.

Installation

The simplest way is using pip:

pip install g2p-plus

Or you can install from source:

git clone https://github.com/codebyzeb/g2p-plus
cd g2p-plus
pip install .

Dependencies

The phonemizer backend requires espeak-ng to be installed. See instructions here.

On mac, the backend requires PHONEMIZER_ESPEAK_LIBRARY to be set in the local environment. You may find that before running g2p_plus, you need to add this to your environment, e.g.:

export PHONEMIZER_ESPEAK_LIBRARY=/opt/local/lib/libespeak-ng.dylib

The epitran backend with English requires Flite to be installed. See instructions here.

Usage

G2P+ is available as a command-line tool or as a python function.

Command-line interface

g2p_plus is the CLI for G2P+, supporting the conversion of corpora to a unified IPA format. It supports multiple backends, as described above. The help menu (-h) describes usage and the languages supported by each backend. The script reads lines from an input file (using -i) and saves space-separated IPA phonemes to an output file (using -o) or reads/writes to/from STDIN/STDOUT if files are not provided. Word boundaries are provided between words using -k using a WORD_BOUNDARY token.

For many languages, the underlying transcription tool does not output phoneme sets that match typical phoneme inventories for that language. As such, we have implemented "folding" dictionaries for many languages. These map the output of a backend for a language to a standard phoneme inventory in Phoible. See g2p_plus/folding for these dictionaries. This "folding" can be turned off using -u.

Example usage:

> g2p_plus phonemizer en-gb -k
hello there!
h ə l əʊ WORD_BOUNDARY ð eə WORD_BOUNDARY

> g2p_plus phonemizer en-us
hello there!
h ə l oʊ ð ɛ ɹ

Python library

G2P+ can be imported in python and used as follows:

from g2p_plus import phonemize_utterances
lines = ['hello there!', 'nice to meet you.']
phonemized = phonemize_utterances(lines, "phonemizer", "en-gb", keep_word_boundaries=True)

Additional arguments

There are a couple arguments shared by all wrappers and a few wrapper-specific arguments. The arguments shared by all wrappers are:

  • --keep-word-boundaries: If set to True, outputs a dedicated WORD_BOUNDARY token between words.
  • --uncorrected: If set to True, does not apply the folding maps.

The wrapper specific arguments are as follows:

  • --allow_possibly_faulty_word_boundaries (for phonemizer): Allows possibly faulty word boundaries, otherwise removes lines with altered word counts after transcription.
  • --preserve_punctuation (for phonemizer): Preserves punctuation in the transcribed output.
  • --with_stress (for phonemizer): Includes stress markers in the transcribed output.
  • --split_tones (for pingyam and pinyin-to-ipa): Separates tones as separate phonemes instead of attaching them to the vowel.

Recommended pairings

Many languages are covered by multiple backends. See RECOMMENDED.md for a recommendation which backends to use for certain languages.

Attribution

This project incorporates content from the following sources:

In accordance with the CC BY-SA 3.0 license, any derivative work or adaptation of these resources must also be shared under the same license.

License

All original content in this repository created by Zébulon Goriely is licensed under the MIT License.

Citing

To cite G2P+:

@misc{goriely2025ipachildesg2pfeaturerich,
      title={IPA-CHILDES & G2P+: Feature-Rich Resources for Cross-Lingual Phonology and Phonemic Language Modeling}, 
      author={Zébulon Goriely and Paula Buttery},
      year={2025},
      eprint={2504.03036},
      archivePrefix={arXiv},
      primaryClass={cs.CL},
      url={https://arxiv.org/abs/2504.03036}, 
}

Metadata

Release files for g2p-plus 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for g2p-plus 0.1.6
File Size Uploaded
g2p_plus-0.1.6.tar.gz 4.0 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for g2p-plus 0.1.6
File Interpreter ABI Platform
g2p_plus-0.1.6-py3-none-any.whl Python 3 none any Details

Total release size: 7.9 MB

Release files / g2p_plus-0.1.6.tar.gz

Download URL g2p_plus-0.1.6.tar.gz
Size 4.0 MB
Tags Source
SHA-256 checksum
How to use checksums
4f00f5f46de35b88956ae4d9c1c65d842a3b280b8b8e757da72762aa05f58b10
BLAKE2b-256 checksum
How to use checksums
1dc1e525d397db70339e8bf2d36757917bfa3c31fa49b520d779236c9a333c51
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 8, 2025.

Transparency log

Release files / g2p_plus-0.1.6-py3-none-any.whl

Download URL g2p_plus-0.1.6-py3-none-any.whl
Size 4.0 MB
Tags Python 3
SHA-256 checksum
How to use checksums
03023cff7eaf93fd05417e8ead7f52c1c90044637e2e31d02019b4d4c7cb635d
BLAKE2b-256 checksum
How to use checksums
5456b269a2f096a7f1c6fe7424ed1d6a4ff24d3e00ddac3d2945b816bdf0484a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 8, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.6 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.0

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page