g2p_en decoder: keyword text features for naptrap

These are the weights of the g2p_en grapheme-to-phoneme model (Kyubyong Park & Jongseok Kim, Apache-2.0, release 2.1.0), repackaged as safetensors for naptrap. The values are unchanged.

naptrap does not use this model to output phoneme strings. The keyword models, such as androiddrew/naptrap-phonmatchnet-en, were trained on the decoder's hidden states. This is the "embedding" path from the PhonMatchNet reference code:

  1. Normalize the keyword: lowercase it, strip accents, and keep [a-z'] words. Numbers must be spelled out.
  2. Encode each word's characters with the grapheme GRU.
  3. Decode greedily (up to 20 steps), keeping each emitted 256-D decoder state.
  4. Join the words with the decoder's <pad> embedding as a separator.

The result is a [positions, 256] float32 matrix.

Not affiliated with or endorsed by the g2p_en authors. See LICENSE and NOTICE.

Usage

from huggingface_hub import snapshot_download
from naptrap import G2PTextEncoder

encoder = G2PTextEncoder.from_pretrained(
    snapshot_download("androiddrew/g2p-en-decoder-pytorch", revision="v1")
)
features = encoder("hey computer")   # torch.float32 [positions, 256]

Accuracy of the PyTorch port

We compared naptrap's PyTorch implementation with the original NumPy G2p.embedding() on 545 keywords. They included Speech Commands words, wake phrases, words with apostrophes and accents, 350 random CMUdict words and 150 random multi-word phrases. Every output length matched, and the maximum absolute difference was 4.6e-6.

Limitations

The model was trained on CMUdict pronunciations of American English words. Unusual names, brand names and non-English words get its best-guess pronunciation, which may not match how people say them. naptrap does not use the dictionary-lookup, homograph or number-expansion steps of the g2p_en package.

conversion/convert.py reproduces model.safetensors from the g2p_en 2.1.0 wheel.

Downloads last month
-
Safetensors
Model size
835k params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support