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.

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)

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.

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%

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

To make it run for debug, you need to download the following files from Releases and put them into src/models.

# 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.7.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.7.0
File Size Uploaded Provenance
e2k-0.7.0.tar.gz 10.0 MB Without provenance Details

Built distribution (wheel)

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

Total release size: 20.1 MB

Release files / e2k-0.7.0.tar.gz

Download URL e2k-0.7.0.tar.gz
Size 10.0 MB
Tags Source
SHA-256 checksum
How to use checksums
abe13d6e8ebf3eca306b003046941b3682f9a190f93731bed775598352b88129
BLAKE2b-256 checksum
How to use checksums
e4a8b1fc66fd21adc00504b01e52b6effd3099f904816f303bf1d52a34d1820c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.4

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

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

Security for e2k 0.7.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