pt2mirandese 0.0.1a2__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.
@@ -0,0 +1,204 @@
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 2021 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.
203
+
204
+ =======================================================================
@@ -0,0 +1,125 @@
1
+ Metadata-Version: 2.4
2
+ Name: pt2mirandese
3
+ Version: 0.0.1a2
4
+ Summary: Rule-based translator from European Portuguese to Mirandese
5
+ Author-email: JarbasAi <jarbasai@mailfence.com>
6
+ License: Apache-2.0 AND CC-BY-SA-4.0
7
+ Project-URL: Homepage, https://github.com/TigreGotico/pt2mirandese
8
+ Project-URL: Repository, https://github.com/TigreGotico/pt2mirandese
9
+ Keywords: mirandese,mwl,portuguese,machine-translation,rule-based,minority-language
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: Apache Software License
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Topic :: Text Processing :: Linguistic
14
+ Requires-Python: >=3.11
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Provides-Extra: test
18
+ Requires-Dist: pytest; extra == "test"
19
+ Requires-Dist: pt2mirandese[eval]; extra == "test"
20
+ Provides-Extra: eval
21
+ Requires-Dist: sacrebleu; extra == "eval"
22
+ Dynamic: license-file
23
+
24
+ # pt2mirandese
25
+
26
+ `pt2mirandese` translates European Portuguese text into Mirandese with hand-written rules and word lists. It is a baseline for a language with few resources: it needs no model and no network.
27
+
28
+ Try it in the browser: [TigreGotico/pt2mirandese](https://huggingface.co/spaces/TigreGotico/pt2mirandese) on Hugging Face. The page runs this package with Pyodide; `space/` holds its source.
29
+
30
+ [Mirandese](https://en.wikipedia.org/wiki/Mirandese_language) (*lhéngua mirandesa*, ISO 639-3 `mwl`) is an Astur-Leonese language of the Terra de Miranda in north-east Portugal. It has fewer than 4,000 speakers and is co-official with Portuguese in its region. Its spelling follows the *Convenção Ortográfica da Língua Mirandesa* (1999).
31
+
32
+ ## Install and use
33
+
34
+ ```bash
35
+ uv pip install -e .
36
+ echo "O livro do meu pai está na mesa." | pt2mirandese
37
+ # L lhibro de l miu pai stá na mesa.
38
+ ```
39
+
40
+ ```python
41
+ from pt2mirandese import translate, word
42
+
43
+ translate("Ela foi com o irmão para a escola e começou a escrever um poema.")
44
+ # 'Eilha fui cul armano pa la scola i ampeçou a screbir un poema.'
45
+ word("história") # 'stória'
46
+ ```
47
+
48
+ `translate` takes one sentence or line and keeps template slots such as `{name}`. `word` converts one lowercase word with no context.
49
+
50
+ ## How it works
51
+
52
+ The translator works in three layers. A word goes to the first layer that has it.
53
+
54
+ Before the layers, `data/native.tsv` holds the corrections of a native speaker. They win over every other source. Some are false friends: Portuguese *brincar* is Mirandese *gaiar*, because Mirandese *brincar* means *saltar*. Portuguese *bolo* is *bolho*, because Mirandese *bolo* is *voo*. A verb row covers every form of the verb (*brincavam* > *gaiában*, *quebrou* > *scachou*).
55
+
56
+ 1. **Closed classes** come from the tables of the Convenção: articles (*l*, *la*, *ls*, *las*), contractions (*de l*, *al*, *cul*, *pa l*), pronouns, possessives, demonstratives, prepositions, adverbs and the present tense of the irregular verbs. Each group names its PDF page in the code.
57
+ 2. **Word lists.** `data/convencao.tsv` comes first: it holds 1,699 words that the Convenção prints, such as *scola*, *dixo* and *irie*, and its form wins over the corpus. Claude Opus 5.5 glossed each Mirandese word on each page into Portuguese, and a second pass checked each gloss against its page. A gloss stays only when the word is Mirandese, the gloss is right, and the Portuguese word has no other common sense that Mirandese writes differently: *verão* is summer as well as *beran*, they will see. `scripts/build_convencao.py` builds the list. `data/lexicon.tsv` holds 10,098 words whose Mirandese form the rules do not give, such as *tierra*, *muorte* and *anho*. `scripts/learn_lexicon.py` learns them from every parallel pair in `gold/`: 113,253 rows, of which 109,672 are different pairs. Where the writers disagree (*lhéngua* and *léngua*), the most frequent form wins. `data/lhenguabase.tsv` adds 296 words from the [Lhenguabase](https://lhenguabase.wikibase.cloud) that the parallel data does not check, such as *gabilanes* and *majaricones*. The Lhenguabase glosses a lemma, so Claude Opus 5.5 gave each Mirandese form the Portuguese word in the same gender and number. `data/wiktionary.tsv` adds 176 more from the Portuguese Wiktionary. A verb that a word list spells with another stem gives that stem to its other forms: *ficar* > *quedar*, so *ficaram* > *quedórun*. `data/verbs.tsv` keeps only the verbs whose forms the parallel data writes that way, because a vowel that changes only under stress does not carry (*buoltar*, but *boltou*). `scripts/build_verbs.py` builds it after each relearn.
58
+ 3. **Spelling rules** convert the rest. Among them: *v* > *b*, *-ção* > *-çon*, final *-z* > *-ç*, initial *es-* > *s-*, *en-*/*in-* > *an-*, pretonic *con-* > *cun-*, stressed final *-ia* > *-ie*, *-mento* > *-miento*, and the verb endings of the Convenção tables (*cantórun*, *cantában*, *comie*, *cantarie*, *canteste*, *cantáren*, *comisse*, *comíssen*). Where the parallel data writes an ending another way, the rules keep the Portuguese ending until a native speaker decides: *cantassen* or *cantássen*, *cantaríamos* or *cantariemos*.
59
+
60
+ Some rules need the words around a word. *muito* is *mui* before an adjective or an adverb (*mui grande*) and *muito* before a noun, a preposition or a pause (*gusto muito de ti*, *hai muito tiempo*), as a native speaker reports. *não* is *nun* before a verb and *nó* before a pause, Convenção p. 30: *el dixo que nó*. *a* is the article *la* except before an infinitive, a numeral or a pronoun. *la*, *l*, *de* and *que* elide before a vowel (*l'alma*, *d'outro*, *qu'el*). *nos* before the verb is the pronoun *mos*. A personal name takes no article: *falei com o Virgílio* > *falei cun Virgílio*, *a casa da Maria* > *la casa de Marie*. `data/names.txt` lists the given names from Wikidata. A name that the Portuguese side of the gold files writes after an article more often than after a bare preposition is a place, which keeps its article (*de la Ouropa*), and is left out. `scripts/build_names.py` builds the list. A given name in the list also keeps its spelling. Roman numerals, acronyms (*TV*), one-letter abbreviations (*a.C.*), web and e-mail addresses and template slots stay as they are.
61
+
62
+ The spelling follows the 2000 Adenda to the Convenção, which writes *ie*, *uo* and *ye* without the circumflex.
63
+
64
+ ## Evaluation
65
+
66
+ | Set | Rows | Copy the Portuguese: chrF2 | Rules alone: exact | Rules alone: chrF2 | pt2mirandese: exact | pt2mirandese: chrF2 |
67
+ | --- | ---: | ---: | ---: | ---: | ---: | ---: |
68
+ | `wikimedia_test.tsv` | 1,489 | 62.4 | 0.076 | 87.2 | 0.377 | 94.8 |
69
+ | `wikimedia_dev.tsv` | 493 | 62.0 | 0.093 | 86.7 | 0.379 | 94.3 |
70
+ | `wikipedia_mined.tsv` | 54,360 | 58.0 | 0.035 | 82.7 | 0.250 | 91.2 |
71
+ | `tatoeba.tsv` | 35 | 35.1 | 0.229 | 49.9 | 0.486 | 63.5 |
72
+ | `convencao.tsv` | 76 | 36.5 | 0.711 | 74.1 | 0.987 | 96.1 |
73
+
74
+ "Exact" accepts the reference or an alternative after lowercasing. chrF2 is corpus chrF from sacrebleu. "Rules alone" switches all the word lists off.
75
+
76
+ ```bash
77
+ uv run --with sacrebleu --with-editable . python scripts/evaluate.py gold/wikimedia_test.tsv --no-lexicon --errors 20
78
+ ```
79
+
80
+ **Rules alone is the score on unseen text.** The word lists learn from every file in `gold/`, the test files included, so the full pt2mirandese columns show how well the lists fit the data they come from. They are not a held-out score. Mirandese text is scarce, and the translator is meant to make synthetic training data for a later translation model, so it uses all the parallel text there is. The rules were tuned on `wikimedia_dev.tsv`, and the test split was read only after each round of tuning, so the rules-alone score on `wikimedia_test.tsv` is held out.
81
+
82
+ **Machine drafts are left out.** Content Translation offers MinT drafts for Portuguese to Mirandese since 2023. Of the 440 published translations, 414 date from 2017, before MinT. `scripts/fetch_cx.py` lists the 17 translations published since 2023 (`gold/cx_mint_era.tsv`), which Content Translation records as 34% to 59% machine text, and `scripts/make_gold.py` drops the 481 pairs that come from them. The older text still shows a mechanical habit of some translators: Roman *VI* written *BI* and *TV* written *TB* in 23 rows.
83
+
84
+ **One Portuguese side is machine translation.** `gold/wikipedia_backtranslated.tsv` pairs 51,045 Mirandese Wikipedia sentences with Portuguese from Claude Haiku 5.5. Its Mirandese side gives the word list real forms, but its Portuguese side is not a reference, so the table does not score it.
85
+
86
+ **Encyclopaedic text is most of the data.** Tatoeba holds everyday sentences by other writers, and there the translator scores 63.5: it misses everyday words (*teç* for *pele*, *Adius* for *Tchau*) and idioms.
87
+
88
+ **The corpus does not always follow the Convenção.** Where the two differ, the translator follows the Convenção, and loses exact matches against references that follow the corpus. On `wikimedia_dev.tsv` the printed words, *lh-* and proper names cost 41 of 493 rows together: 227 rows pass with the corpus forms, 186 with the Convenção forms.
89
+
90
+ - A word the Convenção prints takes that form (`data/convencao.tsv`): *scola*, where the corpus writes *scuola* 593 times.
91
+ - The Convenção (p. 15) asks for *lh-* in traditional words (*lhibro*, *lhéngua*, *lhuna*) and *l-* in neologisms, loanwords and proper names. The corpus mixes the two in both kinds of word, so its counts cannot tell them apart. `data/lh.tsv` lists the words that a curated source writes with *lh-*: the examples of the Convenção, the Portuguese Wiktionary and the [Lhenguabase](https://lhenguabase.wikibase.cloud). The translator writes *lh-* for those words and their verb forms, and *l-* for the rest (*lógica*, *laboratório*). `scripts/build_lh.py` builds the list.
92
+ - The corpus writes the object pronoun *nos* as *ne ls*. The translator writes *mos*, as the Convenção (p. 25) does, and so loses those rows.
93
+ - The Convenção (p. 17) lets proper names keep an official *V* (*Virgílio*). The corpus writes *Birgílio*. The translator keeps *V* and initial *l-* in a capitalised word inside a sentence, unless the word list has a Mirandese form for it (*Lisboua*) or the word is a common word in capitals (*Universidade*, *Revolução*). `data/common.txt` lists the common words: the words with a *v* or an initial *l* that the Portuguese side of the gold files writes in lowercase three times or more. `scripts/build_common.py` builds the list.
94
+
95
+ ## Other systems
96
+
97
+ The one other Portuguese to Mirandese system is MADLAD-400 3B (Google, Apache-2.0), which MinT, the Wikimedia translation service, serves for this pair. Apertium has no Mirandese pair. `scripts/baselines.py` runs the CTranslate2 build `santhosh/madlad400-3b-ct2` on the CPU in int8, with greedy decoding, and writes `bench/madlad/`.
98
+
99
+ | Set | MADLAD: exact | MADLAD: chrF2 | Rules alone: chrF2 | pt2mirandese: chrF2 |
100
+ | --- | ---: | ---: | ---: | ---: |
101
+ | `wikimedia_test.tsv` | 0.144 | 89.0 | 87.2 | 94.8 |
102
+ | `wikimedia_dev.tsv` | 0.114 | 88.4 | 86.7 | 94.3 |
103
+ | `tatoeba.tsv` | 0.029 | 48.0 | 49.9 | 63.5 |
104
+ | `convencao.tsv` | 0.276 | 55.9 | 74.1 | 96.1 |
105
+
106
+ ```bash
107
+ uv run --with sacrebleu --with-editable . python scripts/evaluate.py gold/wikimedia_test.tsv --hyps bench/madlad
108
+ ```
109
+
110
+ MADLAD learned from web text, which most likely includes the Mirandese Wikipedia, so its wikimedia scores are not held out either. On the everyday Tatoeba sentences it often copies the Portuguese (*Adeus*, *Vamos*) or loses the sense: *Olho por olho, dente por dente* becomes *L'ouro ye l dendro*.
111
+
112
+ ## Sources
113
+
114
+ - *Convenção Ortográfica da Língua Mirandesa* (1999). Câmara Municipal de Miranda do Douro and Centro de Linguística da Universidade de Lisboa.
115
+ - Ferreira, M. B. (2003). "Resposta a uma recensão crítica da Convenção Ortográfica da Língua Mirandesa". *Revista de Filoloxía Asturiana* 3-4, 327-343. It states what the 2000 Adenda changed.
116
+ - OPUS wikimedia mwl-pt, release v20260327 (CC-BY-SA 4.0). J. Tiedemann (2012), "Parallel Data, Tools and Interfaces in OPUS", LREC.
117
+ - Portuguese and Mirandese Wikipedia (CC-BY-SA 4.0), for the mined and back-translated pairs.
118
+ - Wiktionary, Portuguese edition, Mirandese entries (CC-BY-SA 4.0).
119
+ - Lhenguabase, the Mirandese lexical database on Wikibase Cloud (CC-BY-SA 4.0). `scripts/fetch_lhenguabase.py` downloads it.
120
+ - Tatoeba (CC-BY 2.0 FR).
121
+ - Wikidata (CC0), for the given names.
122
+
123
+ ## Licence
124
+
125
+ The code is Apache-2.0. The word lists in `pt2mirandese/data/` and the Wikipedia gold files are derived from CC-BY-SA 4.0 sources and are CC-BY-SA 4.0. `gold/tatoeba.tsv` is CC-BY 2.0 FR.
@@ -0,0 +1,102 @@
1
+ # pt2mirandese
2
+
3
+ `pt2mirandese` translates European Portuguese text into Mirandese with hand-written rules and word lists. It is a baseline for a language with few resources: it needs no model and no network.
4
+
5
+ Try it in the browser: [TigreGotico/pt2mirandese](https://huggingface.co/spaces/TigreGotico/pt2mirandese) on Hugging Face. The page runs this package with Pyodide; `space/` holds its source.
6
+
7
+ [Mirandese](https://en.wikipedia.org/wiki/Mirandese_language) (*lhéngua mirandesa*, ISO 639-3 `mwl`) is an Astur-Leonese language of the Terra de Miranda in north-east Portugal. It has fewer than 4,000 speakers and is co-official with Portuguese in its region. Its spelling follows the *Convenção Ortográfica da Língua Mirandesa* (1999).
8
+
9
+ ## Install and use
10
+
11
+ ```bash
12
+ uv pip install -e .
13
+ echo "O livro do meu pai está na mesa." | pt2mirandese
14
+ # L lhibro de l miu pai stá na mesa.
15
+ ```
16
+
17
+ ```python
18
+ from pt2mirandese import translate, word
19
+
20
+ translate("Ela foi com o irmão para a escola e começou a escrever um poema.")
21
+ # 'Eilha fui cul armano pa la scola i ampeçou a screbir un poema.'
22
+ word("história") # 'stória'
23
+ ```
24
+
25
+ `translate` takes one sentence or line and keeps template slots such as `{name}`. `word` converts one lowercase word with no context.
26
+
27
+ ## How it works
28
+
29
+ The translator works in three layers. A word goes to the first layer that has it.
30
+
31
+ Before the layers, `data/native.tsv` holds the corrections of a native speaker. They win over every other source. Some are false friends: Portuguese *brincar* is Mirandese *gaiar*, because Mirandese *brincar* means *saltar*. Portuguese *bolo* is *bolho*, because Mirandese *bolo* is *voo*. A verb row covers every form of the verb (*brincavam* > *gaiában*, *quebrou* > *scachou*).
32
+
33
+ 1. **Closed classes** come from the tables of the Convenção: articles (*l*, *la*, *ls*, *las*), contractions (*de l*, *al*, *cul*, *pa l*), pronouns, possessives, demonstratives, prepositions, adverbs and the present tense of the irregular verbs. Each group names its PDF page in the code.
34
+ 2. **Word lists.** `data/convencao.tsv` comes first: it holds 1,699 words that the Convenção prints, such as *scola*, *dixo* and *irie*, and its form wins over the corpus. Claude Opus 5.5 glossed each Mirandese word on each page into Portuguese, and a second pass checked each gloss against its page. A gloss stays only when the word is Mirandese, the gloss is right, and the Portuguese word has no other common sense that Mirandese writes differently: *verão* is summer as well as *beran*, they will see. `scripts/build_convencao.py` builds the list. `data/lexicon.tsv` holds 10,098 words whose Mirandese form the rules do not give, such as *tierra*, *muorte* and *anho*. `scripts/learn_lexicon.py` learns them from every parallel pair in `gold/`: 113,253 rows, of which 109,672 are different pairs. Where the writers disagree (*lhéngua* and *léngua*), the most frequent form wins. `data/lhenguabase.tsv` adds 296 words from the [Lhenguabase](https://lhenguabase.wikibase.cloud) that the parallel data does not check, such as *gabilanes* and *majaricones*. The Lhenguabase glosses a lemma, so Claude Opus 5.5 gave each Mirandese form the Portuguese word in the same gender and number. `data/wiktionary.tsv` adds 176 more from the Portuguese Wiktionary. A verb that a word list spells with another stem gives that stem to its other forms: *ficar* > *quedar*, so *ficaram* > *quedórun*. `data/verbs.tsv` keeps only the verbs whose forms the parallel data writes that way, because a vowel that changes only under stress does not carry (*buoltar*, but *boltou*). `scripts/build_verbs.py` builds it after each relearn.
35
+ 3. **Spelling rules** convert the rest. Among them: *v* > *b*, *-ção* > *-çon*, final *-z* > *-ç*, initial *es-* > *s-*, *en-*/*in-* > *an-*, pretonic *con-* > *cun-*, stressed final *-ia* > *-ie*, *-mento* > *-miento*, and the verb endings of the Convenção tables (*cantórun*, *cantában*, *comie*, *cantarie*, *canteste*, *cantáren*, *comisse*, *comíssen*). Where the parallel data writes an ending another way, the rules keep the Portuguese ending until a native speaker decides: *cantassen* or *cantássen*, *cantaríamos* or *cantariemos*.
36
+
37
+ Some rules need the words around a word. *muito* is *mui* before an adjective or an adverb (*mui grande*) and *muito* before a noun, a preposition or a pause (*gusto muito de ti*, *hai muito tiempo*), as a native speaker reports. *não* is *nun* before a verb and *nó* before a pause, Convenção p. 30: *el dixo que nó*. *a* is the article *la* except before an infinitive, a numeral or a pronoun. *la*, *l*, *de* and *que* elide before a vowel (*l'alma*, *d'outro*, *qu'el*). *nos* before the verb is the pronoun *mos*. A personal name takes no article: *falei com o Virgílio* > *falei cun Virgílio*, *a casa da Maria* > *la casa de Marie*. `data/names.txt` lists the given names from Wikidata. A name that the Portuguese side of the gold files writes after an article more often than after a bare preposition is a place, which keeps its article (*de la Ouropa*), and is left out. `scripts/build_names.py` builds the list. A given name in the list also keeps its spelling. Roman numerals, acronyms (*TV*), one-letter abbreviations (*a.C.*), web and e-mail addresses and template slots stay as they are.
38
+
39
+ The spelling follows the 2000 Adenda to the Convenção, which writes *ie*, *uo* and *ye* without the circumflex.
40
+
41
+ ## Evaluation
42
+
43
+ | Set | Rows | Copy the Portuguese: chrF2 | Rules alone: exact | Rules alone: chrF2 | pt2mirandese: exact | pt2mirandese: chrF2 |
44
+ | --- | ---: | ---: | ---: | ---: | ---: | ---: |
45
+ | `wikimedia_test.tsv` | 1,489 | 62.4 | 0.076 | 87.2 | 0.377 | 94.8 |
46
+ | `wikimedia_dev.tsv` | 493 | 62.0 | 0.093 | 86.7 | 0.379 | 94.3 |
47
+ | `wikipedia_mined.tsv` | 54,360 | 58.0 | 0.035 | 82.7 | 0.250 | 91.2 |
48
+ | `tatoeba.tsv` | 35 | 35.1 | 0.229 | 49.9 | 0.486 | 63.5 |
49
+ | `convencao.tsv` | 76 | 36.5 | 0.711 | 74.1 | 0.987 | 96.1 |
50
+
51
+ "Exact" accepts the reference or an alternative after lowercasing. chrF2 is corpus chrF from sacrebleu. "Rules alone" switches all the word lists off.
52
+
53
+ ```bash
54
+ uv run --with sacrebleu --with-editable . python scripts/evaluate.py gold/wikimedia_test.tsv --no-lexicon --errors 20
55
+ ```
56
+
57
+ **Rules alone is the score on unseen text.** The word lists learn from every file in `gold/`, the test files included, so the full pt2mirandese columns show how well the lists fit the data they come from. They are not a held-out score. Mirandese text is scarce, and the translator is meant to make synthetic training data for a later translation model, so it uses all the parallel text there is. The rules were tuned on `wikimedia_dev.tsv`, and the test split was read only after each round of tuning, so the rules-alone score on `wikimedia_test.tsv` is held out.
58
+
59
+ **Machine drafts are left out.** Content Translation offers MinT drafts for Portuguese to Mirandese since 2023. Of the 440 published translations, 414 date from 2017, before MinT. `scripts/fetch_cx.py` lists the 17 translations published since 2023 (`gold/cx_mint_era.tsv`), which Content Translation records as 34% to 59% machine text, and `scripts/make_gold.py` drops the 481 pairs that come from them. The older text still shows a mechanical habit of some translators: Roman *VI* written *BI* and *TV* written *TB* in 23 rows.
60
+
61
+ **One Portuguese side is machine translation.** `gold/wikipedia_backtranslated.tsv` pairs 51,045 Mirandese Wikipedia sentences with Portuguese from Claude Haiku 5.5. Its Mirandese side gives the word list real forms, but its Portuguese side is not a reference, so the table does not score it.
62
+
63
+ **Encyclopaedic text is most of the data.** Tatoeba holds everyday sentences by other writers, and there the translator scores 63.5: it misses everyday words (*teç* for *pele*, *Adius* for *Tchau*) and idioms.
64
+
65
+ **The corpus does not always follow the Convenção.** Where the two differ, the translator follows the Convenção, and loses exact matches against references that follow the corpus. On `wikimedia_dev.tsv` the printed words, *lh-* and proper names cost 41 of 493 rows together: 227 rows pass with the corpus forms, 186 with the Convenção forms.
66
+
67
+ - A word the Convenção prints takes that form (`data/convencao.tsv`): *scola*, where the corpus writes *scuola* 593 times.
68
+ - The Convenção (p. 15) asks for *lh-* in traditional words (*lhibro*, *lhéngua*, *lhuna*) and *l-* in neologisms, loanwords and proper names. The corpus mixes the two in both kinds of word, so its counts cannot tell them apart. `data/lh.tsv` lists the words that a curated source writes with *lh-*: the examples of the Convenção, the Portuguese Wiktionary and the [Lhenguabase](https://lhenguabase.wikibase.cloud). The translator writes *lh-* for those words and their verb forms, and *l-* for the rest (*lógica*, *laboratório*). `scripts/build_lh.py` builds the list.
69
+ - The corpus writes the object pronoun *nos* as *ne ls*. The translator writes *mos*, as the Convenção (p. 25) does, and so loses those rows.
70
+ - The Convenção (p. 17) lets proper names keep an official *V* (*Virgílio*). The corpus writes *Birgílio*. The translator keeps *V* and initial *l-* in a capitalised word inside a sentence, unless the word list has a Mirandese form for it (*Lisboua*) or the word is a common word in capitals (*Universidade*, *Revolução*). `data/common.txt` lists the common words: the words with a *v* or an initial *l* that the Portuguese side of the gold files writes in lowercase three times or more. `scripts/build_common.py` builds the list.
71
+
72
+ ## Other systems
73
+
74
+ The one other Portuguese to Mirandese system is MADLAD-400 3B (Google, Apache-2.0), which MinT, the Wikimedia translation service, serves for this pair. Apertium has no Mirandese pair. `scripts/baselines.py` runs the CTranslate2 build `santhosh/madlad400-3b-ct2` on the CPU in int8, with greedy decoding, and writes `bench/madlad/`.
75
+
76
+ | Set | MADLAD: exact | MADLAD: chrF2 | Rules alone: chrF2 | pt2mirandese: chrF2 |
77
+ | --- | ---: | ---: | ---: | ---: |
78
+ | `wikimedia_test.tsv` | 0.144 | 89.0 | 87.2 | 94.8 |
79
+ | `wikimedia_dev.tsv` | 0.114 | 88.4 | 86.7 | 94.3 |
80
+ | `tatoeba.tsv` | 0.029 | 48.0 | 49.9 | 63.5 |
81
+ | `convencao.tsv` | 0.276 | 55.9 | 74.1 | 96.1 |
82
+
83
+ ```bash
84
+ uv run --with sacrebleu --with-editable . python scripts/evaluate.py gold/wikimedia_test.tsv --hyps bench/madlad
85
+ ```
86
+
87
+ MADLAD learned from web text, which most likely includes the Mirandese Wikipedia, so its wikimedia scores are not held out either. On the everyday Tatoeba sentences it often copies the Portuguese (*Adeus*, *Vamos*) or loses the sense: *Olho por olho, dente por dente* becomes *L'ouro ye l dendro*.
88
+
89
+ ## Sources
90
+
91
+ - *Convenção Ortográfica da Língua Mirandesa* (1999). Câmara Municipal de Miranda do Douro and Centro de Linguística da Universidade de Lisboa.
92
+ - Ferreira, M. B. (2003). "Resposta a uma recensão crítica da Convenção Ortográfica da Língua Mirandesa". *Revista de Filoloxía Asturiana* 3-4, 327-343. It states what the 2000 Adenda changed.
93
+ - OPUS wikimedia mwl-pt, release v20260327 (CC-BY-SA 4.0). J. Tiedemann (2012), "Parallel Data, Tools and Interfaces in OPUS", LREC.
94
+ - Portuguese and Mirandese Wikipedia (CC-BY-SA 4.0), for the mined and back-translated pairs.
95
+ - Wiktionary, Portuguese edition, Mirandese entries (CC-BY-SA 4.0).
96
+ - Lhenguabase, the Mirandese lexical database on Wikibase Cloud (CC-BY-SA 4.0). `scripts/fetch_lhenguabase.py` downloads it.
97
+ - Tatoeba (CC-BY 2.0 FR).
98
+ - Wikidata (CC0), for the given names.
99
+
100
+ ## Licence
101
+
102
+ The code is Apache-2.0. The word lists in `pt2mirandese/data/` and the Wikipedia gold files are derived from CC-BY-SA 4.0 sources and are CC-BY-SA 4.0. `gold/tatoeba.tsv` is CC-BY 2.0 FR.