bifonia 0.1.1__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.
- bifonia-0.1.1/LICENSE +202 -0
- bifonia-0.1.1/PKG-INFO +159 -0
- bifonia-0.1.1/README.md +138 -0
- bifonia-0.1.1/bifonia/__init__.py +258 -0
- bifonia-0.1.1/bifonia/corpus.py +53 -0
- bifonia-0.1.1/bifonia/data/corpus.jsonl +56891 -0
- bifonia-0.1.1/bifonia/data/heterophonic_homographs.csv +57 -0
- bifonia-0.1.1/bifonia/data/sense_model_nb.json +79944 -0
- bifonia-0.1.1/bifonia/data/sense_model_perceptron.json +79810 -0
- bifonia-0.1.1/bifonia/data.py +129 -0
- bifonia-0.1.1/bifonia/features.py +155 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/adv_bridge.voc +20 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/after_prep_exclude.voc +18 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/after_prep_extra.voc +57 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/after_prep_weak.voc +14 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/ambiguous_preps.voc +9 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/articles.voc +10 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/aux_verbs.voc +20 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/bake_purpose.voc +8 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/bakeware.voc +17 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/before_prep_extra.voc +6 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/bundle_ambiguous.voc +34 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/bundle_things.voc +32 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/bundle_verbs.voc +71 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/clitics_all.voc +16 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/colher_control_verbs.voc +26 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/comparatives.voc +7 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/conj_subjunctive.voc +10 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/contracted_a.voc +7 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/contracted_det.voc +22 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/copula.voc +44 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/court_terms.voc +12 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/cut_context.voc +23 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/de_contractions.voc +9 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/deferral_adv.voc +8 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/determiners.voc +54 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/exclamative_det.voc +6 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/fem_det.voc +21 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/first_person_nouns.voc +15 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/forma_shape_next.voc +9 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/forma_shape_prev.voc +19 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/function_words.voc +31 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/head_locative.voc +7 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/head_state.voc +18 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/head_verbs.voc +42 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/intensifiers.voc +13 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/locative_contractions.voc +17 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/masc_det.voc +21 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/material_prep.voc +7 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/mould_cues.voc +48 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/neg_adv.voc +12 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/never_after_prep.voc +13 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/numeric.voc +45 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/optative_adv.voc +11 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/para_prev_subj.voc +10 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/para_verb_next.voc +17 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/passive_aux.voc +12 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/pelo_fixed.voc +49 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/pelo_route.voc +48 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/person_possessive.voc +11 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/possession_verbs.voc +17 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/post_clitics.voc +11 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/prep_governing.voc +12 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/pronouns.voc +22 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/pure_negation.voc +9 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/quantifiers.voc +40 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/sede_seat_cues.voc +67 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/sede_thirst_cues.voc +70 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/sing_articles.voc +7 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/soak_verbs.voc +47 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/sobre_adp_quant.voc +12 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/sobre_governors.voc +238 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/sobre_intensifiers.voc +15 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/stoppable_things.voc +76 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/temporal_conj.voc +7 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/tola_det_prev.voc +9 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/tola_poss_prev.voc +10 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/trans_verbs.voc +25 -0
- bifonia-0.1.1/bifonia/locale/pt-pt/wood_context.voc +25 -0
- bifonia-0.1.1/bifonia/model.py +96 -0
- bifonia-0.1.1/bifonia/scoring.py +735 -0
- bifonia-0.1.1/bifonia/version.py +10 -0
- bifonia-0.1.1/bifonia/vocab.py +41 -0
- bifonia-0.1.1/bifonia.egg-info/PKG-INFO +159 -0
- bifonia-0.1.1/bifonia.egg-info/SOURCES.txt +90 -0
- bifonia-0.1.1/bifonia.egg-info/dependency_links.txt +1 -0
- bifonia-0.1.1/bifonia.egg-info/requires.txt +3 -0
- bifonia-0.1.1/bifonia.egg-info/top_level.txt +1 -0
- bifonia-0.1.1/pyproject.toml +38 -0
- bifonia-0.1.1/setup.cfg +4 -0
- bifonia-0.1.1/tests/test_disambiguate.py +84 -0
- bifonia-0.1.1/tests/test_model.py +83 -0
bifonia-0.1.1/LICENSE
ADDED
|
@@ -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 [yyyy] [name of copyright owner]
|
|
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.
|
bifonia-0.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bifonia
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Portuguese heterophonic homograph disambiguation (rule-based + learned)
|
|
5
|
+
Author-email: JarbasAi <jarbasai@mailfence.com>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/TigreGotico/bifonia
|
|
8
|
+
Project-URL: Repository, https://github.com/TigreGotico/bifonia
|
|
9
|
+
Keywords: portuguese,nlp,homograph,ipa,phonetics,g2p,tts
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
14
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
15
|
+
Requires-Python: >=3.9
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Provides-Extra: test
|
|
19
|
+
Requires-Dist: pytest; extra == "test"
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# bifonia
|
|
23
|
+
|
|
24
|
+
Pronunciation disambiguation for European-Portuguese **heterophonic homographs** —
|
|
25
|
+
words spelled identically whose pronunciation depends on **meaning**.
|
|
26
|
+
|
|
27
|
+
`sede` is *thirst* (`ˈsedɨ`, closed e) or a *headquarters* (`ˈsɛdɨ`, open e); `forma`
|
|
28
|
+
is a *mould* (`ˈfoɾmɐ`) or a *shape* (`ˈfɔɾmɐ`); `molho` is *sauce* (`ˈmoʎu`) or a
|
|
29
|
+
*bundle* (`ˈmɔʎu`). A text-to-speech front-end that guesses wrong says the wrong word
|
|
30
|
+
out loud. bifonia picks the right reading — and therefore the right IPA — from context.
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
from bifonia import tokenize, is_ambiguous, guess_sense, disambiguate
|
|
34
|
+
|
|
35
|
+
words = tokenize("Tinha tanta sede que bebi a garrafa toda.")
|
|
36
|
+
i = words.index("sede")
|
|
37
|
+
guess_sense(words, i) # 'thirst'
|
|
38
|
+
disambiguate(words, i) # 'ˈsedɨ'
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Why meaning, not part of speech
|
|
42
|
+
|
|
43
|
+
The obvious approach — tag the part of speech and pick the pronunciation from it —
|
|
44
|
+
cannot work when two readings share a POS. `sede` thirst and seat are **both nouns**;
|
|
45
|
+
`corte` cut and court are both nominal; `forma` mould and shape likewise. A POS tagger
|
|
46
|
+
labels them identically and is wrong on the minority reading by construction. bifonia
|
|
47
|
+
keys every reading on **`sense`** (a meaning slug) and resolves the meaning directly.
|
|
48
|
+
|
|
49
|
+
## Two interchangeable engines
|
|
50
|
+
|
|
51
|
+
| engine | needs a corpus? | how it decides |
|
|
52
|
+
|--------|-----------------|----------------|
|
|
53
|
+
| **rules** | no | hand-written context rules + wordlists (`.voc`) |
|
|
54
|
+
| **learned** | yes | per-word Naive-Bayes / averaged-perceptron over context features |
|
|
55
|
+
|
|
56
|
+
The rule engine is self-contained and needs no training data — the right fit for a fork
|
|
57
|
+
of a low-resource language. The learned models are trained from the labelled corpus and
|
|
58
|
+
generalise better where enough data exists. `guess_sense` uses a **per-word ensemble**:
|
|
59
|
+
each word is served by whichever engine scores at least as well on held-out data, so the
|
|
60
|
+
combined system never does worse than the rules alone. Both are pure Python with no heavy
|
|
61
|
+
runtime dependencies.
|
|
62
|
+
|
|
63
|
+
The learned engine ships in two forms — a Naive-Bayes model and an averaged perceptron —
|
|
64
|
+
and `guess_sense` loads the **averaged perceptron** by default. The perceptron leads on both
|
|
65
|
+
the synthetic and the real-world benchmarks and avoids the per-word collapses that Naive-Bayes
|
|
66
|
+
suffers when correlated features violate its independence assumption; it is warm-started from
|
|
67
|
+
the Naive-Bayes log-odds, so its weights stay readable as per-sense lexicons. Load the other
|
|
68
|
+
model explicitly with `SenseModel.load(path)` if you want to compare.
|
|
69
|
+
|
|
70
|
+
## Accuracy
|
|
71
|
+
|
|
72
|
+
Sense prediction, measured two ways:
|
|
73
|
+
|
|
74
|
+
| approach | synthetic test | real-world (OOD) |
|
|
75
|
+
|----------|:--------------:|:----------------:|
|
|
76
|
+
| most-common baseline | 52.7% | 47.5% |
|
|
77
|
+
| spaCy POS → sense | 65.7% | 81.4% |
|
|
78
|
+
| Stanza POS → sense | 75.5% | 82.5% |
|
|
79
|
+
| rules (no corpus) | 94.5% | 84.6% |
|
|
80
|
+
| Naive-Bayes | 98.1% | 86.7% |
|
|
81
|
+
| averaged perceptron | 99.0% | 89.6% |
|
|
82
|
+
| **shipped ensemble** | **96.1%** | **90.5%** |
|
|
83
|
+
|
|
84
|
+
The *synthetic* column is the held-out split of the generated training corpus, balanced
|
|
85
|
+
across senses; the *OOD* column is real sentences from
|
|
86
|
+
[`bifonia-pt-homographs-wild`](https://huggingface.co/datasets/TigreGotico/bifonia-pt-homographs-wild).
|
|
87
|
+
The two columns answer different questions. The synthetic set is balanced, so it exposes
|
|
88
|
+
how badly POS tagging handles minority readings (a tagger cannot separate two senses that
|
|
89
|
+
share a part of speech — both score 0% on `sede`/thirst). Real text is skewed toward the
|
|
90
|
+
majority readings POS taggers do get right, which lifts them to ~82% — yet the
|
|
91
|
+
meaning-aware models still win, and the perceptron leads by ~7 points. Reproduce with
|
|
92
|
+
`python benchmark_tagger.py` (synthetic) and `python benchmark_ood.py` (OOD).
|
|
93
|
+
|
|
94
|
+
## Install
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
pip install -e . --no-deps
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
No dependencies — pure standard library.
|
|
101
|
+
|
|
102
|
+
## API
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
from bifonia import (tokenize, is_ambiguous, guess_sense, guess_pos,
|
|
106
|
+
disambiguate, add_extra_diacritics)
|
|
107
|
+
|
|
108
|
+
sentence = "Resolveu o problema desta forma simples."
|
|
109
|
+
words = tokenize(sentence)
|
|
110
|
+
i = words.index("forma")
|
|
111
|
+
|
|
112
|
+
guess_sense(words, i) # 'shape'
|
|
113
|
+
guess_pos(words, i) # 'NOUN' (descriptive)
|
|
114
|
+
disambiguate(words, i) # 'ˈfɔɾmɐ'
|
|
115
|
+
disambiguate(words, i, sense="mould") # 'ˈfoɾmɐ' (override)
|
|
116
|
+
add_extra_diacritics(sentence) # '...desta fórma simples.' (acute = open vowel)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
`add_extra_diacritics` rewrites each homograph with a disambiguating diacritic
|
|
120
|
+
(acute → open vowel, circumflex → closed) that a downstream grapheme-to-phoneme stage
|
|
121
|
+
can read directly.
|
|
122
|
+
|
|
123
|
+
## Datasets
|
|
124
|
+
|
|
125
|
+
Both on the Hugging Face Hub, schema `{word, sense, pos, ipa, sentence}`:
|
|
126
|
+
|
|
127
|
+
- [`bifonia-pt-homographs`](https://huggingface.co/datasets/TigreGotico/bifonia-pt-homographs)
|
|
128
|
+
— 56,891 labelled sentences over 27 words, with stratified train/test splits, for
|
|
129
|
+
training and synthetic evaluation.
|
|
130
|
+
- [`bifonia-pt-homographs-wild`](https://huggingface.co/datasets/TigreGotico/bifonia-pt-homographs-wild)
|
|
131
|
+
— real Wikipedia and web sentences, an out-of-distribution test set.
|
|
132
|
+
|
|
133
|
+
## Word coverage
|
|
134
|
+
|
|
135
|
+
27 homographs: `acordo`, `acerto`, `cerro`, `choro`, `colher`, `começo`, `conserto`,
|
|
136
|
+
`coro`, `corte`, `forma`, `gosto`, `gozo`, `jogo`, `molho`, `olho`, `para`, `pelo`,
|
|
137
|
+
`peso`, `porto`, `posto`, `rego`, `seco`, `sede`, `sobre`, `tola`, `torre`, `transtorno`.
|
|
138
|
+
|
|
139
|
+
Per-word IPA, senses, and diacritized forms are in [`docs/words.md`](docs/words.md).
|
|
140
|
+
|
|
141
|
+
## Project layout
|
|
142
|
+
|
|
143
|
+
- `bifonia/data/corpus.jsonl` — the labelled corpus (single source of truth).
|
|
144
|
+
- `bifonia/data/heterophonic_homographs.csv` — the `word,sense,pos,ipa` table.
|
|
145
|
+
- `bifonia/data/sense_model_{nb,perceptron}.json` — trained models (JSON weights).
|
|
146
|
+
- `bifonia/locale/<lang>/*.voc` — context wordlists, one term per line, editable.
|
|
147
|
+
- `bifonia/features.py` — language-agnostic feature extraction (shared by train and inference).
|
|
148
|
+
|
|
149
|
+
Porting to a related language means supplying a corpus and `.voc` files and retraining —
|
|
150
|
+
the algorithm carries no hardcoded Portuguese.
|
|
151
|
+
|
|
152
|
+
## See also
|
|
153
|
+
|
|
154
|
+
- [`docs/methodology.md`](docs/methodology.md) — algorithm, features, and benchmarks
|
|
155
|
+
- [`docs/usage.md`](docs/usage.md) — full API reference
|
|
156
|
+
- [`docs/words.md`](docs/words.md) — per-word pronunciation notes
|
|
157
|
+
- [`docs/diacritics_restoration.md`](docs/diacritics_restoration.md) — the diacritics-restoration task
|
|
158
|
+
- [`examples/basic_usage.py`](examples/basic_usage.py) — runnable demo
|
|
159
|
+
- [`train.py`](train.py) · [`benchmark_tagger.py`](benchmark_tagger.py) · [`benchmark_ood.py`](benchmark_ood.py)
|
bifonia-0.1.1/README.md
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# bifonia
|
|
2
|
+
|
|
3
|
+
Pronunciation disambiguation for European-Portuguese **heterophonic homographs** —
|
|
4
|
+
words spelled identically whose pronunciation depends on **meaning**.
|
|
5
|
+
|
|
6
|
+
`sede` is *thirst* (`ˈsedɨ`, closed e) or a *headquarters* (`ˈsɛdɨ`, open e); `forma`
|
|
7
|
+
is a *mould* (`ˈfoɾmɐ`) or a *shape* (`ˈfɔɾmɐ`); `molho` is *sauce* (`ˈmoʎu`) or a
|
|
8
|
+
*bundle* (`ˈmɔʎu`). A text-to-speech front-end that guesses wrong says the wrong word
|
|
9
|
+
out loud. bifonia picks the right reading — and therefore the right IPA — from context.
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
from bifonia import tokenize, is_ambiguous, guess_sense, disambiguate
|
|
13
|
+
|
|
14
|
+
words = tokenize("Tinha tanta sede que bebi a garrafa toda.")
|
|
15
|
+
i = words.index("sede")
|
|
16
|
+
guess_sense(words, i) # 'thirst'
|
|
17
|
+
disambiguate(words, i) # 'ˈsedɨ'
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Why meaning, not part of speech
|
|
21
|
+
|
|
22
|
+
The obvious approach — tag the part of speech and pick the pronunciation from it —
|
|
23
|
+
cannot work when two readings share a POS. `sede` thirst and seat are **both nouns**;
|
|
24
|
+
`corte` cut and court are both nominal; `forma` mould and shape likewise. A POS tagger
|
|
25
|
+
labels them identically and is wrong on the minority reading by construction. bifonia
|
|
26
|
+
keys every reading on **`sense`** (a meaning slug) and resolves the meaning directly.
|
|
27
|
+
|
|
28
|
+
## Two interchangeable engines
|
|
29
|
+
|
|
30
|
+
| engine | needs a corpus? | how it decides |
|
|
31
|
+
|--------|-----------------|----------------|
|
|
32
|
+
| **rules** | no | hand-written context rules + wordlists (`.voc`) |
|
|
33
|
+
| **learned** | yes | per-word Naive-Bayes / averaged-perceptron over context features |
|
|
34
|
+
|
|
35
|
+
The rule engine is self-contained and needs no training data — the right fit for a fork
|
|
36
|
+
of a low-resource language. The learned models are trained from the labelled corpus and
|
|
37
|
+
generalise better where enough data exists. `guess_sense` uses a **per-word ensemble**:
|
|
38
|
+
each word is served by whichever engine scores at least as well on held-out data, so the
|
|
39
|
+
combined system never does worse than the rules alone. Both are pure Python with no heavy
|
|
40
|
+
runtime dependencies.
|
|
41
|
+
|
|
42
|
+
The learned engine ships in two forms — a Naive-Bayes model and an averaged perceptron —
|
|
43
|
+
and `guess_sense` loads the **averaged perceptron** by default. The perceptron leads on both
|
|
44
|
+
the synthetic and the real-world benchmarks and avoids the per-word collapses that Naive-Bayes
|
|
45
|
+
suffers when correlated features violate its independence assumption; it is warm-started from
|
|
46
|
+
the Naive-Bayes log-odds, so its weights stay readable as per-sense lexicons. Load the other
|
|
47
|
+
model explicitly with `SenseModel.load(path)` if you want to compare.
|
|
48
|
+
|
|
49
|
+
## Accuracy
|
|
50
|
+
|
|
51
|
+
Sense prediction, measured two ways:
|
|
52
|
+
|
|
53
|
+
| approach | synthetic test | real-world (OOD) |
|
|
54
|
+
|----------|:--------------:|:----------------:|
|
|
55
|
+
| most-common baseline | 52.7% | 47.5% |
|
|
56
|
+
| spaCy POS → sense | 65.7% | 81.4% |
|
|
57
|
+
| Stanza POS → sense | 75.5% | 82.5% |
|
|
58
|
+
| rules (no corpus) | 94.5% | 84.6% |
|
|
59
|
+
| Naive-Bayes | 98.1% | 86.7% |
|
|
60
|
+
| averaged perceptron | 99.0% | 89.6% |
|
|
61
|
+
| **shipped ensemble** | **96.1%** | **90.5%** |
|
|
62
|
+
|
|
63
|
+
The *synthetic* column is the held-out split of the generated training corpus, balanced
|
|
64
|
+
across senses; the *OOD* column is real sentences from
|
|
65
|
+
[`bifonia-pt-homographs-wild`](https://huggingface.co/datasets/TigreGotico/bifonia-pt-homographs-wild).
|
|
66
|
+
The two columns answer different questions. The synthetic set is balanced, so it exposes
|
|
67
|
+
how badly POS tagging handles minority readings (a tagger cannot separate two senses that
|
|
68
|
+
share a part of speech — both score 0% on `sede`/thirst). Real text is skewed toward the
|
|
69
|
+
majority readings POS taggers do get right, which lifts them to ~82% — yet the
|
|
70
|
+
meaning-aware models still win, and the perceptron leads by ~7 points. Reproduce with
|
|
71
|
+
`python benchmark_tagger.py` (synthetic) and `python benchmark_ood.py` (OOD).
|
|
72
|
+
|
|
73
|
+
## Install
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pip install -e . --no-deps
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
No dependencies — pure standard library.
|
|
80
|
+
|
|
81
|
+
## API
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
from bifonia import (tokenize, is_ambiguous, guess_sense, guess_pos,
|
|
85
|
+
disambiguate, add_extra_diacritics)
|
|
86
|
+
|
|
87
|
+
sentence = "Resolveu o problema desta forma simples."
|
|
88
|
+
words = tokenize(sentence)
|
|
89
|
+
i = words.index("forma")
|
|
90
|
+
|
|
91
|
+
guess_sense(words, i) # 'shape'
|
|
92
|
+
guess_pos(words, i) # 'NOUN' (descriptive)
|
|
93
|
+
disambiguate(words, i) # 'ˈfɔɾmɐ'
|
|
94
|
+
disambiguate(words, i, sense="mould") # 'ˈfoɾmɐ' (override)
|
|
95
|
+
add_extra_diacritics(sentence) # '...desta fórma simples.' (acute = open vowel)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
`add_extra_diacritics` rewrites each homograph with a disambiguating diacritic
|
|
99
|
+
(acute → open vowel, circumflex → closed) that a downstream grapheme-to-phoneme stage
|
|
100
|
+
can read directly.
|
|
101
|
+
|
|
102
|
+
## Datasets
|
|
103
|
+
|
|
104
|
+
Both on the Hugging Face Hub, schema `{word, sense, pos, ipa, sentence}`:
|
|
105
|
+
|
|
106
|
+
- [`bifonia-pt-homographs`](https://huggingface.co/datasets/TigreGotico/bifonia-pt-homographs)
|
|
107
|
+
— 56,891 labelled sentences over 27 words, with stratified train/test splits, for
|
|
108
|
+
training and synthetic evaluation.
|
|
109
|
+
- [`bifonia-pt-homographs-wild`](https://huggingface.co/datasets/TigreGotico/bifonia-pt-homographs-wild)
|
|
110
|
+
— real Wikipedia and web sentences, an out-of-distribution test set.
|
|
111
|
+
|
|
112
|
+
## Word coverage
|
|
113
|
+
|
|
114
|
+
27 homographs: `acordo`, `acerto`, `cerro`, `choro`, `colher`, `começo`, `conserto`,
|
|
115
|
+
`coro`, `corte`, `forma`, `gosto`, `gozo`, `jogo`, `molho`, `olho`, `para`, `pelo`,
|
|
116
|
+
`peso`, `porto`, `posto`, `rego`, `seco`, `sede`, `sobre`, `tola`, `torre`, `transtorno`.
|
|
117
|
+
|
|
118
|
+
Per-word IPA, senses, and diacritized forms are in [`docs/words.md`](docs/words.md).
|
|
119
|
+
|
|
120
|
+
## Project layout
|
|
121
|
+
|
|
122
|
+
- `bifonia/data/corpus.jsonl` — the labelled corpus (single source of truth).
|
|
123
|
+
- `bifonia/data/heterophonic_homographs.csv` — the `word,sense,pos,ipa` table.
|
|
124
|
+
- `bifonia/data/sense_model_{nb,perceptron}.json` — trained models (JSON weights).
|
|
125
|
+
- `bifonia/locale/<lang>/*.voc` — context wordlists, one term per line, editable.
|
|
126
|
+
- `bifonia/features.py` — language-agnostic feature extraction (shared by train and inference).
|
|
127
|
+
|
|
128
|
+
Porting to a related language means supplying a corpus and `.voc` files and retraining —
|
|
129
|
+
the algorithm carries no hardcoded Portuguese.
|
|
130
|
+
|
|
131
|
+
## See also
|
|
132
|
+
|
|
133
|
+
- [`docs/methodology.md`](docs/methodology.md) — algorithm, features, and benchmarks
|
|
134
|
+
- [`docs/usage.md`](docs/usage.md) — full API reference
|
|
135
|
+
- [`docs/words.md`](docs/words.md) — per-word pronunciation notes
|
|
136
|
+
- [`docs/diacritics_restoration.md`](docs/diacritics_restoration.md) — the diacritics-restoration task
|
|
137
|
+
- [`examples/basic_usage.py`](examples/basic_usage.py) — runnable demo
|
|
138
|
+
- [`train.py`](train.py) · [`benchmark_tagger.py`](benchmark_tagger.py) · [`benchmark_ood.py`](benchmark_ood.py)
|