ovos-plugin-linguonnx 0.2.0a1__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.
- ovos_plugin_linguonnx-0.2.0a1/LICENSE +202 -0
- ovos_plugin_linguonnx-0.2.0a1/PKG-INFO +205 -0
- ovos_plugin_linguonnx-0.2.0a1/README.md +188 -0
- ovos_plugin_linguonnx-0.2.0a1/ovos_plugin_linguonnx/__init__.py +26 -0
- ovos_plugin_linguonnx-0.2.0a1/ovos_plugin_linguonnx/detect.py +62 -0
- ovos_plugin_linguonnx-0.2.0a1/ovos_plugin_linguonnx/translate.py +165 -0
- ovos_plugin_linguonnx-0.2.0a1/ovos_plugin_linguonnx/version.py +13 -0
- ovos_plugin_linguonnx-0.2.0a1/ovos_plugin_linguonnx.egg-info/PKG-INFO +205 -0
- ovos_plugin_linguonnx-0.2.0a1/ovos_plugin_linguonnx.egg-info/SOURCES.txt +15 -0
- ovos_plugin_linguonnx-0.2.0a1/ovos_plugin_linguonnx.egg-info/dependency_links.txt +1 -0
- ovos_plugin_linguonnx-0.2.0a1/ovos_plugin_linguonnx.egg-info/entry_points.txt +5 -0
- ovos_plugin_linguonnx-0.2.0a1/ovos_plugin_linguonnx.egg-info/requires.txt +5 -0
- ovos_plugin_linguonnx-0.2.0a1/ovos_plugin_linguonnx.egg-info/top_level.txt +1 -0
- ovos_plugin_linguonnx-0.2.0a1/pyproject.toml +40 -0
- ovos_plugin_linguonnx-0.2.0a1/setup.cfg +4 -0
- ovos_plugin_linguonnx-0.2.0a1/test/test_detect.py +120 -0
- ovos_plugin_linguonnx-0.2.0a1/test/test_translate.py +205 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2024 Casimiro Ferreira
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ovos-plugin-linguonnx
|
|
3
|
+
Version: 0.2.0a1
|
|
4
|
+
Summary: OVOS language detection and translation plugins using linguonnx (ONNX, offline)
|
|
5
|
+
Author-email: jarbasAi <jarbasai@mailfence.com>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/OpenVoiceOS/ovos-plugin-linguonnx
|
|
8
|
+
Project-URL: linguonnx, https://github.com/OpenVoiceOS/linguonnx
|
|
9
|
+
Requires-Python: >=3.8
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: linguonnx>=0.9.3a1
|
|
13
|
+
Requires-Dist: ovos-plugin-manager<3.0.0,>=2.1.0
|
|
14
|
+
Provides-Extra: test
|
|
15
|
+
Requires-Dist: pytest; extra == "test"
|
|
16
|
+
Dynamic: license-file
|
|
17
|
+
|
|
18
|
+
# ovos-plugin-linguonnx
|
|
19
|
+
|
|
20
|
+
OVOS language plugins built on
|
|
21
|
+
[`linguonnx`](https://github.com/OpenVoiceOS/linguonnx). One package, two
|
|
22
|
+
plugins, both CPU-only on `onnxruntime`, both fully offline after the models
|
|
23
|
+
are cached, neither needs torch:
|
|
24
|
+
|
|
25
|
+
| Plugin | Entry point group | Plugin id |
|
|
26
|
+
|---|---|---|
|
|
27
|
+
| `LinguONNXLangDetectPlugin` | `opm.lang.detect` | `ovos-lang-detect-plugin-linguonnx` |
|
|
28
|
+
| `LinguONNXTranslatePlugin` | `opm.lang.translate` | `ovos-translate-plugin-linguonnx` |
|
|
29
|
+
|
|
30
|
+
> This package was called `ovos-lang-detect-plugin-linguonnx` while it only did
|
|
31
|
+
> detection. The plugin **ids** did not change, so existing configuration keeps
|
|
32
|
+
> working; only the distribution name and the Python package did.
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install ovos-plugin-linguonnx
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Models download from HuggingFace on first use and are cached under
|
|
41
|
+
`~/.cache/linguonnx/models/<model_id>/`. Constructing either plugin does not
|
|
42
|
+
trigger a download; the first real call does. On a server, prefetch instead —
|
|
43
|
+
see [Prefetching](#prefetching).
|
|
44
|
+
|
|
45
|
+
## Language detection
|
|
46
|
+
|
|
47
|
+
```json
|
|
48
|
+
{
|
|
49
|
+
"language_detection": {
|
|
50
|
+
"module": "ovos-lang-detect-plugin-linguonnx",
|
|
51
|
+
"ovos-lang-detect-plugin-linguonnx": {
|
|
52
|
+
"model": "glotlid-int8",
|
|
53
|
+
"collapse_varieties": true,
|
|
54
|
+
"min_confidence": 0.0,
|
|
55
|
+
"lang": "en-US"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
- `model`: `"glotlid-int8"` (default, quantized, 419 MB) or `"glotlid"`
|
|
62
|
+
(fp32, 1.68 GB). Both cover the same 2102 GlotLID labels; the int8 model
|
|
63
|
+
has no measured accuracy loss, so there is no reason to prefer the fp32
|
|
64
|
+
one unless you need it for some other purpose.
|
|
65
|
+
- `collapse_varieties`: see [Language varieties](#language-varieties).
|
|
66
|
+
- `min_confidence`: if the model's top confidence is below this, `detect()`
|
|
67
|
+
returns `self.config.get("lang", "en-US")` instead of the detected tag.
|
|
68
|
+
Default `0.0`, meaning no fallback ever triggers.
|
|
69
|
+
- `lang`: the fallback tag used when `min_confidence` isn't met. Default
|
|
70
|
+
`"en-US"`.
|
|
71
|
+
|
|
72
|
+
### Language varieties
|
|
73
|
+
|
|
74
|
+
GlotLID identifies individual language varieties, not macrolanguages.
|
|
75
|
+
Casual Arabic text comes back as e.g. `ajp-Arab` (South Levantine) rather
|
|
76
|
+
than `ar`, and some Chinese text comes back as `yue-Hani` (Cantonese)
|
|
77
|
+
rather than `zh`.
|
|
78
|
+
|
|
79
|
+
`linguonnx` itself defaults to reporting these varieties as-is, since that
|
|
80
|
+
fine-grained answer is useful on its own (free dialect identification).
|
|
81
|
+
This plugin flips the default to collapse varieties onto their
|
|
82
|
+
macrolanguage (`ajp-Arab` -> `ar`), because the two things OVOS actually
|
|
83
|
+
does with a detected language tag - picking a TTS voice, picking a
|
|
84
|
+
translation target - only know macrolanguages. A caller getting
|
|
85
|
+
`ajp-Arab` back from a pipeline that only ships `ar` voices would read it
|
|
86
|
+
as unsupported.
|
|
87
|
+
|
|
88
|
+
Set `collapse_varieties: false` in the plugin config to get `linguonnx`'s
|
|
89
|
+
native per-variety fidelity instead.
|
|
90
|
+
|
|
91
|
+
## Translation
|
|
92
|
+
|
|
93
|
+
```json
|
|
94
|
+
{
|
|
95
|
+
"language_translation": {
|
|
96
|
+
"module": "ovos-translate-plugin-linguonnx",
|
|
97
|
+
"ovos-translate-plugin-linguonnx": {
|
|
98
|
+
"prefer": "fewest_hops",
|
|
99
|
+
"max_hops": 2,
|
|
100
|
+
"pivot_ranking": "auto",
|
|
101
|
+
"include_noncommercial": false,
|
|
102
|
+
"precision": "int8",
|
|
103
|
+
"exclude_flagged": false,
|
|
104
|
+
"min_chrf": null,
|
|
105
|
+
"models": null,
|
|
106
|
+
"model_cache_size": 4,
|
|
107
|
+
"max_model_mb": 8192,
|
|
108
|
+
"num_beams": 4,
|
|
109
|
+
"max_new_tokens": 128
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Every key is optional. A key you leave out is not defaulted by the plugin — it
|
|
116
|
+
is simply not passed, so `linguonnx` stays the single source of truth for what
|
|
117
|
+
a default is. The values above are the `linguonnx` defaults.
|
|
118
|
+
|
|
119
|
+
- `prefer`: route ranking. `"fewest_hops"` takes the shortest route.
|
|
120
|
+
`"dedicated"` prefers a bilingual model over a multilingual one even when
|
|
121
|
+
that costs an extra hop.
|
|
122
|
+
- `max_hops`: how many models a route may chain. `1` is direct models only,
|
|
123
|
+
`2` allows one pivot language. Higher is allowed, but each hop compounds the
|
|
124
|
+
previous hop's errors.
|
|
125
|
+
- `pivot_ranking`: how pivot candidates are ordered on a two-hop route.
|
|
126
|
+
`"auto"` uses phonological distance when `orthography2ipa` is installed
|
|
127
|
+
(`pip install linguonnx[distance]`) and a curated table otherwise.
|
|
128
|
+
`"phonological"` demands the package; `"table"` ignores it.
|
|
129
|
+
- `include_noncommercial`: `false` uses only permissively licensed models.
|
|
130
|
+
`true` adds NLLB-200 (CC-BY-NC-4.0) — broader coverage, but it puts a
|
|
131
|
+
non-commercial licence on your output.
|
|
132
|
+
- `precision`: `"int8"` for the quantized models, `"fp32"` for the full ones
|
|
133
|
+
(roughly 4x the disk and memory), or `null` for both.
|
|
134
|
+
- `exclude_flagged`: drop any model linguonnx's own quality sweep flags —
|
|
135
|
+
either precision scoring below 40 chrF against the FLORES-200 reference, or
|
|
136
|
+
int8 trailing fp32 by more than 2 chrF. Combine with `precision: null` to
|
|
137
|
+
fall back to fp32 wherever int8 alone is flagged.
|
|
138
|
+
- `min_chrf`: drop any model scoring below this chrF against FLORES-200.
|
|
139
|
+
`null` keeps every model the other filters allow through.
|
|
140
|
+
- `models`: exact registry ids to route over, overriding every other filter
|
|
141
|
+
above. A list of model ids as linguonnx names them.
|
|
142
|
+
- `model_cache_size`: how many loaded models stay in memory at once,
|
|
143
|
+
least-recently-used evicted first. The whole default graph is ~25 GB, so
|
|
144
|
+
this is the knob that keeps a long-lived server from being OOM-killed.
|
|
145
|
+
- `max_model_mb`: refuse a cold download larger than this, in MB, instead of
|
|
146
|
+
holding the request for minutes. Set it low on a host whose cache is
|
|
147
|
+
pre-warmed, so a surprise fetch fails fast and loudly. It maps to the
|
|
148
|
+
`LINGUONNX_MAX_DOWNLOAD_MB` environment variable.
|
|
149
|
+
- `num_beams`: beam width. `1` is greedy and about 4x faster.
|
|
150
|
+
- `max_new_tokens`: output length cap per hop. Raise it for long input; the
|
|
151
|
+
decode loop stops at the cap without warning.
|
|
152
|
+
|
|
153
|
+
### Routing
|
|
154
|
+
|
|
155
|
+
`linguonnx` is not one giant multilingual model. It is a graph of models, and a
|
|
156
|
+
request is routed through one or two of them. A pair with a direct model
|
|
157
|
+
(`en->gl`) runs that model; a pair without one (`pt->eu`) pivots
|
|
158
|
+
(`pt->en->eu`). This is why `supported_translations(source)` is narrower than
|
|
159
|
+
`available_languages`: a tag can be in the graph and still have no route from
|
|
160
|
+
your source.
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
from ovos_plugin_linguonnx import LinguONNXTranslatePlugin
|
|
164
|
+
|
|
165
|
+
tx = LinguONNXTranslatePlugin()
|
|
166
|
+
tx.translate("Good morning", target="gl", source="en")
|
|
167
|
+
tx.supported_translations("en") # targets routable from English
|
|
168
|
+
tx.available_languages # every tag anywhere in the graph
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Errors
|
|
172
|
+
|
|
173
|
+
`translate()` raises builtins, never a `linguonnx` exception type, so a caller
|
|
174
|
+
that only knows the OVOS interface can still tell the two failure modes apart:
|
|
175
|
+
|
|
176
|
+
- **`ValueError`** — the pair is not routable. The caller asked for something
|
|
177
|
+
this graph cannot serve. `linguonnx`'s own message says which bound blocked
|
|
178
|
+
it (hop cap, licence filter, unrunnable model), so it is passed through.
|
|
179
|
+
- **`RuntimeError`** — the pair is routable, but the model is not on disk and
|
|
180
|
+
`max_model_mb` refused to fetch it on the request path. Retrying will not
|
|
181
|
+
help; prefetch the model.
|
|
182
|
+
|
|
183
|
+
A server in front of this should map the first to 4xx and the second to 5xx.
|
|
184
|
+
Blaming the caller for a cold cache is the mistake worth avoiding.
|
|
185
|
+
|
|
186
|
+
### Prefetching
|
|
187
|
+
|
|
188
|
+
On a server, no request should ever trigger a download. Warm the cache at
|
|
189
|
+
deploy time:
|
|
190
|
+
|
|
191
|
+
```python
|
|
192
|
+
from linguonnx import load_translator
|
|
193
|
+
from linguonnx.model_manager import prefetch
|
|
194
|
+
|
|
195
|
+
prefetch(*load_translator().models, kind="translate")
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
The default permissive int8 selection is 73 models, about 25 GB on disk.
|
|
199
|
+
|
|
200
|
+
## Credits
|
|
201
|
+
|
|
202
|
+
- [linguonnx](https://github.com/OpenVoiceOS/linguonnx) — the detection and
|
|
203
|
+
translation engine this package wraps.
|
|
204
|
+
- [TigreGotico/glotlid-onnx](https://huggingface.co/TigreGotico/glotlid-onnx) —
|
|
205
|
+
the ONNX export of GlotLID that `linguonnx` runs for detection.
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# ovos-plugin-linguonnx
|
|
2
|
+
|
|
3
|
+
OVOS language plugins built on
|
|
4
|
+
[`linguonnx`](https://github.com/OpenVoiceOS/linguonnx). One package, two
|
|
5
|
+
plugins, both CPU-only on `onnxruntime`, both fully offline after the models
|
|
6
|
+
are cached, neither needs torch:
|
|
7
|
+
|
|
8
|
+
| Plugin | Entry point group | Plugin id |
|
|
9
|
+
|---|---|---|
|
|
10
|
+
| `LinguONNXLangDetectPlugin` | `opm.lang.detect` | `ovos-lang-detect-plugin-linguonnx` |
|
|
11
|
+
| `LinguONNXTranslatePlugin` | `opm.lang.translate` | `ovos-translate-plugin-linguonnx` |
|
|
12
|
+
|
|
13
|
+
> This package was called `ovos-lang-detect-plugin-linguonnx` while it only did
|
|
14
|
+
> detection. The plugin **ids** did not change, so existing configuration keeps
|
|
15
|
+
> working; only the distribution name and the Python package did.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install ovos-plugin-linguonnx
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Models download from HuggingFace on first use and are cached under
|
|
24
|
+
`~/.cache/linguonnx/models/<model_id>/`. Constructing either plugin does not
|
|
25
|
+
trigger a download; the first real call does. On a server, prefetch instead —
|
|
26
|
+
see [Prefetching](#prefetching).
|
|
27
|
+
|
|
28
|
+
## Language detection
|
|
29
|
+
|
|
30
|
+
```json
|
|
31
|
+
{
|
|
32
|
+
"language_detection": {
|
|
33
|
+
"module": "ovos-lang-detect-plugin-linguonnx",
|
|
34
|
+
"ovos-lang-detect-plugin-linguonnx": {
|
|
35
|
+
"model": "glotlid-int8",
|
|
36
|
+
"collapse_varieties": true,
|
|
37
|
+
"min_confidence": 0.0,
|
|
38
|
+
"lang": "en-US"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
- `model`: `"glotlid-int8"` (default, quantized, 419 MB) or `"glotlid"`
|
|
45
|
+
(fp32, 1.68 GB). Both cover the same 2102 GlotLID labels; the int8 model
|
|
46
|
+
has no measured accuracy loss, so there is no reason to prefer the fp32
|
|
47
|
+
one unless you need it for some other purpose.
|
|
48
|
+
- `collapse_varieties`: see [Language varieties](#language-varieties).
|
|
49
|
+
- `min_confidence`: if the model's top confidence is below this, `detect()`
|
|
50
|
+
returns `self.config.get("lang", "en-US")` instead of the detected tag.
|
|
51
|
+
Default `0.0`, meaning no fallback ever triggers.
|
|
52
|
+
- `lang`: the fallback tag used when `min_confidence` isn't met. Default
|
|
53
|
+
`"en-US"`.
|
|
54
|
+
|
|
55
|
+
### Language varieties
|
|
56
|
+
|
|
57
|
+
GlotLID identifies individual language varieties, not macrolanguages.
|
|
58
|
+
Casual Arabic text comes back as e.g. `ajp-Arab` (South Levantine) rather
|
|
59
|
+
than `ar`, and some Chinese text comes back as `yue-Hani` (Cantonese)
|
|
60
|
+
rather than `zh`.
|
|
61
|
+
|
|
62
|
+
`linguonnx` itself defaults to reporting these varieties as-is, since that
|
|
63
|
+
fine-grained answer is useful on its own (free dialect identification).
|
|
64
|
+
This plugin flips the default to collapse varieties onto their
|
|
65
|
+
macrolanguage (`ajp-Arab` -> `ar`), because the two things OVOS actually
|
|
66
|
+
does with a detected language tag - picking a TTS voice, picking a
|
|
67
|
+
translation target - only know macrolanguages. A caller getting
|
|
68
|
+
`ajp-Arab` back from a pipeline that only ships `ar` voices would read it
|
|
69
|
+
as unsupported.
|
|
70
|
+
|
|
71
|
+
Set `collapse_varieties: false` in the plugin config to get `linguonnx`'s
|
|
72
|
+
native per-variety fidelity instead.
|
|
73
|
+
|
|
74
|
+
## Translation
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"language_translation": {
|
|
79
|
+
"module": "ovos-translate-plugin-linguonnx",
|
|
80
|
+
"ovos-translate-plugin-linguonnx": {
|
|
81
|
+
"prefer": "fewest_hops",
|
|
82
|
+
"max_hops": 2,
|
|
83
|
+
"pivot_ranking": "auto",
|
|
84
|
+
"include_noncommercial": false,
|
|
85
|
+
"precision": "int8",
|
|
86
|
+
"exclude_flagged": false,
|
|
87
|
+
"min_chrf": null,
|
|
88
|
+
"models": null,
|
|
89
|
+
"model_cache_size": 4,
|
|
90
|
+
"max_model_mb": 8192,
|
|
91
|
+
"num_beams": 4,
|
|
92
|
+
"max_new_tokens": 128
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Every key is optional. A key you leave out is not defaulted by the plugin — it
|
|
99
|
+
is simply not passed, so `linguonnx` stays the single source of truth for what
|
|
100
|
+
a default is. The values above are the `linguonnx` defaults.
|
|
101
|
+
|
|
102
|
+
- `prefer`: route ranking. `"fewest_hops"` takes the shortest route.
|
|
103
|
+
`"dedicated"` prefers a bilingual model over a multilingual one even when
|
|
104
|
+
that costs an extra hop.
|
|
105
|
+
- `max_hops`: how many models a route may chain. `1` is direct models only,
|
|
106
|
+
`2` allows one pivot language. Higher is allowed, but each hop compounds the
|
|
107
|
+
previous hop's errors.
|
|
108
|
+
- `pivot_ranking`: how pivot candidates are ordered on a two-hop route.
|
|
109
|
+
`"auto"` uses phonological distance when `orthography2ipa` is installed
|
|
110
|
+
(`pip install linguonnx[distance]`) and a curated table otherwise.
|
|
111
|
+
`"phonological"` demands the package; `"table"` ignores it.
|
|
112
|
+
- `include_noncommercial`: `false` uses only permissively licensed models.
|
|
113
|
+
`true` adds NLLB-200 (CC-BY-NC-4.0) — broader coverage, but it puts a
|
|
114
|
+
non-commercial licence on your output.
|
|
115
|
+
- `precision`: `"int8"` for the quantized models, `"fp32"` for the full ones
|
|
116
|
+
(roughly 4x the disk and memory), or `null` for both.
|
|
117
|
+
- `exclude_flagged`: drop any model linguonnx's own quality sweep flags —
|
|
118
|
+
either precision scoring below 40 chrF against the FLORES-200 reference, or
|
|
119
|
+
int8 trailing fp32 by more than 2 chrF. Combine with `precision: null` to
|
|
120
|
+
fall back to fp32 wherever int8 alone is flagged.
|
|
121
|
+
- `min_chrf`: drop any model scoring below this chrF against FLORES-200.
|
|
122
|
+
`null` keeps every model the other filters allow through.
|
|
123
|
+
- `models`: exact registry ids to route over, overriding every other filter
|
|
124
|
+
above. A list of model ids as linguonnx names them.
|
|
125
|
+
- `model_cache_size`: how many loaded models stay in memory at once,
|
|
126
|
+
least-recently-used evicted first. The whole default graph is ~25 GB, so
|
|
127
|
+
this is the knob that keeps a long-lived server from being OOM-killed.
|
|
128
|
+
- `max_model_mb`: refuse a cold download larger than this, in MB, instead of
|
|
129
|
+
holding the request for minutes. Set it low on a host whose cache is
|
|
130
|
+
pre-warmed, so a surprise fetch fails fast and loudly. It maps to the
|
|
131
|
+
`LINGUONNX_MAX_DOWNLOAD_MB` environment variable.
|
|
132
|
+
- `num_beams`: beam width. `1` is greedy and about 4x faster.
|
|
133
|
+
- `max_new_tokens`: output length cap per hop. Raise it for long input; the
|
|
134
|
+
decode loop stops at the cap without warning.
|
|
135
|
+
|
|
136
|
+
### Routing
|
|
137
|
+
|
|
138
|
+
`linguonnx` is not one giant multilingual model. It is a graph of models, and a
|
|
139
|
+
request is routed through one or two of them. A pair with a direct model
|
|
140
|
+
(`en->gl`) runs that model; a pair without one (`pt->eu`) pivots
|
|
141
|
+
(`pt->en->eu`). This is why `supported_translations(source)` is narrower than
|
|
142
|
+
`available_languages`: a tag can be in the graph and still have no route from
|
|
143
|
+
your source.
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
from ovos_plugin_linguonnx import LinguONNXTranslatePlugin
|
|
147
|
+
|
|
148
|
+
tx = LinguONNXTranslatePlugin()
|
|
149
|
+
tx.translate("Good morning", target="gl", source="en")
|
|
150
|
+
tx.supported_translations("en") # targets routable from English
|
|
151
|
+
tx.available_languages # every tag anywhere in the graph
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Errors
|
|
155
|
+
|
|
156
|
+
`translate()` raises builtins, never a `linguonnx` exception type, so a caller
|
|
157
|
+
that only knows the OVOS interface can still tell the two failure modes apart:
|
|
158
|
+
|
|
159
|
+
- **`ValueError`** — the pair is not routable. The caller asked for something
|
|
160
|
+
this graph cannot serve. `linguonnx`'s own message says which bound blocked
|
|
161
|
+
it (hop cap, licence filter, unrunnable model), so it is passed through.
|
|
162
|
+
- **`RuntimeError`** — the pair is routable, but the model is not on disk and
|
|
163
|
+
`max_model_mb` refused to fetch it on the request path. Retrying will not
|
|
164
|
+
help; prefetch the model.
|
|
165
|
+
|
|
166
|
+
A server in front of this should map the first to 4xx and the second to 5xx.
|
|
167
|
+
Blaming the caller for a cold cache is the mistake worth avoiding.
|
|
168
|
+
|
|
169
|
+
### Prefetching
|
|
170
|
+
|
|
171
|
+
On a server, no request should ever trigger a download. Warm the cache at
|
|
172
|
+
deploy time:
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
from linguonnx import load_translator
|
|
176
|
+
from linguonnx.model_manager import prefetch
|
|
177
|
+
|
|
178
|
+
prefetch(*load_translator().models, kind="translate")
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
The default permissive int8 selection is 73 models, about 25 GB on disk.
|
|
182
|
+
|
|
183
|
+
## Credits
|
|
184
|
+
|
|
185
|
+
- [linguonnx](https://github.com/OpenVoiceOS/linguonnx) — the detection and
|
|
186
|
+
translation engine this package wraps.
|
|
187
|
+
- [TigreGotico/glotlid-onnx](https://huggingface.co/TigreGotico/glotlid-onnx) —
|
|
188
|
+
the ONNX export of GlotLID that `linguonnx` runs for detection.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""OVOS language plugins backed by `linguonnx <https://github.com/OpenVoiceOS/linguonnx>`_.
|
|
2
|
+
|
|
3
|
+
One package ships both halves of the library:
|
|
4
|
+
|
|
5
|
+
``LinguONNXLangDetectPlugin``
|
|
6
|
+
``opm.lang.detect`` - GlotLID language identification over ONNX Runtime.
|
|
7
|
+
``LinguONNXTranslatePlugin``
|
|
8
|
+
``opm.lang.translate`` - offline machine translation over the linguonnx
|
|
9
|
+
routing graph (M2M100 plus the opus-mt bilingual pairs by default).
|
|
10
|
+
|
|
11
|
+
Both load their models on first use, so importing or constructing either class
|
|
12
|
+
never touches the disk or the network.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from ovos_plugin_linguonnx.detect import LinguONNXLangDetectPlugin
|
|
16
|
+
from ovos_plugin_linguonnx.translate import LinguONNXTranslatePlugin
|
|
17
|
+
from ovos_plugin_linguonnx.version import __version__
|
|
18
|
+
|
|
19
|
+
# Historical aliases. `ovos-lang-detect-plugin-linguonnx` exported
|
|
20
|
+
# `LanguageDetectorPlugin` from its top-level package, and configs and imports
|
|
21
|
+
# in the wild still use it.
|
|
22
|
+
LanguageDetectorPlugin = LinguONNXLangDetectPlugin
|
|
23
|
+
LanguageTranslatorPlugin = LinguONNXTranslatePlugin
|
|
24
|
+
|
|
25
|
+
__all__ = ["LinguONNXLangDetectPlugin", "LinguONNXTranslatePlugin",
|
|
26
|
+
"LanguageDetectorPlugin", "LanguageTranslatorPlugin", "__version__"]
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""OVOS language-detection plugin wrapping the linguonnx GlotLID detector."""
|
|
2
|
+
|
|
3
|
+
from typing import Dict, Optional, Set
|
|
4
|
+
|
|
5
|
+
from ovos_plugin_manager.templates.language import LanguageDetector
|
|
6
|
+
|
|
7
|
+
DEFAULT_MODEL = "glotlid-int8"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class LinguONNXLangDetectPlugin(LanguageDetector):
|
|
11
|
+
"""LanguageDetector implementation backed by ``linguonnx`` (GlotLID/ONNX).
|
|
12
|
+
|
|
13
|
+
The underlying model is only loaded on first call to :meth:`detect`,
|
|
14
|
+
:meth:`detect_probs`, :meth:`detect_raw` or :attr:`available_languages` -
|
|
15
|
+
constructing this class never triggers a model load/download.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def __init__(self, config: Optional[Dict] = None):
|
|
19
|
+
super().__init__(config)
|
|
20
|
+
self._detector = None
|
|
21
|
+
|
|
22
|
+
@property
|
|
23
|
+
def model(self) -> str:
|
|
24
|
+
return self.config.get("model", DEFAULT_MODEL)
|
|
25
|
+
|
|
26
|
+
@property
|
|
27
|
+
def collapse_varieties(self) -> bool:
|
|
28
|
+
# linguonnx itself defaults this to False (fidelity: "ajp-Arab" is a
|
|
29
|
+
# real, useful answer on its own). OVOS callers use the detected tag
|
|
30
|
+
# to pick a TTS voice or a translation target, and those pipelines
|
|
31
|
+
# only know macrolanguages - "ajp-Arab" would look unsupported where
|
|
32
|
+
# "ar" is. So the plugin flips the default to True; set
|
|
33
|
+
# collapse_varieties: false in config to get linguonnx's raw fidelity.
|
|
34
|
+
return self.config.get("collapse_varieties", True)
|
|
35
|
+
|
|
36
|
+
@property
|
|
37
|
+
def min_confidence(self) -> float:
|
|
38
|
+
return self.config.get("min_confidence", 0.0)
|
|
39
|
+
|
|
40
|
+
@property
|
|
41
|
+
def detector(self):
|
|
42
|
+
"""Lazily load (and cache) the linguonnx detector instance."""
|
|
43
|
+
if self._detector is None:
|
|
44
|
+
from linguonnx import load_detector
|
|
45
|
+
self._detector = load_detector(self.model)
|
|
46
|
+
return self._detector
|
|
47
|
+
|
|
48
|
+
def detect(self, text: str) -> str:
|
|
49
|
+
_, confidence = self.detector.detect_raw(text)
|
|
50
|
+
if confidence < self.min_confidence:
|
|
51
|
+
return self.config.get("lang", "en-US")
|
|
52
|
+
return self.detector.detect(text, collapse_varieties=self.collapse_varieties)
|
|
53
|
+
|
|
54
|
+
def detect_probs(self, text: str) -> Dict[str, float]:
|
|
55
|
+
return self.detector.detect_probs(text)
|
|
56
|
+
|
|
57
|
+
@property
|
|
58
|
+
def available_languages(self) -> Set[str]:
|
|
59
|
+
return self.detector.available_languages
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
__all__ = ["LinguONNXLangDetectPlugin"]
|