accentuk 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- accentuk-0.1.0/.gitignore +11 -0
- accentuk-0.1.0/LICENSE +201 -0
- accentuk-0.1.0/PKG-INFO +201 -0
- accentuk-0.1.0/README.md +172 -0
- accentuk-0.1.0/docs/ct2_benchmark.json +130 -0
- accentuk-0.1.0/docs/ct2_benchmark.md +100 -0
- accentuk-0.1.0/docs/design_full_and_light.md +222 -0
- accentuk-0.1.0/pyproject.toml +41 -0
- accentuk-0.1.0/scripts/benchmark_package.py +191 -0
- accentuk-0.1.0/scripts/compare_ct2.py +821 -0
- accentuk-0.1.0/scripts/compare_service.py +180 -0
- accentuk-0.1.0/scripts/ct2_calib.py +56 -0
- accentuk-0.1.0/scripts/pkg_shim.py +37 -0
- accentuk-0.1.0/scripts/verify_export.py +84 -0
- accentuk-0.1.0/src/accentuk/__init__.py +23 -0
- accentuk-0.1.0/src/accentuk/assets/NOTICE.md +17 -0
- accentuk-0.1.0/src/accentuk/assets/releases.json +128 -0
- accentuk-0.1.0/src/accentuk/assets.py +218 -0
- accentuk-0.1.0/src/accentuk/cli.py +104 -0
- accentuk-0.1.0/src/accentuk/combiner.py +291 -0
- accentuk-0.1.0/src/accentuk/engine.py +718 -0
- accentuk-0.1.0/src/accentuk/errors.py +27 -0
- accentuk-0.1.0/src/accentuk/export.py +403 -0
- accentuk-0.1.0/src/accentuk/frontend.py +178 -0
- accentuk-0.1.0/src/accentuk/inference.py +344 -0
- accentuk-0.1.0/src/accentuk/lexicon.py +110 -0
- accentuk-0.1.0/src/accentuk/morphology.py +260 -0
- accentuk-0.1.0/src/accentuk/normalizer.py +121 -0
- accentuk-0.1.0/src/accentuk/route.py +35 -0
- accentuk-0.1.0/src/accentuk/segment.py +166 -0
- accentuk-0.1.0/src/accentuk/text.py +158 -0
- accentuk-0.1.0/src/accentuk/token_resolver.py +335 -0
- accentuk-0.1.0/src/accentuk/triage.py +47 -0
- accentuk-0.1.0/src/accentuk/verbalize.py +211 -0
- accentuk-0.1.0/tests/test_assets.py +85 -0
- accentuk-0.1.0/tests/test_cli.py +60 -0
- accentuk-0.1.0/tests/test_core.py +129 -0
- accentuk-0.1.0/tests/test_engine.py +95 -0
- accentuk-0.1.0/tests/test_export.py +148 -0
- accentuk-0.1.0/tests/test_frontend.py +47 -0
- accentuk-0.1.0/tests/test_inference.py +77 -0
- accentuk-0.1.0/tests/test_lexicon.py +75 -0
- accentuk-0.1.0/tests/test_modes.py +115 -0
- accentuk-0.1.0/tests/test_morphology.py +91 -0
- accentuk-0.1.0/tests/test_parity.py +97 -0
- accentuk-0.1.0/tests/test_route.py +22 -0
- accentuk-0.1.0/tests/test_segment.py +36 -0
accentuk-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 the uk-tts-frontend authors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
accentuk-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: accentuk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Offline Ukrainian stress marking and optional TTS preparation
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
License-File: src/accentuk/assets/NOTICE.md
|
|
8
|
+
Requires-Python: <3.15,>=3.12
|
|
9
|
+
Requires-Dist: ctranslate2<5,>=4.8
|
|
10
|
+
Requires-Dist: huggingface-hub>=0.25
|
|
11
|
+
Requires-Dist: marisa-trie<2,>=1.2
|
|
12
|
+
Requires-Dist: pymorphy3-dicts-uk<3,>=2.4
|
|
13
|
+
Requires-Dist: pymorphy3<3,>=2
|
|
14
|
+
Requires-Dist: sentencepiece<1,>=0.2
|
|
15
|
+
Requires-Dist: spacy-curated-transformers<0.4,>=0.3
|
|
16
|
+
Requires-Dist: spacy<3.9,>=3.8
|
|
17
|
+
Requires-Dist: torch<3,>=2.4
|
|
18
|
+
Requires-Dist: transformers<5,>=4.45
|
|
19
|
+
Provides-Extra: build
|
|
20
|
+
Requires-Dist: ukrainian-word-stress==2.1.0; extra == 'build'
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: build>=1.2; extra == 'dev'
|
|
23
|
+
Requires-Dist: pytest<10,>=8; extra == 'dev'
|
|
24
|
+
Requires-Dist: ruff>=0.9; extra == 'dev'
|
|
25
|
+
Requires-Dist: ukrainian-word-stress==2.1.0; extra == 'dev'
|
|
26
|
+
Provides-Extra: tts
|
|
27
|
+
Requires-Dist: sacremoses<1,>=0.1; extra == 'tts'
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# accentuk
|
|
31
|
+
|
|
32
|
+
> The offline Python package. The Docker service (stress API, lexicon database, TTS frontend, UI) is [vacuum-in/accentuk-api](https://github.com/vacuum-in/accentuk-api).
|
|
33
|
+
|
|
34
|
+
Offline Ukrainian stress marking and TTS text verbalization powered by a memory-mapped MARISA lexicon and deep neural disambiguation.
|
|
35
|
+
|
|
36
|
+
`accentuk` runs completely locally without network calls at inference time. It offers two first-class operational modes: **Light** (CTranslate2 INT8 quantized, ~150 MB RAM, ultra-low latency) and **Full** (PyTorch FP32 + spaCy TRF + learned Combiner, maximum ensemble coverage).
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Operating Modes: Light vs. Full
|
|
41
|
+
|
|
42
|
+
| Metric / Capability | Light Mode (`mode="light"`) | Full Mode (`mode="full"`) | Benefit of Light |
|
|
43
|
+
|---|---|---|---|
|
|
44
|
+
| **Lexicon Lookup** | MARISA BytesTrie (`lexicon.marisa`) | MARISA BytesTrie (`lexicon.marisa`) | Zero-copy mmap (<10 µs/word) |
|
|
45
|
+
| **Deterministic Rules** | Prepositions, compounds, suffix analogy table | Prepositions, compounds, suffix analogy table | Identical deterministic rules |
|
|
46
|
+
| **Cross-Encoder Model** | CTranslate2 INT8 (`267 MB`) | PyTorch FP32 XLM-RoBERTa (`1,061 MB`) | **3.1x faster**, **74.8% smaller** |
|
|
47
|
+
| **Token Classifier** | CTranslate2 INT8 (`106 MB`) | PyTorch FP32 XLM-RoBERTa (`420 MB`) | **6.0x faster**, **74.7% smaller** |
|
|
48
|
+
| **TTS Verbalizer** | CTranslate2 INT8 (`51 MB`, 4.4 ms/sentence) | PyTorch FP32 MarianMT (`200 MB`, 2.9 s/sentence) | **660x faster**, **74.3% smaller** |
|
|
49
|
+
| **Morphology Tier** | spaCy small (`uk_core_news_sm`, ~15 MB) | spaCy TRF (`uk_core_news_trf_380`, 380 MB) | small CPU tagger |
|
|
50
|
+
| **Total Model Disk** | **425 MB** | **~1,680 MB** (+ 380 MB spaCy) | **74.7% disk reduction** |
|
|
51
|
+
| **Runtime Memory (RSS)** | **~120 – 180 MB** | **~1,500 – 2,200 MB** | **~10x lower RAM** |
|
|
52
|
+
| **Recommended For** | Production TTS, embedded systems, CLI, microservices | Research, batch indexing, maximum ensemble accuracy | |
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Installation
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pip install accentuk
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Optional TTS verbalization support:
|
|
63
|
+
```bash
|
|
64
|
+
pip install "accentuk[tts]"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Quick Start (Python API)
|
|
70
|
+
|
|
71
|
+
### 1. Stress Marking (`Accentor`)
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from accentuk import Accentor
|
|
75
|
+
|
|
76
|
+
# Light mode: fast CTranslate2 INT8 models, low memory footprint
|
|
77
|
+
with Accentor(mode="light") as engine:
|
|
78
|
+
result = engine.stress("Замок стоїть на горі.")
|
|
79
|
+
print(result.text) # "За́мок стої́ть на горі́."
|
|
80
|
+
for token in result.tokens:
|
|
81
|
+
print(f"{token.text} -> {token.output_text} ({token.status})")
|
|
82
|
+
|
|
83
|
+
# Full mode: PyTorch FP32 models + spaCy TRF + Combiner
|
|
84
|
+
with Accentor(mode="full") as engine:
|
|
85
|
+
result = engine.stress("Замок стоїть на горі.")
|
|
86
|
+
print(result.text)
|
|
87
|
+
|
|
88
|
+
# Auto mode (default): uses Light if CT2 models exist, otherwise Full/Dictionary
|
|
89
|
+
with Accentor(mode="auto") as engine:
|
|
90
|
+
result = engine.stress("Мої сестри.")
|
|
91
|
+
print(result.text) # "Мої́ се́стри."
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### 2. TTS Normalization & Stress Marking (`Frontend`)
|
|
95
|
+
|
|
96
|
+
Normalizes dates, numbers, currencies, abbreviations, and symbols, then applies stress marks:
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
from accentuk import Frontend
|
|
100
|
+
|
|
101
|
+
# Light mode: fast INT8 verbalization (4.4 ms) + Light stress marking
|
|
102
|
+
with Frontend(mode="light") as frontend:
|
|
103
|
+
result = frontend.prepare("Вона купила 25 яблук за 150 грн 3 квітня 2024 року.")
|
|
104
|
+
print(result.text)
|
|
105
|
+
|
|
106
|
+
# Full mode: MarianMT PyTorch FP32 + Full stress marking
|
|
107
|
+
with Frontend(mode="full") as frontend:
|
|
108
|
+
result = frontend.prepare("Вона купила 25 яблук за 150 грн 3 квітня 2024 року.")
|
|
109
|
+
print(result.text)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## CLI Usage
|
|
115
|
+
|
|
116
|
+
### Downloading Model Assets
|
|
117
|
+
|
|
118
|
+
Download the appropriate bundle for your target environment:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
# Download Light assets (~425 MB CT2 INT8 models + lexicon)
|
|
122
|
+
accentuk download --light
|
|
123
|
+
|
|
124
|
+
# Download Full assets (~2.2 GB PyTorch weights + spaCy TRF + lexicon)
|
|
125
|
+
accentuk download --full
|
|
126
|
+
|
|
127
|
+
# Download with TTS verbalizer included
|
|
128
|
+
accentuk download --light --tts
|
|
129
|
+
accentuk download --full --tts
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Stress Marking from CLI
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
# Stress plain Ukrainian text using Light mode
|
|
136
|
+
accentuk stress "Замок на горі стоїть." --mode light
|
|
137
|
+
|
|
138
|
+
# Stress using Full mode
|
|
139
|
+
accentuk stress "Замок на горі стоїть." --mode full
|
|
140
|
+
|
|
141
|
+
# Process text from standard input
|
|
142
|
+
echo "Мої сестри." | accentuk stress --mode light
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### TTS Normalization from CLI
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
accentuk prepare "О 7:45 ранку 3 квітня потяг № 12 прибув до Києва." --mode light
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Accuracy
|
|
154
|
+
|
|
155
|
+
Measured on 2026-10-13 with the same benchmarks as the service (`vacuum-in/accentuk-api`), word accuracy:
|
|
156
|
+
|
|
157
|
+
| test | service | full mode | light mode |
|
|
158
|
+
|---|---:|---:|---:|
|
|
159
|
+
| 200 most frequent ambiguous forms of Common Voice uk, stress heard in the recordings | 95.88% | 95.88% | 95.54% |
|
|
160
|
+
| modern-text gold, 3,887 words (all / reviewed lines) | 98.07% / 96.83% | 98.07% / 96.83% | 97.63% / 96.25% |
|
|
161
|
+
| [lang-uk stress benchmark](https://github.com/lang-uk/ukrainian-tts-preprocessing), words / heteronyms | 96.10% / 84.62% | 96.10% / 84.62% | 96.10% / 84.62% |
|
|
162
|
+
|
|
163
|
+
The lexicon `accentuk download` installs (`lexicon-v2`, built from the public `data-v2` of accentuk-api) is the
|
|
164
|
+
service's, including the 51,298-word dictionary of stress heard in recordings; the light-mode column was measured on a
|
|
165
|
+
clean download of it.
|
|
166
|
+
|
|
167
|
+
Full mode gives the service's answers. Light mode differs on 34 lang-uk tokens: 18 where the small spaCy tagger
|
|
168
|
+
parses differently from the transformer one, the rest from INT8 quantization (the INT8 cross-encoder picks
|
|
169
|
+
another reading than FP32 on 2.1% of targets; its margins track FP32 with r = 0.984, so the served threshold 0.5 is kept).
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## Benchmark Results
|
|
174
|
+
|
|
175
|
+
Evaluated on AMD EPYC / Intel Xeon CPUs with single-thread and batched execution:
|
|
176
|
+
|
|
177
|
+
| Model Tier | PyTorch FP32 Latency | CTranslate2 INT8 Latency | Speedup | Quality Parity |
|
|
178
|
+
|---|---|---|---|---|
|
|
179
|
+
| **Verbalizer (MarianMT)** | 2,891 ms / sentence | **4.38 ms / sentence** | **659.9x** | 100% exact match |
|
|
180
|
+
| **Token Classifier (XLM-R-uk)** | 31.0 ms / target | **5.20 ms / target** | **5.96x** | 100% top-1 match |
|
|
181
|
+
| **Cross-Encoder (XLM-R)** | 100.2 ms / target | **32.6 ms / target** | **3.07x** | 96.0% top-1 match |
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## Disambiguation Pipeline
|
|
186
|
+
|
|
187
|
+
When a word has multiple possible accents (heteronym), `accentuk` resolves stress through sequential tiers:
|
|
188
|
+
|
|
189
|
+
1. **Memory-Mapped Lexicon**: Exact form lookup via MARISA Trie (`lexicon.marisa`).
|
|
190
|
+
2. **Capitalization & Proper Noun Rules**: Differentiates names and toponyms (e.g. *Розді́л* vs. *ро́зділ*).
|
|
191
|
+
3. **Prepositional Pronoun Shift**: Shifts accent to the first syllable after governing prepositions (e.g. *без ньо́го*, *до ме́не*).
|
|
192
|
+
4. **Contextual Cross-Encoder**: Evaluates sentence context against candidate senses (*aloudreader/uk-stress-crossencoder*).
|
|
193
|
+
5. **Token Classifier**: Direct sequence labeling trained on audiobook audio alignment (*aloudreader/uk-stress-token-classifier*).
|
|
194
|
+
6. **Morphology & Agreement Rules**: Grammatical tags and case/number agreements (spaCy TRF in Full mode).
|
|
195
|
+
7. **Dictionary Defaults & Fallbacks**: Trie defaults, compound splitting (*пшенично-житній*), and analogy-based suffix tables.
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## License
|
|
200
|
+
|
|
201
|
+
Apache-2.0. See `LICENSE` and `NOTICE.md` for third-party component licenses and dataset attributions.
|
accentuk-0.1.0/README.md
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# accentuk
|
|
2
|
+
|
|
3
|
+
> The offline Python package. The Docker service (stress API, lexicon database, TTS frontend, UI) is [vacuum-in/accentuk-api](https://github.com/vacuum-in/accentuk-api).
|
|
4
|
+
|
|
5
|
+
Offline Ukrainian stress marking and TTS text verbalization powered by a memory-mapped MARISA lexicon and deep neural disambiguation.
|
|
6
|
+
|
|
7
|
+
`accentuk` runs completely locally without network calls at inference time. It offers two first-class operational modes: **Light** (CTranslate2 INT8 quantized, ~150 MB RAM, ultra-low latency) and **Full** (PyTorch FP32 + spaCy TRF + learned Combiner, maximum ensemble coverage).
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Operating Modes: Light vs. Full
|
|
12
|
+
|
|
13
|
+
| Metric / Capability | Light Mode (`mode="light"`) | Full Mode (`mode="full"`) | Benefit of Light |
|
|
14
|
+
|---|---|---|---|
|
|
15
|
+
| **Lexicon Lookup** | MARISA BytesTrie (`lexicon.marisa`) | MARISA BytesTrie (`lexicon.marisa`) | Zero-copy mmap (<10 µs/word) |
|
|
16
|
+
| **Deterministic Rules** | Prepositions, compounds, suffix analogy table | Prepositions, compounds, suffix analogy table | Identical deterministic rules |
|
|
17
|
+
| **Cross-Encoder Model** | CTranslate2 INT8 (`267 MB`) | PyTorch FP32 XLM-RoBERTa (`1,061 MB`) | **3.1x faster**, **74.8% smaller** |
|
|
18
|
+
| **Token Classifier** | CTranslate2 INT8 (`106 MB`) | PyTorch FP32 XLM-RoBERTa (`420 MB`) | **6.0x faster**, **74.7% smaller** |
|
|
19
|
+
| **TTS Verbalizer** | CTranslate2 INT8 (`51 MB`, 4.4 ms/sentence) | PyTorch FP32 MarianMT (`200 MB`, 2.9 s/sentence) | **660x faster**, **74.3% smaller** |
|
|
20
|
+
| **Morphology Tier** | spaCy small (`uk_core_news_sm`, ~15 MB) | spaCy TRF (`uk_core_news_trf_380`, 380 MB) | small CPU tagger |
|
|
21
|
+
| **Total Model Disk** | **425 MB** | **~1,680 MB** (+ 380 MB spaCy) | **74.7% disk reduction** |
|
|
22
|
+
| **Runtime Memory (RSS)** | **~120 – 180 MB** | **~1,500 – 2,200 MB** | **~10x lower RAM** |
|
|
23
|
+
| **Recommended For** | Production TTS, embedded systems, CLI, microservices | Research, batch indexing, maximum ensemble accuracy | |
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install accentuk
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Optional TTS verbalization support:
|
|
34
|
+
```bash
|
|
35
|
+
pip install "accentuk[tts]"
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Quick Start (Python API)
|
|
41
|
+
|
|
42
|
+
### 1. Stress Marking (`Accentor`)
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from accentuk import Accentor
|
|
46
|
+
|
|
47
|
+
# Light mode: fast CTranslate2 INT8 models, low memory footprint
|
|
48
|
+
with Accentor(mode="light") as engine:
|
|
49
|
+
result = engine.stress("Замок стоїть на горі.")
|
|
50
|
+
print(result.text) # "За́мок стої́ть на горі́."
|
|
51
|
+
for token in result.tokens:
|
|
52
|
+
print(f"{token.text} -> {token.output_text} ({token.status})")
|
|
53
|
+
|
|
54
|
+
# Full mode: PyTorch FP32 models + spaCy TRF + Combiner
|
|
55
|
+
with Accentor(mode="full") as engine:
|
|
56
|
+
result = engine.stress("Замок стоїть на горі.")
|
|
57
|
+
print(result.text)
|
|
58
|
+
|
|
59
|
+
# Auto mode (default): uses Light if CT2 models exist, otherwise Full/Dictionary
|
|
60
|
+
with Accentor(mode="auto") as engine:
|
|
61
|
+
result = engine.stress("Мої сестри.")
|
|
62
|
+
print(result.text) # "Мої́ се́стри."
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### 2. TTS Normalization & Stress Marking (`Frontend`)
|
|
66
|
+
|
|
67
|
+
Normalizes dates, numbers, currencies, abbreviations, and symbols, then applies stress marks:
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from accentuk import Frontend
|
|
71
|
+
|
|
72
|
+
# Light mode: fast INT8 verbalization (4.4 ms) + Light stress marking
|
|
73
|
+
with Frontend(mode="light") as frontend:
|
|
74
|
+
result = frontend.prepare("Вона купила 25 яблук за 150 грн 3 квітня 2024 року.")
|
|
75
|
+
print(result.text)
|
|
76
|
+
|
|
77
|
+
# Full mode: MarianMT PyTorch FP32 + Full stress marking
|
|
78
|
+
with Frontend(mode="full") as frontend:
|
|
79
|
+
result = frontend.prepare("Вона купила 25 яблук за 150 грн 3 квітня 2024 року.")
|
|
80
|
+
print(result.text)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## CLI Usage
|
|
86
|
+
|
|
87
|
+
### Downloading Model Assets
|
|
88
|
+
|
|
89
|
+
Download the appropriate bundle for your target environment:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
# Download Light assets (~425 MB CT2 INT8 models + lexicon)
|
|
93
|
+
accentuk download --light
|
|
94
|
+
|
|
95
|
+
# Download Full assets (~2.2 GB PyTorch weights + spaCy TRF + lexicon)
|
|
96
|
+
accentuk download --full
|
|
97
|
+
|
|
98
|
+
# Download with TTS verbalizer included
|
|
99
|
+
accentuk download --light --tts
|
|
100
|
+
accentuk download --full --tts
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Stress Marking from CLI
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
# Stress plain Ukrainian text using Light mode
|
|
107
|
+
accentuk stress "Замок на горі стоїть." --mode light
|
|
108
|
+
|
|
109
|
+
# Stress using Full mode
|
|
110
|
+
accentuk stress "Замок на горі стоїть." --mode full
|
|
111
|
+
|
|
112
|
+
# Process text from standard input
|
|
113
|
+
echo "Мої сестри." | accentuk stress --mode light
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### TTS Normalization from CLI
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
accentuk prepare "О 7:45 ранку 3 квітня потяг № 12 прибув до Києва." --mode light
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## Accuracy
|
|
125
|
+
|
|
126
|
+
Measured on 2026-10-13 with the same benchmarks as the service (`vacuum-in/accentuk-api`), word accuracy:
|
|
127
|
+
|
|
128
|
+
| test | service | full mode | light mode |
|
|
129
|
+
|---|---:|---:|---:|
|
|
130
|
+
| 200 most frequent ambiguous forms of Common Voice uk, stress heard in the recordings | 95.88% | 95.88% | 95.54% |
|
|
131
|
+
| modern-text gold, 3,887 words (all / reviewed lines) | 98.07% / 96.83% | 98.07% / 96.83% | 97.63% / 96.25% |
|
|
132
|
+
| [lang-uk stress benchmark](https://github.com/lang-uk/ukrainian-tts-preprocessing), words / heteronyms | 96.10% / 84.62% | 96.10% / 84.62% | 96.10% / 84.62% |
|
|
133
|
+
|
|
134
|
+
The lexicon `accentuk download` installs (`lexicon-v2`, built from the public `data-v2` of accentuk-api) is the
|
|
135
|
+
service's, including the 51,298-word dictionary of stress heard in recordings; the light-mode column was measured on a
|
|
136
|
+
clean download of it.
|
|
137
|
+
|
|
138
|
+
Full mode gives the service's answers. Light mode differs on 34 lang-uk tokens: 18 where the small spaCy tagger
|
|
139
|
+
parses differently from the transformer one, the rest from INT8 quantization (the INT8 cross-encoder picks
|
|
140
|
+
another reading than FP32 on 2.1% of targets; its margins track FP32 with r = 0.984, so the served threshold 0.5 is kept).
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Benchmark Results
|
|
145
|
+
|
|
146
|
+
Evaluated on AMD EPYC / Intel Xeon CPUs with single-thread and batched execution:
|
|
147
|
+
|
|
148
|
+
| Model Tier | PyTorch FP32 Latency | CTranslate2 INT8 Latency | Speedup | Quality Parity |
|
|
149
|
+
|---|---|---|---|---|
|
|
150
|
+
| **Verbalizer (MarianMT)** | 2,891 ms / sentence | **4.38 ms / sentence** | **659.9x** | 100% exact match |
|
|
151
|
+
| **Token Classifier (XLM-R-uk)** | 31.0 ms / target | **5.20 ms / target** | **5.96x** | 100% top-1 match |
|
|
152
|
+
| **Cross-Encoder (XLM-R)** | 100.2 ms / target | **32.6 ms / target** | **3.07x** | 96.0% top-1 match |
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## Disambiguation Pipeline
|
|
157
|
+
|
|
158
|
+
When a word has multiple possible accents (heteronym), `accentuk` resolves stress through sequential tiers:
|
|
159
|
+
|
|
160
|
+
1. **Memory-Mapped Lexicon**: Exact form lookup via MARISA Trie (`lexicon.marisa`).
|
|
161
|
+
2. **Capitalization & Proper Noun Rules**: Differentiates names and toponyms (e.g. *Розді́л* vs. *ро́зділ*).
|
|
162
|
+
3. **Prepositional Pronoun Shift**: Shifts accent to the first syllable after governing prepositions (e.g. *без ньо́го*, *до ме́не*).
|
|
163
|
+
4. **Contextual Cross-Encoder**: Evaluates sentence context against candidate senses (*aloudreader/uk-stress-crossencoder*).
|
|
164
|
+
5. **Token Classifier**: Direct sequence labeling trained on audiobook audio alignment (*aloudreader/uk-stress-token-classifier*).
|
|
165
|
+
6. **Morphology & Agreement Rules**: Grammatical tags and case/number agreements (spaCy TRF in Full mode).
|
|
166
|
+
7. **Dictionary Defaults & Fallbacks**: Trie defaults, compound splitting (*пшенично-житній*), and analogy-based suffix tables.
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## License
|
|
171
|
+
|
|
172
|
+
Apache-2.0. See `LICENSE` and `NOTICE.md` for third-party component licenses and dataset attributions.
|