ablt 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ablt-2.0.0/LICENSE +194 -0
- ablt-2.0.0/NOTICE +44 -0
- ablt-2.0.0/PKG-INFO +149 -0
- ablt-2.0.0/README.md +129 -0
- ablt-2.0.0/pyproject.toml +32 -0
- ablt-2.0.0/setup.cfg +4 -0
- ablt-2.0.0/src/ablt/__init__.py +13 -0
- ablt-2.0.0/src/ablt/cli.py +59 -0
- ablt-2.0.0/src/ablt/models/README.txt +4 -0
- ablt-2.0.0/src/ablt/models/SHA256SUMS +2 -0
- ablt-2.0.0/src/ablt/models/ablt-luganda-v2.joiners.json +982 -0
- ablt-2.0.0/src/ablt/models/ablt-luganda-v2.model +0 -0
- ablt-2.0.0/src/ablt/rules.py +90 -0
- ablt-2.0.0/src/ablt/segmenter.py +78 -0
- ablt-2.0.0/src/ablt/tokenizer.py +139 -0
- ablt-2.0.0/src/ablt.egg-info/PKG-INFO +149 -0
- ablt-2.0.0/src/ablt.egg-info/SOURCES.txt +20 -0
- ablt-2.0.0/src/ablt.egg-info/dependency_links.txt +1 -0
- ablt-2.0.0/src/ablt.egg-info/entry_points.txt +2 -0
- ablt-2.0.0/src/ablt.egg-info/requires.txt +1 -0
- ablt-2.0.0/src/ablt.egg-info/top_level.txt +1 -0
- ablt-2.0.0/tests/test_ablt.py +117 -0
ablt-2.0.0/LICENSE
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2025 Mathew Sekanjako and Psalms23Wave LLC.
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
you may not use this file except in compliance with the License.
|
|
9
|
+
You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
See the License for the specific language governing permissions and
|
|
17
|
+
limitations under the License.
|
|
18
|
+
|
|
19
|
+
-------------------------------------------------------------------------------
|
|
20
|
+
|
|
21
|
+
APACHE LICENSE, VERSION 2.0 (FULL TEXT)
|
|
22
|
+
|
|
23
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
24
|
+
|
|
25
|
+
1. Definitions.
|
|
26
|
+
|
|
27
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
28
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
29
|
+
|
|
30
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
31
|
+
the copyright owner that is granting the License.
|
|
32
|
+
|
|
33
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
34
|
+
other entities that control, are controlled by, or are under common
|
|
35
|
+
control with that entity. For the purposes of this definition,
|
|
36
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
37
|
+
direction or management of such entity, whether by contract or
|
|
38
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
39
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
40
|
+
|
|
41
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
42
|
+
exercising permissions granted by this License.
|
|
43
|
+
|
|
44
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
45
|
+
including but not limited to software source code, documentation
|
|
46
|
+
source, and configuration files.
|
|
47
|
+
|
|
48
|
+
"Object" form shall mean any form resulting from mechanical
|
|
49
|
+
transformation or translation of a Source form, including but
|
|
50
|
+
not limited to compiled object code, generated documentation,
|
|
51
|
+
and conversions to other media types.
|
|
52
|
+
|
|
53
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
54
|
+
Object form, made available under the License, as indicated by a
|
|
55
|
+
copyright notice that is included in or attached to the work
|
|
56
|
+
(an example is provided in the Appendix below).
|
|
57
|
+
|
|
58
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
59
|
+
form, that is based on (or derived from) the Work and for which the
|
|
60
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
61
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
62
|
+
of this License, Derivative Works shall not include works that remain
|
|
63
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
64
|
+
the Work and Derivative Works thereof.
|
|
65
|
+
|
|
66
|
+
"Contribution" shall mean any work of authorship, including
|
|
67
|
+
the original version of the Work and any modifications or additions
|
|
68
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
69
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
70
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
71
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
72
|
+
means any form of electronic, verbal, or written communication sent
|
|
73
|
+
to the Licensor or its representatives, including but not limited to
|
|
74
|
+
communication on electronic mailing lists, source code control systems,
|
|
75
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
76
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
77
|
+
excluding communication that is conspicuously marked or otherwise
|
|
78
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
79
|
+
|
|
80
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
81
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
82
|
+
subsequently incorporated within the Work.
|
|
83
|
+
|
|
84
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
85
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
86
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
87
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
88
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
89
|
+
Work and such Derivative Works in Source or Object form.
|
|
90
|
+
|
|
91
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
92
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
93
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
94
|
+
(except as stated in this section) patent license to make, have made,
|
|
95
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
96
|
+
where such license applies only to those patent claims licensable
|
|
97
|
+
by such Contributor that are necessarily infringed by their
|
|
98
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
99
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
100
|
+
institute patent litigation against any entity (including a
|
|
101
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
102
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
103
|
+
or contributory patent infringement, then any patent licenses
|
|
104
|
+
granted to You under this License for that Work shall terminate
|
|
105
|
+
as of the date such litigation is filed.
|
|
106
|
+
|
|
107
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
108
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
109
|
+
modifications, and in Source or Object form, provided that You
|
|
110
|
+
meet the following conditions:
|
|
111
|
+
|
|
112
|
+
(a) You must give any other recipients of the Work or
|
|
113
|
+
Derivative Works a copy of this License; and
|
|
114
|
+
|
|
115
|
+
(b) You must cause any modified files to carry prominent notices
|
|
116
|
+
stating that You changed the files; and
|
|
117
|
+
|
|
118
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
119
|
+
that You distribute, all copyright, patent, trademark, and
|
|
120
|
+
attribution notices from the Source form of the Work,
|
|
121
|
+
excluding those notices that do not pertain to any part of
|
|
122
|
+
the Derivative Works; and
|
|
123
|
+
|
|
124
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
125
|
+
distribution, then any Derivative Works that You distribute must
|
|
126
|
+
include a readable copy of the attribution notices contained
|
|
127
|
+
within such NOTICE file, excluding those notices that do not
|
|
128
|
+
pertain to any part of the Derivative Works, in at least one
|
|
129
|
+
of the following places: within a NOTICE text file distributed
|
|
130
|
+
as part of the Derivative Works; within the Source form or
|
|
131
|
+
documentation, if provided along with the Derivative Works; or,
|
|
132
|
+
within a display generated by the Derivative Works, if and
|
|
133
|
+
wherever such third-party notices normally appear. The contents
|
|
134
|
+
of the NOTICE file are for informational purposes only and
|
|
135
|
+
do not modify the License. You may add Your own attribution
|
|
136
|
+
notices within Derivative Works that You distribute, alongside
|
|
137
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
138
|
+
that such additional attribution notices cannot be construed
|
|
139
|
+
as modifying the License.
|
|
140
|
+
|
|
141
|
+
You may add Your own copyright statement to Your modifications and
|
|
142
|
+
may provide additional or different license terms and conditions
|
|
143
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
144
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
145
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
146
|
+
the conditions stated in this License.
|
|
147
|
+
|
|
148
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
149
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
150
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
151
|
+
this License, without any additional terms or conditions.
|
|
152
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
153
|
+
the terms of any separate license agreement you may have executed
|
|
154
|
+
with Licensor regarding such Contributions.
|
|
155
|
+
|
|
156
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
157
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
158
|
+
except as required for describing the origin of the Work and
|
|
159
|
+
reproducing the content of the NOTICE file.
|
|
160
|
+
|
|
161
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
162
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
163
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
164
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
165
|
+
implied, including, without limitation, any warranties or conditions
|
|
166
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
167
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
168
|
+
appropriateness of using or redistributing the Work and assume any
|
|
169
|
+
risks associated with Your exercise of permissions under this License.
|
|
170
|
+
|
|
171
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
172
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
173
|
+
unless required by applicable law (such as deliberate and grossly
|
|
174
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
175
|
+
liable to You for damages, including any direct, indirect, special,
|
|
176
|
+
incidental, or consequential damages of any character arising as a
|
|
177
|
+
result of this License or out of the use or inability to use the
|
|
178
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
179
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
180
|
+
other commercial damages or losses), even if such Contributor
|
|
181
|
+
has been advised of the possibility of such damages.
|
|
182
|
+
|
|
183
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
184
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
185
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
186
|
+
or other liability obligations and/or rights consistent with this
|
|
187
|
+
License. However, in accepting such obligations, You may act only
|
|
188
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
189
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
190
|
+
defend, and hold each Contributor harmless for any liability
|
|
191
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
192
|
+
of your accepting any such warranty or additional liability.
|
|
193
|
+
|
|
194
|
+
END OF TERMS AND CONDITIONS
|
ablt-2.0.0/NOTICE
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
ABLT (Alkebulan Bantu-Luganda Tokenizer), part of Alkebulan AI
|
|
2
|
+
Copyright (c) 2025-2026 Mathew Sekanjako and Psalms23Wave LLC.
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
-------------------------------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
ATTRIBUTION NOTICE (required by Apache License 2.0 §4(d))
|
|
13
|
+
|
|
14
|
+
This software and all derivative works must preserve the following attribution:
|
|
15
|
+
|
|
16
|
+
"Built on Alkebulan AI / ABLT / Sekan,
|
|
17
|
+
originally invented and developed by Mathew Sekanjako
|
|
18
|
+
(https://www.psalms23wave.com), released through Psalms23Wave LLC."
|
|
19
|
+
|
|
20
|
+
The ABLT (Alkebulan Bantu-Luganda Tokenizer) architecture, a two-stage
|
|
21
|
+
morphologically-aware tokenizer combining a language-specific symbolic
|
|
22
|
+
layer with a universal SentencePiece Unigram sub-word model, was
|
|
23
|
+
designed by Mathew Sekanjako in 2025 as part of the Alkebulan AI research
|
|
24
|
+
programme. Version 2 (2026) is by the same author.
|
|
25
|
+
|
|
26
|
+
Author: Mathew Sekanjako, https://www.sekanjakomathew.com
|
|
27
|
+
|
|
28
|
+
-------------------------------------------------------------------------------
|
|
29
|
+
|
|
30
|
+
TRADEMARK NOTICE
|
|
31
|
+
|
|
32
|
+
"Alkebulan AI", "ABLT", "Alkebulan Bantu Language Tokenizer", and "Sekan"
|
|
33
|
+
are trademarks of Psalms23Wave LLC. The Apache 2.0 license does NOT grant
|
|
34
|
+
rights to use these marks. See TRADEMARK.md in the Alkebulan AI repository
|
|
35
|
+
for permitted uses.
|
|
36
|
+
|
|
37
|
+
-------------------------------------------------------------------------------
|
|
38
|
+
|
|
39
|
+
THIRD-PARTY COMPONENTS AND DATA
|
|
40
|
+
|
|
41
|
+
* SentencePiece (Apache-2.0), https://github.com/google/sentencepiece
|
|
42
|
+
|
|
43
|
+
The bundled model was trained on Luganda text that includes the SALT dataset
|
|
44
|
+
by Sunbird AI, which is licensed under CC BY-SA 4.0.
|
ablt-2.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ablt
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: ABLT: a grammar-first tokenizer for Luganda and other Bantu languages
|
|
5
|
+
Author: Mathew Sekanjako
|
|
6
|
+
Maintainer: Psalms23Wave LLC
|
|
7
|
+
License-Expression: Apache-2.0
|
|
8
|
+
Project-URL: Repository, https://github.com/Psalms23Wave/AlkebulanAI
|
|
9
|
+
Project-URL: Author, https://www.sekanjakomathew.com
|
|
10
|
+
Project-URL: LinkedIn, https://www.linkedin.com/in/sekanjako-mathew/
|
|
11
|
+
Project-URL: Company, https://www.psalms23wave.com
|
|
12
|
+
Project-URL: Contact, https://www.psalms23wave.com/contact
|
|
13
|
+
Keywords: tokenizer,Luganda,Bantu,African languages,NLP,morphology,SentencePiece
|
|
14
|
+
Requires-Python: >=3.9
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
License-File: NOTICE
|
|
18
|
+
Requires-Dist: sentencepiece>=0.2.0
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# ABLT
|
|
22
|
+
|
|
23
|
+
**Alkebulan Bantu-Luganda Tokenizer, version 2.** A tokenizer for Luganda that cuts words
|
|
24
|
+
where their meaning changes, using the grammar of the language, before a statistical
|
|
25
|
+
tokenizer (SentencePiece) takes over.
|
|
26
|
+
|
|
27
|
+
Built by Mathew Sekanjako ([sekanjakomathew.com](https://www.sekanjakomathew.com),
|
|
28
|
+
[LinkedIn](https://www.linkedin.com/in/sekanjako-mathew/)), Psalms23Wave LLC, as part of
|
|
29
|
+
Alkebulan AI.
|
|
30
|
+
|
|
31
|
+
## Install
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install "git+https://github.com/Psalms23Wave/AlkebulanAI#subdirectory=packages/ablt"
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
It needs only `sentencepiece`. The trained Luganda model is inside the package.
|
|
38
|
+
|
|
39
|
+
## Use
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
from ablt import ABLT
|
|
43
|
+
|
|
44
|
+
tokenizer = ABLT()
|
|
45
|
+
|
|
46
|
+
tokenizer.tokenize("Abantu basoma ebitabo.")
|
|
47
|
+
# ['▁Abaǀ', '▁ntu', '▁baǀ', '▁soma', '▁ebiǀ', '▁tabo', '.']
|
|
48
|
+
|
|
49
|
+
ids = tokenizer.encode("Abantu basoma ebitabo.")
|
|
50
|
+
tokenizer.decode(ids)
|
|
51
|
+
# 'Abantu basoma ebitabo.' (exactly the text that went in)
|
|
52
|
+
|
|
53
|
+
tokenizer.show_cuts("okusoma ebitabo")
|
|
54
|
+
# 'oku|soma ebi|tabo'
|
|
55
|
+
|
|
56
|
+
tokenizer.morphemes("okusoma")
|
|
57
|
+
# ['oku', 'soma']
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### From the terminal, with no Python to write
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
ablt "Abantu baagala okusoma ebitabo."
|
|
64
|
+
# ▁Abaǀ ▁ntu ▁baǀ ▁agala ▁okuǀ ▁soma ▁ebiǀ ▁tabo .
|
|
65
|
+
|
|
66
|
+
ablt --cuts "Abantu baagala okusoma ebitabo."
|
|
67
|
+
# Aba|ntu ba|agala oku|soma ebi|tabo.
|
|
68
|
+
|
|
69
|
+
ablt --ids "Abantu baagala okusoma ebitabo." # piece numbers
|
|
70
|
+
ablt < story.txt # a whole file, line by line
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Reading the pieces
|
|
74
|
+
|
|
75
|
+
- A piece that starts with `▁` begins a new word.
|
|
76
|
+
- A piece that ends with `ǀ` is joined to the piece after it. `▁abaǀ` followed by `▁ntu` is
|
|
77
|
+
the single word `abantu`.
|
|
78
|
+
- A root is the same piece wherever it appears. `▁ntu` is the same piece in `abantu`,
|
|
79
|
+
`omuntu` and `ekintu`, and `▁soma` is the same piece in `okusoma` and `basoma`, so a model
|
|
80
|
+
learns each root once.
|
|
81
|
+
|
|
82
|
+
## What was measured
|
|
83
|
+
|
|
84
|
+
Run `python packages/ablt/tools/evaluate.py` to reproduce these.
|
|
85
|
+
|
|
86
|
+
| Test | ABLT version 2 | Plain SentencePiece trained on the same text, same size |
|
|
87
|
+
|---|---|---|
|
|
88
|
+
| Cuts fall on grammar boundaries, 83 Luganda words (F1) | 91.7% | 41.3% |
|
|
89
|
+
| The same words written with a capital letter | 93.3% | 72.7% |
|
|
90
|
+
| Words cut fully correctly | 86.7% | 18.1% |
|
|
91
|
+
| Pieces per word, 7,060 sentences of MasakhaNER 2.0 Luganda | 2.20 | 1.94 |
|
|
92
|
+
| Decoding gives back the exact text, 13,542 sentences | 13,542 of 13,542 | |
|
|
93
|
+
|
|
94
|
+
The plain tokenizer is a check built for this comparison: it is trained on the same text
|
|
95
|
+
with the same settings and has no grammar rules. It makes fewer pieces because it leaves
|
|
96
|
+
most words whole. ABLT cuts on purpose, at the grammar.
|
|
97
|
+
|
|
98
|
+
On the same MasakhaNER sentences, the tokenizers of two general models make 2.69 pieces per
|
|
99
|
+
word (Qwen2.5) and 2.89 (GPT-2).
|
|
100
|
+
|
|
101
|
+
## What changed from version 1
|
|
102
|
+
|
|
103
|
+
| | Version 1 | Version 2 |
|
|
104
|
+
|---|---|---|
|
|
105
|
+
| Decoding gives back the exact text | about 3% of sentences | every sentence tested |
|
|
106
|
+
| Words that start with a capital letter | not cut | cut like any other word |
|
|
107
|
+
| Names and acronyms in the middle of a sentence | cut by the rules | left whole |
|
|
108
|
+
| Forced short pieces | yes, 3.82 pieces per word | none, 2.20 pieces per word |
|
|
109
|
+
| A root after a prefix | a different piece from the root alone | the same piece |
|
|
110
|
+
| Text is rewritten before tokenizing | yes (spaces added round punctuation) | no |
|
|
111
|
+
|
|
112
|
+
The grammar rules themselves are the version 1 rules, unchanged: the longest noun-class
|
|
113
|
+
prefix, otherwise the longest verb extension. Each word is cut in at most one place.
|
|
114
|
+
|
|
115
|
+
## Limits
|
|
116
|
+
|
|
117
|
+
- The answer key has 83 words. It needs checking and extending by Luganda speakers.
|
|
118
|
+
- Each word is cut once. `alisoma` becomes `ali|soma`, where a full analysis is
|
|
119
|
+
`a|li|soma`.
|
|
120
|
+
- A name at the very start of a sentence is treated as an ordinary word and may be cut.
|
|
121
|
+
- It has been tested on Luganda only. Other Bantu languages need their own rule tables.
|
|
122
|
+
- It is shown to cut words at grammar boundaries. Whether that makes a trained model learn
|
|
123
|
+
better, or from less text, has not been tested yet.
|
|
124
|
+
|
|
125
|
+
## Training text and credit
|
|
126
|
+
|
|
127
|
+
The bundled model was trained on 58,346 unique lines of Luganda text (see `DATA.md` in the
|
|
128
|
+
Alkebulan AI repository). Most of that text comes from the SALT dataset by Sunbird AI,
|
|
129
|
+
released under CC BY-SA 4.0. One line in ten was held back and used only for testing.
|
|
130
|
+
|
|
131
|
+
## Rebuilding the model
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
python packages/ablt/tools/train_model.py # trains and writes the bundled model
|
|
135
|
+
python packages/ablt/tools/evaluate.py # prints the table above
|
|
136
|
+
python -m pytest packages/ablt/tests -q
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Licence and credit
|
|
140
|
+
|
|
141
|
+
Copyright 2025-2026 Mathew Sekanjako and Psalms23Wave LLC. Licensed under the Apache License,
|
|
142
|
+
version 2.0 (see `LICENSE`). Anyone who shares this work, changed or unchanged, must keep the
|
|
143
|
+
copyright notices and the `NOTICE` file, and must say what they changed.
|
|
144
|
+
|
|
145
|
+
ABLT™, Sekan™ and Alkebulan AI™ are trademarks of Psalms23Wave LLC. The licence does not
|
|
146
|
+
give permission to use these names for other products. The project's full terms are in
|
|
147
|
+
`LICENSING.md`, `TRADEMARK.md` and `COMMERCIAL.md` in the Alkebulan AI repository.
|
|
148
|
+
|
|
149
|
+
To cite it, see `CITATION.cff`.
|
ablt-2.0.0/README.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# ABLT
|
|
2
|
+
|
|
3
|
+
**Alkebulan Bantu-Luganda Tokenizer, version 2.** A tokenizer for Luganda that cuts words
|
|
4
|
+
where their meaning changes, using the grammar of the language, before a statistical
|
|
5
|
+
tokenizer (SentencePiece) takes over.
|
|
6
|
+
|
|
7
|
+
Built by Mathew Sekanjako ([sekanjakomathew.com](https://www.sekanjakomathew.com),
|
|
8
|
+
[LinkedIn](https://www.linkedin.com/in/sekanjako-mathew/)), Psalms23Wave LLC, as part of
|
|
9
|
+
Alkebulan AI.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install "git+https://github.com/Psalms23Wave/AlkebulanAI#subdirectory=packages/ablt"
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
It needs only `sentencepiece`. The trained Luganda model is inside the package.
|
|
18
|
+
|
|
19
|
+
## Use
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from ablt import ABLT
|
|
23
|
+
|
|
24
|
+
tokenizer = ABLT()
|
|
25
|
+
|
|
26
|
+
tokenizer.tokenize("Abantu basoma ebitabo.")
|
|
27
|
+
# ['▁Abaǀ', '▁ntu', '▁baǀ', '▁soma', '▁ebiǀ', '▁tabo', '.']
|
|
28
|
+
|
|
29
|
+
ids = tokenizer.encode("Abantu basoma ebitabo.")
|
|
30
|
+
tokenizer.decode(ids)
|
|
31
|
+
# 'Abantu basoma ebitabo.' (exactly the text that went in)
|
|
32
|
+
|
|
33
|
+
tokenizer.show_cuts("okusoma ebitabo")
|
|
34
|
+
# 'oku|soma ebi|tabo'
|
|
35
|
+
|
|
36
|
+
tokenizer.morphemes("okusoma")
|
|
37
|
+
# ['oku', 'soma']
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### From the terminal, with no Python to write
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
ablt "Abantu baagala okusoma ebitabo."
|
|
44
|
+
# ▁Abaǀ ▁ntu ▁baǀ ▁agala ▁okuǀ ▁soma ▁ebiǀ ▁tabo .
|
|
45
|
+
|
|
46
|
+
ablt --cuts "Abantu baagala okusoma ebitabo."
|
|
47
|
+
# Aba|ntu ba|agala oku|soma ebi|tabo.
|
|
48
|
+
|
|
49
|
+
ablt --ids "Abantu baagala okusoma ebitabo." # piece numbers
|
|
50
|
+
ablt < story.txt # a whole file, line by line
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Reading the pieces
|
|
54
|
+
|
|
55
|
+
- A piece that starts with `▁` begins a new word.
|
|
56
|
+
- A piece that ends with `ǀ` is joined to the piece after it. `▁abaǀ` followed by `▁ntu` is
|
|
57
|
+
the single word `abantu`.
|
|
58
|
+
- A root is the same piece wherever it appears. `▁ntu` is the same piece in `abantu`,
|
|
59
|
+
`omuntu` and `ekintu`, and `▁soma` is the same piece in `okusoma` and `basoma`, so a model
|
|
60
|
+
learns each root once.
|
|
61
|
+
|
|
62
|
+
## What was measured
|
|
63
|
+
|
|
64
|
+
Run `python packages/ablt/tools/evaluate.py` to reproduce these.
|
|
65
|
+
|
|
66
|
+
| Test | ABLT version 2 | Plain SentencePiece trained on the same text, same size |
|
|
67
|
+
|---|---|---|
|
|
68
|
+
| Cuts fall on grammar boundaries, 83 Luganda words (F1) | 91.7% | 41.3% |
|
|
69
|
+
| The same words written with a capital letter | 93.3% | 72.7% |
|
|
70
|
+
| Words cut fully correctly | 86.7% | 18.1% |
|
|
71
|
+
| Pieces per word, 7,060 sentences of MasakhaNER 2.0 Luganda | 2.20 | 1.94 |
|
|
72
|
+
| Decoding gives back the exact text, 13,542 sentences | 13,542 of 13,542 | |
|
|
73
|
+
|
|
74
|
+
The plain tokenizer is a check built for this comparison: it is trained on the same text
|
|
75
|
+
with the same settings and has no grammar rules. It makes fewer pieces because it leaves
|
|
76
|
+
most words whole. ABLT cuts on purpose, at the grammar.
|
|
77
|
+
|
|
78
|
+
On the same MasakhaNER sentences, the tokenizers of two general models make 2.69 pieces per
|
|
79
|
+
word (Qwen2.5) and 2.89 (GPT-2).
|
|
80
|
+
|
|
81
|
+
## What changed from version 1
|
|
82
|
+
|
|
83
|
+
| | Version 1 | Version 2 |
|
|
84
|
+
|---|---|---|
|
|
85
|
+
| Decoding gives back the exact text | about 3% of sentences | every sentence tested |
|
|
86
|
+
| Words that start with a capital letter | not cut | cut like any other word |
|
|
87
|
+
| Names and acronyms in the middle of a sentence | cut by the rules | left whole |
|
|
88
|
+
| Forced short pieces | yes, 3.82 pieces per word | none, 2.20 pieces per word |
|
|
89
|
+
| A root after a prefix | a different piece from the root alone | the same piece |
|
|
90
|
+
| Text is rewritten before tokenizing | yes (spaces added round punctuation) | no |
|
|
91
|
+
|
|
92
|
+
The grammar rules themselves are the version 1 rules, unchanged: the longest noun-class
|
|
93
|
+
prefix, otherwise the longest verb extension. Each word is cut in at most one place.
|
|
94
|
+
|
|
95
|
+
## Limits
|
|
96
|
+
|
|
97
|
+
- The answer key has 83 words. It needs checking and extending by Luganda speakers.
|
|
98
|
+
- Each word is cut once. `alisoma` becomes `ali|soma`, where a full analysis is
|
|
99
|
+
`a|li|soma`.
|
|
100
|
+
- A name at the very start of a sentence is treated as an ordinary word and may be cut.
|
|
101
|
+
- It has been tested on Luganda only. Other Bantu languages need their own rule tables.
|
|
102
|
+
- It is shown to cut words at grammar boundaries. Whether that makes a trained model learn
|
|
103
|
+
better, or from less text, has not been tested yet.
|
|
104
|
+
|
|
105
|
+
## Training text and credit
|
|
106
|
+
|
|
107
|
+
The bundled model was trained on 58,346 unique lines of Luganda text (see `DATA.md` in the
|
|
108
|
+
Alkebulan AI repository). Most of that text comes from the SALT dataset by Sunbird AI,
|
|
109
|
+
released under CC BY-SA 4.0. One line in ten was held back and used only for testing.
|
|
110
|
+
|
|
111
|
+
## Rebuilding the model
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
python packages/ablt/tools/train_model.py # trains and writes the bundled model
|
|
115
|
+
python packages/ablt/tools/evaluate.py # prints the table above
|
|
116
|
+
python -m pytest packages/ablt/tests -q
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Licence and credit
|
|
120
|
+
|
|
121
|
+
Copyright 2025-2026 Mathew Sekanjako and Psalms23Wave LLC. Licensed under the Apache License,
|
|
122
|
+
version 2.0 (see `LICENSE`). Anyone who shares this work, changed or unchanged, must keep the
|
|
123
|
+
copyright notices and the `NOTICE` file, and must say what they changed.
|
|
124
|
+
|
|
125
|
+
ABLT™, Sekan™ and Alkebulan AI™ are trademarks of Psalms23Wave LLC. The licence does not
|
|
126
|
+
give permission to use these names for other products. The project's full terms are in
|
|
127
|
+
`LICENSING.md`, `TRADEMARK.md` and `COMMERCIAL.md` in the Alkebulan AI repository.
|
|
128
|
+
|
|
129
|
+
To cite it, see `CITATION.cff`.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "ablt"
|
|
7
|
+
version = "2.0.0"
|
|
8
|
+
description = "ABLT: a grammar-first tokenizer for Luganda and other Bantu languages"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
license-files = ["LICENSE", "NOTICE"]
|
|
13
|
+
authors = [{ name = "Mathew Sekanjako" }]
|
|
14
|
+
maintainers = [{ name = "Psalms23Wave LLC" }]
|
|
15
|
+
keywords = ["tokenizer", "Luganda", "Bantu", "African languages", "NLP", "morphology", "SentencePiece"]
|
|
16
|
+
dependencies = ["sentencepiece>=0.2.0"]
|
|
17
|
+
|
|
18
|
+
[project.scripts]
|
|
19
|
+
ablt = "ablt.cli:main"
|
|
20
|
+
|
|
21
|
+
[project.urls]
|
|
22
|
+
Repository = "https://github.com/Psalms23Wave/AlkebulanAI"
|
|
23
|
+
Author = "https://www.sekanjakomathew.com"
|
|
24
|
+
LinkedIn = "https://www.linkedin.com/in/sekanjako-mathew/"
|
|
25
|
+
Company = "https://www.psalms23wave.com"
|
|
26
|
+
Contact = "https://www.psalms23wave.com/contact"
|
|
27
|
+
|
|
28
|
+
[tool.setuptools.packages.find]
|
|
29
|
+
where = ["src"]
|
|
30
|
+
|
|
31
|
+
[tool.setuptools.package-data]
|
|
32
|
+
ablt = ["models/*.model", "models/*.json", "models/SHA256SUMS", "models/README.txt"]
|
ablt-2.0.0/setup.cfg
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Copyright 2025-2026 Mathew Sekanjako and Psalms23Wave LLC
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""ABLT: a grammar-first tokenizer for Luganda and other Bantu languages."""
|
|
4
|
+
|
|
5
|
+
from .segmenter import cut, show_cuts, split_word
|
|
6
|
+
from .tokenizer import ABLT
|
|
7
|
+
|
|
8
|
+
__version__ = "2.0.0"
|
|
9
|
+
__author__ = "Mathew Sekanjako"
|
|
10
|
+
__copyright__ = "Copyright 2025-2026 Mathew Sekanjako and Psalms23Wave LLC"
|
|
11
|
+
__license__ = "Apache-2.0"
|
|
12
|
+
__url__ = "https://www.sekanjakomathew.com"
|
|
13
|
+
__all__ = ["ABLT", "cut", "show_cuts", "split_word"]
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Copyright 2025-2026 Mathew Sekanjako and Psalms23Wave LLC
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""Use ABLT from the terminal.
|
|
4
|
+
|
|
5
|
+
ablt "Abantu basoma ebitabo." show the pieces
|
|
6
|
+
ablt --cuts "Abantu basoma ebitabo." show where the grammar cuts fall
|
|
7
|
+
ablt --ids "Abantu basoma ebitabo." show the piece numbers
|
|
8
|
+
ablt < story.txt read lines from a file
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import argparse
|
|
14
|
+
import sys
|
|
15
|
+
|
|
16
|
+
from . import __version__
|
|
17
|
+
from .segmenter import show_cuts
|
|
18
|
+
from .tokenizer import ABLT
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def main(arguments: list[str] | None = None) -> int:
|
|
22
|
+
parser = argparse.ArgumentParser(
|
|
23
|
+
prog="ablt",
|
|
24
|
+
description="ABLT: a grammar-first tokenizer for Luganda, by Mathew Sekanjako (Psalms23Wave LLC).",
|
|
25
|
+
)
|
|
26
|
+
parser.add_argument(
|
|
27
|
+
"text",
|
|
28
|
+
nargs="*",
|
|
29
|
+
help="text to tokenize; if left out, lines are read from standard input",
|
|
30
|
+
)
|
|
31
|
+
output = parser.add_mutually_exclusive_group()
|
|
32
|
+
output.add_argument(
|
|
33
|
+
"--cuts", action="store_true", help="show the text with | at each grammar cut"
|
|
34
|
+
)
|
|
35
|
+
output.add_argument(
|
|
36
|
+
"--ids", action="store_true", help="show piece numbers instead of pieces"
|
|
37
|
+
)
|
|
38
|
+
credit = f"ablt {__version__}. Copyright 2025-2026 Mathew Sekanjako and Psalms23Wave LLC. Apache-2.0."
|
|
39
|
+
parser.add_argument("--version", action="version", version=credit)
|
|
40
|
+
options = parser.parse_args(arguments)
|
|
41
|
+
|
|
42
|
+
lines = (
|
|
43
|
+
[" ".join(options.text)]
|
|
44
|
+
if options.text
|
|
45
|
+
else (line.rstrip("\n") for line in sys.stdin)
|
|
46
|
+
)
|
|
47
|
+
tokenizer = None if options.cuts else ABLT()
|
|
48
|
+
for line in lines:
|
|
49
|
+
if options.cuts:
|
|
50
|
+
print(show_cuts(line))
|
|
51
|
+
elif options.ids:
|
|
52
|
+
print(" ".join(str(index) for index in tokenizer.encode(line)))
|
|
53
|
+
else:
|
|
54
|
+
print(" ".join(tokenizer.tokenize(line)))
|
|
55
|
+
return 0
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
if __name__ == "__main__":
|
|
59
|
+
raise SystemExit(main())
|