Instructions to use vukrosic/nano-g2p with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use vukrosic/nano-g2p with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="vukrosic/nano-g2p")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("vukrosic/nano-g2p", dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use vukrosic/nano-g2p with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "vukrosic/nano-g2p" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "vukrosic/nano-g2p", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/vukrosic/nano-g2p
- SGLang
How to use vukrosic/nano-g2p with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "vukrosic/nano-g2p" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "vukrosic/nano-g2p", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "vukrosic/nano-g2p" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "vukrosic/nano-g2p", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use vukrosic/nano-g2p with Docker Model Runner:
docker model run hf.co/vukrosic/nano-g2p
nano-g2p
Spells out how a word is pronounced — though → DH OW, tough → T AH F,
through → TH R UW, cough → K AA F. English spelling is famously not
phonetic (though/tough/through/cough/rough/bough — six different sounds
from -ough), so no rule does this; pronunciation lives only in a learned lexicon. A
~1M-parameter (1,016,960) byte-level transformer that learns grapheme→phoneme
patterns and generalises to words it never saw.
- Code, benchmark, tests, technical report: https://github.com/vukrosic/nano-g2p
- Runs on CPU in milliseconds. No tokenizer file — raw UTF-8 bytes. ARPAbet, stress stripped.
Benchmark (held-out words, N=2000 — unseen in training)
| exact-match | phoneme-acc | |
|---|---|---|
| nano-g2p model | 72.1% | 92.7% |
| per-letter script | 8.4% | 54.7% |
| nearest-word lookup | 1.8% | 65.6% |
The model beats both scripts by a wide margin on words it never saw — it learned generalisable pronunciation rules, not a memorised dictionary or fuzzy match. The cleanest must-beat-a-script result of the portfolio.
Usage
pip install torch safetensors numpy
# grab modeling_nano_g2p.py + config.json from the GitHub repo
from modeling_nano_g2p import load, pronounce
m = load("model.safetensors", "config.json")
pronounce(m, "though") # -> "DH OW"
pronounce(m, "tough") # -> "T AH F"
How it was trained
Frozen public lexicon: top common English words (wordfreq) with their CMU
pronunciation (cmudict), stress stripped, ~35k words; 2,000 held out as an unseen
test set. SFT, prompt masked. ~1M-param byte-level transformer (RMSNorm, RoPE, GQA,
SwiGLU), 20k steps, AdamW, cosine LR. Full recipe and reproduction in the GitHub repo.
MIT. Built by Vuk Rosić. Pronunciations derived from CMUdict (BSD-style license).
- Downloads last month
- 49