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: 3

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

Task Model Metric Score
Katakana Prediction P2K BLEU ↑ 0.89
Katakana Prediction C2K BLEU ↑ 0.92
Accent Prediction AccentPredictor Accuracy ↑ 88.4%
Pronunciation Validity NGram Recall ↑ 98.9%
Pronunciation Validity NGram Acronym rejection ↑ 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.0

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.0
File Size Uploaded Provenance
e2k-0.8.0.tar.gz 12.5 MB Without provenance Details

Built distribution (wheel)

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

Total release size: 25.0 MB

Release files / e2k-0.8.0.tar.gz

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

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

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

Security for e2k 0.8.0

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