Skip to main content

English to Katakana Translator

PyPI version

e2k is a Python library that translates English to Katakana using lightweight RNN models trained on data from Wiktionary and JMdict/EDICT. It only requires numpy as a runtime dependency. A Rust port with the same models and outputs lives in e2k-rs.

We also provide pretrained models and dictionaries in the Releases section (not included in the PyPI package).

Installation

pip install e2k

Usage

1. Basic Translation

Two models are available:

Model Input Type Description
P2K Phonemes Converts phonemes (from CMUdict) to Katakana
C2K Characters Converts English text directly to Katakana
from e2k import P2K, C2K
from g2p_en import G2p # any g2p library with CMUdict phonemes can work

p2k = P2K()
g2p = G2p()

word = "geogaddi"
print(p2k(g2p(word)))  # ジオダギー

c2k = C2K()
print(c2k(word))       # ジオガディ
c2k(word, "top_p", p=0.9, t=2)
c2k(word, "top_k", k=5, seed=42)

Both models also come in a turbo variant, a smaller model distilled from the default one. It's about twice as fast with comparable accuracy, though its outputs differ on some words.

c2k = C2K(model="turbo")
p2k = P2K(model="turbo")

2. Pitch Accent Prediction

The library includes an RNN-based pitch accent predictor trained on Unidic.

from e2k import AccentPredictor as Ap, C2K

ap = Ap()
c2k = C2K()

word = "geogaddi"
katakana = c2k(word)
accent = ap(katakana)

print(f"Katakana: {katakana}, Accent: {accent}")
# Katakana: ジオガディ, Accent: 2

3. Pronunciation Validity (N-Gram Model)

You can check if a word should be transliterated or spelled as-is. A linear SVM over character n-gram scores decides, trained on CMUdict words against synthetic acronyms, abbreviations and random strings.

from e2k import NGram
ngram = NGram()

word = "ussr"
if ngram(word):
    print(c2k(word))
else:
    print(ngram.as_is(word))

Example output:

  • ussr → ユーエスエスアール
  • doggy → ドッギー

4. Input/Output Symbol Tables

c2k.in_table  # valid characters
p2k.in_table  # valid phonemes
c2k.out_table # katakana output symbols
p2k.out_table # katakana output symbols
accent.in_table # valid katakana symbols for accent prediction

Performance

Evaluated with e2k_train/eval.py on held-out test splits no model was trained on: 1,566 dictionary words for katakana prediction, 37,594 Unidic entries for accent prediction.

Katakana Prediction

Model Variant BLEU ↑ Exact Match ↑ CER ↓
C2K base 0.843 67.1% 12.8%
C2K turbo 0.846 67.9% 12.7%
P2K base 0.776 56.2% 17.9%
P2K turbo 0.778 55.8% 17.6%

Accent Prediction

Model Accuracy ↑ Precision ↑ Recall ↑ F1 ↑
AccentPredictor 88.6% 89.1% 88.6% 88.8%

Pronunciation Validity

Model Recall ↑ Acronym Rejection ↑
NGram 98.9% 90.5%

Develop

Dependencies

We use uv for dependency management:

  • Root package (e2k in src/) is the PyPI library and only depends on numpy.
  • Training code lives in the e2k_train/ workspace member (e2k_train) and carries the heavy ML/tooling dependencies.

For root package:

uv sync

Testing

The model files are tracked in git under src/e2k/models, so a fresh clone runs as is.

# test
uv run src/inference.py

Training

See here for instructions related to data preparation, training, evaluation and exporting.

License

  • Code: Unlicense
  • Dictionaries: CC-BY-SA (Wiktionary, JMdict/EDICT)
  • Accent Predictor: Unidic (GPLv2.0/LGPLv2.1/BSD)
  • N-Gram Model: CMUDict (BSD 2-Clause)

Machine learning weights may be considered derivative works, check the upstream licenses when distributing.

Credits

Metadata

Release files for e2k 0.8.1

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

Source distribution (sdist)

Source distribution for e2k 0.8.1
File Size Uploaded Provenance
e2k-0.8.1.tar.gz 12.5 MB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for e2k 0.8.1
File Interpreter ABI Platform
e2k-0.8.1-py3-none-any.whl Python 3 none any Details

Total release size: 25.0 MB

Release files / e2k-0.8.1.tar.gz

Download URL e2k-0.8.1.tar.gz
Size 12.5 MB
Tags Source
SHA-256 checksum
How to use checksums
d6e446d229904d00548908776a6b17db21f6f341ac0858d854cf0c5465fd3d1a
BLAKE2b-256 checksum
How to use checksums
240646e141c07e051b73d6184c64894fd0e8e5f5deae3a4779a15da0da6968a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.4

Release files / e2k-0.8.1-py3-none-any.whl

Download URL e2k-0.8.1-py3-none-any.whl
Size 12.5 MB
Tags Python 3
SHA-256 checksum
How to use checksums
0092d4572b3c846a4e5a7492a179eb2c5ee4f198df3279f17e8cae232b09db9f
BLAKE2b-256 checksum
How to use checksums
e8349e845f9f6de15766b77a0bade2bc31b6d501283034ff49d34dfd449a2329
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.4

Security for e2k 0.8.1

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.

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