Skip to main content

naholos

Ukrainian word stress (наголос): puts U+0301 after the stressed vowel.

from naholos import Naholos

n = Naholos()
n(["Мені потрібен атлас світу.", "Вона одягла сукню з шовкового атласу."])
# ['Мені́ потрі́бен а́тлас сві́ту.', 'Вона́ одягла́ су́кню з шовко́вого атла́су.']

It combines the ukrainian-word-stress dictionary with a small neural tagger (ByT5 encoder + one linear head over the characters). The dictionary handles words with a single possible stress. The tagger reads the whole sentence and resolves heteronyms (за́мок / замо́к, а́тлас / атла́с) and words that are not in the dictionary. The tagger needs one encoder pass per sentence, about 4 ms on a GPU, and it cannot change the letters of the text.

Install

pip install naholos

The model (Mikhailo/naholos-tagger, ~830 MB) downloads on first use. The default hybrid mode uses only the dictionary lookup. mode="dictionary" also loads Stanza for POS disambiguation (~500 MB of models on first use), unless you pass disambiguation="plain".

Usage

Naholos(mode="hybrid")       # default: dictionary where unambiguous, tagger elsewhere
Naholos(mode="model")        # tagger for every word: stress as narrators actually say it
Naholos(mode="dictionary")   # ukrainian-word-stress only, no neural model
Naholos(monosyllables=True)  # also mark one-vowel words (ві́н); off by default
n(["перше речення", "друге"])        # batches
naholos "Учора визирнуло сонце."
cat book.txt | naholos --mode model > book.stressed.txt

Long texts are split at sentence ends.

Fixing a stress yourself

When the model gets a word wrong, mark it yourself. Your stress always wins over the dictionary and the model.

In the text you send, a word you already marked keeps your mark. All three notations work: за́мок (U+0301), за´мок (U+00B4) or за+мок. The output always uses U+0301, or the symbol= you chose.

n("Старий за+мок на горі, ключ у замку.")
# 'Стари́й за́мок на горі́, ключ у за́мку.'

A "+" counts as a mark only right after a vowel inside a word, so 2+2 and C++ are left alone. Pass plus_marks=False (CLI: --no-plus) if your text uses "+" otherwise. keep_marks=False ignores every mark in the input and stresses the text from scratch.

For words you correct often, use a user dictionary. Matching ignores case:

n = Naholos(user_dict={"замок": "за́мок"})       # or a list ["за+мок", "Мико+ла"]
n.add_words("по+ки", "Мико́ла")                  # add more at any time
n = Naholos(user_dict="my_words.txt")           # one stressed word per line, "#" = comment
naholos --user-dict my_words.txt "Ключ від замка"

A mark in the text beats the user dictionary. The user dictionary beats the built-in rules.

Accuracy

The table counts word accuracy on words with two or more vowels whose stress is known, using python -m naholos.evaluate (RTX 4090; ms per sentence in the last column).

set words dictionary model hybrid
expert-stressed literary text, every word in 3000 sentences (private set) 9666 0.889 0.917 0.935
lang-uk human gold, ambiguous words 1472 0.521 0.751 0.755
held-out audiobook forms, stress heard in recordings 3102 0.741 0.924 0.929
Common Voice, stress heard in recordings* 3001 0.638 0.939 0.939
ms / sentence 10–14 4.5–5 4.5–5

dictionary is ukrainian-word-stress 2.1 with Stanza disambiguation. It leaves a word unmarked when it cannot decide, and that counts as an error. Without Stanza (disambiguation="plain") it scores 0.843 on the expert-stressed set. The lang-uk, audiobook and Common Voice sets label only hard words (heteronyms and other ambiguous forms), so their numbers are much lower than on running text.

* Some of these Common Voice sentences were in the training data, so this row is optimistic.

hybrid follows the literary norm wherever the dictionary allows only one stress, and lets the tagger decide everything else. model is closer to how people actually read: narrators sometimes stress "unambiguous" words differently from the dictionary.

Known weakness: when one sentence uses the same heteronym in two senses ("старий замок на горі, а на дверях новий замок"), both usually get the same stress.

Training

Data is JSON Lines, one sentence per line, with the stressed vowel marked:

{"text": "Учо́ра над мі́стом ви́зирнуло со́нце."}

Only words with two or more vowels and exactly one mark are trained on. Leave a word unmarked if you don't know its stress, and it is skipped. A small example (Common Voice sentences, CC0, with stress taken from the recordings) is in examples/:

# fine-tune the released tagger on your data
python -m naholos.train --train examples/train.jsonl --val examples/val.jsonl \
    --out my-tagger --init Mikhailo/naholos-tagger --max-steps 50 --budget 4000

# or train a new head on a plain ByT5
python -m naholos.train --train data/train.jsonl --val data/val.jsonl \
    --out my-tagger --init google/byt5-base --epochs 2 --lr 5e-5 --grad-ckpt

# evaluate any marked file
python -m naholos.evaluate examples/val.jsonl --model my-tagger
Naholos(model="my-tagger")

On an RTX 4090, ByT5-base trains at ~1.2 s per step with --budget 16000 --grad-ckpt, using about 12 GB of memory.

How the model was trained

The model is google/byt5-base, first fine-tuned as a seq2seq stress model, then turned into the tagger (encoder + head) and trained on about 800k sentences:

  • stress heard in recordings: ~1.5M audiobook and Common Voice utterances, aligned with the Montreal Forced Aligner and labelled by an acoustic stress detector. Only confident labels are used, and whole sentences with an unsure word are dropped.
  • ambiguous words from modern audiobooks, labelled by the stress their narrators read, provided by the author of accentuk for this model. That data is not redistributed.

License

The code is MIT. The model is Apache-2.0, like its base google/byt5-base.

Metadata

Release files for naholos 0.1.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 naholos 0.1.0
File Size Uploaded Provenance Actions
naholos-0.1.0.tar.gz 31.7 kB Without provenance Details for naholos-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 49.1 kB

Release files / naholos-0.1.0.tar.gz

Download URL naholos-0.1.0.tar.gz
Size 31.7 kB
Tags Source
SHA-256 checksum
How to use checksums
dfb70ac884e2fa8a9a5ed2a6665c76f072f376953e4acc36033addcf61c21cb0
BLAKE2b-256 checksum
How to use checksums
17f8329304450845b78884020513d91ca71cbd8386613be302cd8dce235377ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.12

Release files / naholos-0.1.0-py3-none-any.whl

Download URL naholos-0.1.0-py3-none-any.whl
Size 17.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d997eb3deeaea87a08d475aefc184c7d41922a488db1f945b327e49d1b535f0f
BLAKE2b-256 checksum
How to use checksums
38362b6d2555199310b413e7fcf9b7c3caf07efc62ef4e2df10f0e102d7365a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.12

Security for naholos 0.1.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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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