ce-tagger 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ # Python
2
+ __pycache__
3
+ .pytest_cache
4
+ .ruff_cache
5
+ *.pyc
6
+
7
+ # Virtual environment
8
+ venv
9
+ .venv
10
+
11
+ # Distribution
12
+ dist
13
+ build
14
+ .eggs
15
+
16
+ # Answers of an origin check run from this directory
17
+ ce-tagger-answers.jsonl
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 (2026-11-29)
4
+
5
+ First beta.
6
+
7
+ - `Tagger`: marks Russian speech and loans the dictionaries do not attest in Chechen text; standard library only.
8
+ - Bundled model `ce_ru_tagger` version 3.
9
+ - `ce-tagger` command: cleaned text, list of marked words, list of words for review, list of unknown words.
10
+ - Optional origin check of unknown words through a Gemini-protocol endpoint (`pip install 'ce-tagger[ai]'`,
11
+ `--ai`): off by default, answers kept in a file and reused.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Chechen Language
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,195 @@
1
+ ---
2
+ language:
3
+ - ce
4
+ license: mit
5
+ library_name: ce-tagger
6
+ pipeline_tag: token-classification
7
+ tags:
8
+ - chechen
9
+ - code-switching
10
+ - language-identification
11
+ - loanwords
12
+ - corpus-cleaning
13
+ ---
14
+
15
+ # ce_ru_tagger, version 3
16
+
17
+ Marks the words of a Chechen text that are not Chechen: Russian speech, and loans that no dictionary attests. Built
18
+ for cleaning Chechen corpora before a frequency wordlist is made. It ships inside the Python package
19
+ [`ce-tagger`](https://github.com/chechen-language/ce-tagger).
20
+
21
+ | | |
22
+ | --- | --- |
23
+ | Kind of model | word lexicons, two character 5-gram models, three logistic regressions; not a neural network |
24
+ | File | `ce_ru_tagger.json.gz`, 7.7 MB, gzip-compressed JSON (no pickle: loading it runs no code) |
25
+ | Needs | Python 3.10+, standard library only |
26
+ | Speed | about 10 000 words per second on one core; loads in 1.5 s; about 340 MB of memory |
27
+ | Script | Chechen Cyrillic |
28
+ | Output per word | probability of "not Chechen", mark, kind (`ru` or `other`), whether the dictionaries attest the word |
29
+ | Threshold | 0.3 |
30
+ | Built | 2026-11-28 |
31
+
32
+ ## What the model decides
33
+
34
+ The rule it implements (in force since 2026-11-26):
35
+
36
+ - **Russian speech is not Chechen**: a reply, a quotation, a title, a Russian word dropped into a Chechen phrase.
37
+ Decided for each place in the text.
38
+ - **A loan counts as Chechen only if a dictionary attests it**, itself or as a form of a listed word (`машен`,
39
+ `школехь`, `районерчу`). A loan the dictionaries do not attest is marked: kind `ru` if it came from or through
40
+ Russian (`урканаш`, `райцентре`), kind `other` if it came from another language (`биллахӏ`, `яраббий`).
41
+ - A Chechen formation on a Russian root is marked unless the word itself is listed (`бригадхо`, `гитлерхойн`).
42
+ A Chechen formation on a root from another language is Chechen (`ӏеламчаш`).
43
+ - Names are neither protected nor hunted, and are left out of the scores.
44
+
45
+ Which error is worse was a deliberate choice. The dictionaries are incomplete (of the largest, one volume of ten
46
+ exists), so some legitimate loans are marked. That was accepted in order to pass as few foreign words as possible.
47
+ When in doubt, the labels mark.
48
+
49
+ ## How to use
50
+
51
+ ```bash
52
+ pip install ce-tagger
53
+ ce-tagger corpus.json.gz -o cleaned.json.gz --marked marked.tsv --review review.tsv
54
+ ```
55
+
56
+ ```python
57
+ from ce_tagger import Tagger
58
+
59
+ tagger = Tagger() # or Tagger("ce_ru_tagger.json.gz")
60
+ for token in tagger.tag(text).marked:
61
+ print(token.word, token.kind, token.p)
62
+ ```
63
+
64
+ ## How it works
65
+
66
+ For each word the model gathers evidence, then two classifiers decide.
67
+
68
+ 1. **What is known about the word.** How often it occurs in Chechen text and as a foreign word in the training
69
+ corpus; how often in a Russian reference list; how Chechen or Russian its letters look (character 5-grams);
70
+ whether the dictionaries attest it (listed, a form of a listed word, or not). For a word the dictionaries do not
71
+ attest: whether it starts with a Russian word, whether it begins or ends with a listed form, and its letters.
72
+ 2. **Where it stands.** The same evidence for two neighbours on each side, punctuation around the word, whether it
73
+ is inside quotes, capitalisation.
74
+ 3. **Stage 1** is a logistic regression over all of this. **Stage 2** repeats it with the stage-1 probabilities of
75
+ three neighbours on each side, so that a short homograph (`и`, `а`, `я`, `да`) follows the words around it.
76
+ 4. A third classifier names the kind of a marked word from its letters.
77
+
78
+ Every decision can be traced to its features. The model has no notion of meaning: a word it has never seen and no
79
+ dictionary lists is judged by its shape and its neighbours only.
80
+
81
+ ## Training data
82
+
83
+ - **Corpus:** the Bukhia corpus of Chechen fiction, folklore and essays: 654 documents, 653 000 words. One document
84
+ (orthography rules) is left out.
85
+ - **Labels for Russian speech:** made by Gemini 4 Hydrogen, word by word in running text, on a third of the corpus
86
+ (1 199 passages): the places where an earlier statistical filter saw Russian or a rare Russian-looking word.
87
+ 3 115 words are Russian speech.
88
+ A random sample of the rest was checked the same way: 0 Russian words in 12 861.
89
+ - **Labels for loans:** each of the 23 738 different corpus words that the dictionaries do not attest went to
90
+ Gemini 4 Hydrogen with two or three examples, in two independent passes: native, from Russian, from another
91
+ language, a name, not a word. The passes gave the same group for 98.9% of the words. Where they differed, the word
92
+ was marked. For the words that came out as loans the model then named the initial form, again twice; a word whose
93
+ initial form the dictionaries attest in both passes went back to Chechen (362 words). Result: 942 words from
94
+ Russian and 360 from another language, together 0.34% of the text.
95
+ - **One book more:** the released tool, with its origin check on, was run on a book of short prose outside the
96
+ corpus. 2 366 words of that book which the model did not know were judged the same way and added: 268 loans and 2 042
97
+ native words, names and forms of listed words. The other words of the book were not used for training, and four
98
+ stories of it were set aside as a test.
99
+ - **Dictionaries:** word forms from 12 dictionary titles. A quotation from fiction inside a dictionary entry does
100
+ not count as attestation; an example written by the dictionary's authors does.
101
+ - **Russian reference:** word counts from six Russian corpora of the Leipzig Corpora Collection (news, web,
102
+ Wikipedia; 6.3 million words).
103
+
104
+ A native speaker checked the large model on a blind sample: on the 84 words where the question applied, his answer
105
+ and the model's were the same. That is the only human check so far.
106
+
107
+ ## Evaluation
108
+
109
+ Five-fold cross-validation by document: each document is tagged by a model that has seen no part of it. **All
110
+ figures are agreement with Gemini 4 Hydrogen's labels, not accuracy against a native-speaker gold standard.**
111
+
112
+ "New word" means the word occurs nowhere in the training folds with a label. On a new corpus this is the row that
113
+ matters: the model has only the shape of the word to go by.
114
+
115
+ | Not Chechen: found | P > 0.2 | **P > 0.3** | P > 0.5 |
116
+ | --- | --- | --- | --- |
117
+ | Russian speech (2 917 words) | 96.8% | **96.2%** | 94.8% |
118
+ | Loan from Russian, word seen in training (185) | 98.9% | **98.9%** | 98.4% |
119
+ | Loan from Russian, new word (1 659) | 77.3% | **72.4%** | 62.1% |
120
+ | Loan from another language, word seen in training (277) | 96.0% | **96.0%** | 95.7% |
121
+ | Loan from another language, new word (536) | 34.3% | **28.7%** | 22.0% |
122
+
123
+ | Chechen: marked by mistake | P > 0.2 | **P > 0.3** | P > 0.5 |
124
+ | --- | --- | --- | --- |
125
+ | Word the dictionaries attest (593 663) | 156 | **110** | 76 |
126
+ | Native word the dictionaries do not attest, new word (18 497) | 3.2% | **2.1%** | 1.1% |
127
+ | All Chechen words (626 030) | 0.121% | **0.082%** | 0.045% |
128
+ | Names, for information (24 080) | 4.7% | **3.6%** | 2.2% |
129
+
130
+ The kind of a marked word is right for 97.3% of the words from Russian and 83.4% of the words from another language.
131
+
132
+ ### Held-out stories
133
+
134
+ Four stories of the added book (11 000 words) were never used for training. On the 497 word occurrences there that
135
+ Gemini 4 Hydrogen judged:
136
+
137
+ | | Version 2 | Version 3 |
138
+ | --- | --- | --- |
139
+ | Native word or name marked by mistake (472) | 14 | 4 |
140
+ | Loan found (25) | 17 | 18 |
141
+
142
+ The stories hold too few loans to measure how many are found. What the table shows is fewer false marks on new
143
+ native words of the same author.
144
+
145
+ ### What learning one more book changed
146
+
147
+ Between version 2 and version 3 the figures for new words stayed the same within a point or two. Learning a book
148
+ makes the model remember the words of that book. It does not teach it to recognise an unknown loan from Arabic or a
149
+ Turkic language in the next book.
150
+
151
+ ## Weak spots
152
+
153
+ - **A loan from Arabic or a Turkic language that the model has never seen is mostly missed** (29% found). By its
154
+ letters it looks like a Chechen word: `шекхал`, `гавур`, `акхсакхал`. Only a dictionary, more training text or the
155
+ origin check of the package tells them apart.
156
+ - **About a quarter of unseen loans from Russian are missed**: Chechen formations on a Russian root (`россерчу`),
157
+ short stems (`зек`), words with a Chechen look (`кунак`).
158
+ - **Russian speech is found unevenly**: best where it comes in passages, far less often for a single word far
159
+ from other Russian (a title in quotes, an exclamation such as «Браво»).
160
+ - **Everyday old loans that the dictionaries miss are marked** as `other`: `къурӏан`, `хьаьким`, `ӏелам`, `султан`.
161
+ Whether they should be is an open question for native speakers.
162
+ - **A spelling the dictionaries do not list is marked** even when the word is listed in another spelling.
163
+ - **Names:** 3.6% of name occurrences are marked. The model was not asked to handle names either way.
164
+ - **Register:** trained on fiction, folklore and essays. News text has not been tested.
165
+ - **Labels:** made by a large model. Its two passes agree with each other for 98.9% of words, which measures
166
+ steadiness, not correctness.
167
+
168
+ ## Out of scope
169
+
170
+ - Deciding whether a text is Chechen at all, or detecting any language other than "Chechen / not Chechen".
171
+ - Chechen in Latin script.
172
+ - Spell checking: a misspelt Chechen word is not what the model looks for, though an unlisted spelling can get marked.
173
+ - Judging how established a loan is. The model follows the dictionaries, and they are incomplete.
174
+
175
+ ## Sources inside the file
176
+
177
+ | Source | What the file holds |
178
+ | --- | --- |
179
+ | Bukhia corpus | counts of 67 000 different words, character statistics; no text |
180
+ | One book of short prose | counts for 2 310 of its words; no text |
181
+ | 12 dictionary titles | 455 000 word forms, without definitions |
182
+ | Leipzig Corpora Collection, Russian | counts of 386 000 words, character statistics |
183
+ | Gemini 4 Hydrogen | the labels the weights were fitted to |
184
+
185
+ Leipzig Corpora Collection: D. Goldhahn, T. Eckart, U. Quasthoff, *Building Large Monolingual Dictionaries at the
186
+ Leipzig Corpora Collection: From 100 to 200 Languages*, LREC 2012. Corpora used: `rus_news_2022`,
187
+ `rus_wikipedia_2021`, `rus-ru_web-public_2019`, `rus_newscrawl-public_2018`.
188
+
189
+ ## Versions
190
+
191
+ | Version | Date | Change |
192
+ | --- | --- | --- |
193
+ | 1 | 2026-11-26 | Russian speech only; every loan stayed. Not released. |
194
+ | 2 | 2026-11-28 | Rule of 2026-11-26: unattested loans are marked, kind `ru` / `other`; dictionary test knows forms of listed words. Not released. |
195
+ | 3 | 2026-11-28 | Version 2 plus 2 366 words of one more book, judged through the package's origin check. |
@@ -0,0 +1,172 @@
1
+ Metadata-Version: 2.5
2
+ Name: ce-tagger
3
+ Version: 0.1.0
4
+ Summary: Find the words of a Chechen text that are not Chechen: Russian speech and loans the dictionaries do not attest
5
+ Project-URL: Homepage, https://github.com/chechen-language/ce-tagger
6
+ Project-URL: Repository, https://github.com/chechen-language/ce-tagger
7
+ Project-URL: Issues, https://github.com/chechen-language/ce-tagger/issues
8
+ Author-email: Chechen Language <chechen-language@proton.me>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: Chechen,code-switching,corpus cleaning,language identification
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: Text Processing :: Linguistic
16
+ Requires-Python: >=3.10
17
+ Provides-Extra: ai
18
+ Requires-Dist: google-genai<4,>=2.29; extra == 'ai'
19
+ Requires-Dist: httpx<1,>=0.28.1; extra == 'ai'
20
+ Requires-Dist: pydantic<3,>=2; extra == 'ai'
21
+ Description-Content-Type: text/markdown
22
+
23
+ # ce-tagger
24
+
25
+ `ce-tagger` finds the words of a Chechen text that are not Chechen: Russian speech, and loans that no dictionary
26
+ attests. It is meant for cleaning a corpus before words are counted. It runs locally on the standard library, with
27
+ the model inside the package. An optional check asks a Gemini endpoint about the words the model has never met.
28
+
29
+ | Text | Marked |
30
+ | --- | --- |
31
+ | Машенаш некъа йистехьо гӏоьртина севцира. | nothing: `машен` is a loan the dictionaries list |
32
+ | Шайн эшарца, шайн гӏовгӏанца дӏакхечира уьш райцентре. | `райцентре` (ru) |
33
+ | Валлахӏ, ва биллахӏ, Васал, хӏокху тӏаьххьарчу деношкахь... | `валлахӏ`, `биллахӏ` (other) |
34
+ | Цо элира: «Товарищ начальник, я не знаю, что с ним делать». | all nine Russian words (ru) |
35
+
36
+ Requires Python 3.10 or later. Beta: the figures below are agreement with the labels of a large model, not accuracy
37
+ against a native-speaker gold standard.
38
+
39
+ ## The rule
40
+
41
+ A word is marked as not Chechen when it is
42
+
43
+ - **Russian speech**: a reply, a quotation, a title, a Russian word dropped into a Chechen phrase. This is decided
44
+ for each place in the text, so `и`, `а` or `да` can be Chechen in one sentence and Russian in the next;
45
+ - **a loan that no dictionary attests**, whatever its ending: `урканаш`, `райцентре`, `сборник`. A Chechen formation
46
+ on a Russian root counts too (`бригадхо`, `гитлерхойн`) unless the word itself is listed.
47
+
48
+ A marked word carries a kind: `ru` (Russian speech, or came from or through Russian) or `other` (came from another
49
+ language: `биллахӏ`, `яраббий`).
50
+
51
+ Not marked: native words; loans the dictionaries list, in any of their forms (`машен`, `школехь`, `районерчу`);
52
+ Chechen formations on a root from another language (`ӏеламчаш`). Names are neither protected nor hunted.
53
+
54
+ The dictionaries are 12 titles, one of them a ten-volume dictionary of which one volume exists so far. A valid loan
55
+ that these dictionaries happen to miss is marked. This is deliberate: marking a legitimate loan is the cheaper
56
+ error, passing a foreign word as Chechen is the costly one.
57
+
58
+ ## Installation
59
+
60
+ ```bash
61
+ pip install ce-tagger # or: uv add ce-tagger
62
+ pip install 'ce-tagger[ai]' # with the optional origin check
63
+ ```
64
+
65
+ ## Quick start
66
+
67
+ ```bash
68
+ ce-tagger text.txt -o cleaned.txt --marked marked.tsv --review review.tsv --unknown unknown.tsv
69
+ ```
70
+
71
+ `text.txt` is the input. The other four are output files, each optional:
72
+
73
+ - `cleaned.txt` (`-o`): the text without the marked words.
74
+ - `marked.tsv` (`--marked`): the words that were marked, to see what was removed.
75
+ - `review.tsv` (`--review`): words that were kept, but the model was unsure about. A short list for a native
76
+ speaker.
77
+ - `unknown.tsv` (`--unknown`): words found in neither the dictionaries nor the training data. This is what `--ai`
78
+ would ask about.
79
+
80
+ Without them the command saves nothing and only prints a summary: how many words it marked and the most frequent
81
+ ones.
82
+
83
+ - `marked.tsv` and `review.tsv` are tab-separated, one row per place in the text: `doc`, `offset`, `word`,
84
+ `p_not_chechen`, `kind` (`ru` or `other`, marked words only), `decided_by` (`model` or `ai`),
85
+ `in_dictionaries_0_1_2` (2: the word is in the dictionaries, 1: it is a form of a dictionary word, 0: neither)
86
+ and `context`.
87
+ - In the cleaned text a removed word becomes spaces, so offsets stay valid.
88
+ - The input can also be a `.json` / `.json.gz` corpus: a list of objects with a `text` field. The cleaned corpus
89
+ keeps that structure.
90
+ - `--threshold P` marks words above this probability. The model's own threshold is 0.3.
91
+
92
+ ```python
93
+ from ce_tagger import Tagger
94
+
95
+ tagger = Tagger()
96
+ result = tagger.tag("Шайн эшарца, шайн гӏовгӏанца дӏакхечира уьш райцентре.")
97
+ for token in result.marked:
98
+ print(token.word, token.kind, round(token.p, 2), token.decided_by) # райцентре ru 1.0 model
99
+ print(result.cleaned())
100
+
101
+ results = tagger.tag_many(texts) # several texts as one job
102
+ ```
103
+
104
+ Each `Token` has `start`, `end` (offsets in the text), `word` (normalised), `p` (probability that the word is not
105
+ Chechen), `marked`, `kind`, `decided_by` (`model` or `ai`) and `attested` (2 listed in the dictionaries, 1 a form
106
+ of a listed word, 0 no).
107
+
108
+ Speed: about 10 000 words per second on one core; the model loads in 1.5 s and takes about 340 MB of memory.
109
+
110
+ ## Words the model does not know
111
+
112
+ The model knows a word when a dictionary attests it or the training corpus contains it. Any other word is judged by
113
+ its letters and neighbours. For a Russian word that mostly works. A loan from Arabic or a Turkic language looks
114
+ like a Chechen word and is mostly missed (see the table below).
115
+
116
+ The optional **origin check** sends exactly these words, each with up to three short examples from the text, to a
117
+ large model through a Gemini-protocol endpoint (Google's API, or a compatible gateway). Its verdict replaces the
118
+ local model's and the output records who decided.
119
+
120
+ ```bash
121
+ export GEMINI_API_KEY=...
122
+ ce-tagger corpus.json.gz --ai --ai-model MODEL_NAME -o cleaned.json.gz --marked marked.tsv
123
+ ```
124
+
125
+ The check is off by default. Answers are kept in a file, so a second run sends nothing and gives the same result,
126
+ and the file can be applied later without any network call. The check takes minutes instead of seconds, sends
127
+ parts of your text to the provider and spends the quota of your key: see [docs/origin-check.md](https://github.com/chechen-language/ce-tagger/blob/main/docs/origin-check.md).
128
+
129
+ ## How well it works
130
+
131
+ Five-fold cross-validation by document on the training corpus; each document is tagged by a model that never saw
132
+ it. "New word" means the word occurs nowhere in the training folds, which is the situation on a new corpus.
133
+
134
+ | | Result at the model's threshold (0.3) |
135
+ | --- | --- |
136
+ | Russian speech found | 96.2% of 2 917 words |
137
+ | Loan from Russian found: word seen in training / new word | 98.9% / 72.4% |
138
+ | Loan from another language found: word seen in training / new word | 96.0% / 28.7% |
139
+ | Chechen word the dictionaries attest, marked by mistake | 110 of 593 663 |
140
+ | Native word the dictionaries do not attest, new word, marked by mistake | 2.1% |
141
+ | Kind right: `ru` / `other` | 97.3% / 83.4% |
142
+
143
+ Full tables, the test on a held-out part of a book and the weak spots are in [MODEL_CARD.md](https://github.com/chechen-language/ce-tagger/blob/main/MODEL_CARD.md).
144
+
145
+ ## Limitations
146
+
147
+ - Agreement with a large model's labels is not accuracy. A native-speaker gold set does not exist yet.
148
+ - Trained on fiction, folklore and essays. News text has not been tested.
149
+ - Unknown loans from Arabic or Turkic languages are mostly missed without the origin check.
150
+ - Single Russian words far from other Russian (a title in quotes, an exclamation) are caught less often than
151
+ Russian passages.
152
+ - Some everyday old loans are missing from the dictionaries and get marked as `other` (`къурӏан`, `хьаьким`).
153
+
154
+ ## Development
155
+
156
+ ```bash
157
+ uv run --extra ai --with pytest pytest
158
+ uv build
159
+ ```
160
+
161
+ The offline tests cover the tagger, the answer file, the origin procedure, the command line and real SDK requests
162
+ to local HTTP servers. They need no key and no endpoint. `pytest tests/test_live_gemini.py --run-live` sends four
163
+ words to the endpoint set by `GEMINI_API_KEY`, `GEMINI_MODEL` and `GEMINI_BASE_URL`.
164
+
165
+ Report bugs or ask questions in [GitHub Issues](https://github.com/chechen-language/ce-tagger/issues).
166
+
167
+ ## Data inside the model
168
+
169
+ The model file holds word counts from the training corpus, Russian word counts derived from the
170
+ [Leipzig Corpora Collection](https://wortschatz.uni-leipzig.de/en/download/Russian), word forms from 12 dictionary
171
+ titles, and about 85 000 weights. It holds no text. Sources and their terms are listed in
172
+ [MODEL_CARD.md](https://github.com/chechen-language/ce-tagger/blob/main/MODEL_CARD.md).
@@ -0,0 +1,150 @@
1
+ # ce-tagger
2
+
3
+ `ce-tagger` finds the words of a Chechen text that are not Chechen: Russian speech, and loans that no dictionary
4
+ attests. It is meant for cleaning a corpus before words are counted. It runs locally on the standard library, with
5
+ the model inside the package. An optional check asks a Gemini endpoint about the words the model has never met.
6
+
7
+ | Text | Marked |
8
+ | --- | --- |
9
+ | Машенаш некъа йистехьо гӏоьртина севцира. | nothing: `машен` is a loan the dictionaries list |
10
+ | Шайн эшарца, шайн гӏовгӏанца дӏакхечира уьш райцентре. | `райцентре` (ru) |
11
+ | Валлахӏ, ва биллахӏ, Васал, хӏокху тӏаьххьарчу деношкахь... | `валлахӏ`, `биллахӏ` (other) |
12
+ | Цо элира: «Товарищ начальник, я не знаю, что с ним делать». | all nine Russian words (ru) |
13
+
14
+ Requires Python 3.10 or later. Beta: the figures below are agreement with the labels of a large model, not accuracy
15
+ against a native-speaker gold standard.
16
+
17
+ ## The rule
18
+
19
+ A word is marked as not Chechen when it is
20
+
21
+ - **Russian speech**: a reply, a quotation, a title, a Russian word dropped into a Chechen phrase. This is decided
22
+ for each place in the text, so `и`, `а` or `да` can be Chechen in one sentence and Russian in the next;
23
+ - **a loan that no dictionary attests**, whatever its ending: `урканаш`, `райцентре`, `сборник`. A Chechen formation
24
+ on a Russian root counts too (`бригадхо`, `гитлерхойн`) unless the word itself is listed.
25
+
26
+ A marked word carries a kind: `ru` (Russian speech, or came from or through Russian) or `other` (came from another
27
+ language: `биллахӏ`, `яраббий`).
28
+
29
+ Not marked: native words; loans the dictionaries list, in any of their forms (`машен`, `школехь`, `районерчу`);
30
+ Chechen formations on a root from another language (`ӏеламчаш`). Names are neither protected nor hunted.
31
+
32
+ The dictionaries are 12 titles, one of them a ten-volume dictionary of which one volume exists so far. A valid loan
33
+ that these dictionaries happen to miss is marked. This is deliberate: marking a legitimate loan is the cheaper
34
+ error, passing a foreign word as Chechen is the costly one.
35
+
36
+ ## Installation
37
+
38
+ ```bash
39
+ pip install ce-tagger # or: uv add ce-tagger
40
+ pip install 'ce-tagger[ai]' # with the optional origin check
41
+ ```
42
+
43
+ ## Quick start
44
+
45
+ ```bash
46
+ ce-tagger text.txt -o cleaned.txt --marked marked.tsv --review review.tsv --unknown unknown.tsv
47
+ ```
48
+
49
+ `text.txt` is the input. The other four are output files, each optional:
50
+
51
+ - `cleaned.txt` (`-o`): the text without the marked words.
52
+ - `marked.tsv` (`--marked`): the words that were marked, to see what was removed.
53
+ - `review.tsv` (`--review`): words that were kept, but the model was unsure about. A short list for a native
54
+ speaker.
55
+ - `unknown.tsv` (`--unknown`): words found in neither the dictionaries nor the training data. This is what `--ai`
56
+ would ask about.
57
+
58
+ Without them the command saves nothing and only prints a summary: how many words it marked and the most frequent
59
+ ones.
60
+
61
+ - `marked.tsv` and `review.tsv` are tab-separated, one row per place in the text: `doc`, `offset`, `word`,
62
+ `p_not_chechen`, `kind` (`ru` or `other`, marked words only), `decided_by` (`model` or `ai`),
63
+ `in_dictionaries_0_1_2` (2: the word is in the dictionaries, 1: it is a form of a dictionary word, 0: neither)
64
+ and `context`.
65
+ - In the cleaned text a removed word becomes spaces, so offsets stay valid.
66
+ - The input can also be a `.json` / `.json.gz` corpus: a list of objects with a `text` field. The cleaned corpus
67
+ keeps that structure.
68
+ - `--threshold P` marks words above this probability. The model's own threshold is 0.3.
69
+
70
+ ```python
71
+ from ce_tagger import Tagger
72
+
73
+ tagger = Tagger()
74
+ result = tagger.tag("Шайн эшарца, шайн гӏовгӏанца дӏакхечира уьш райцентре.")
75
+ for token in result.marked:
76
+ print(token.word, token.kind, round(token.p, 2), token.decided_by) # райцентре ru 1.0 model
77
+ print(result.cleaned())
78
+
79
+ results = tagger.tag_many(texts) # several texts as one job
80
+ ```
81
+
82
+ Each `Token` has `start`, `end` (offsets in the text), `word` (normalised), `p` (probability that the word is not
83
+ Chechen), `marked`, `kind`, `decided_by` (`model` or `ai`) and `attested` (2 listed in the dictionaries, 1 a form
84
+ of a listed word, 0 no).
85
+
86
+ Speed: about 10 000 words per second on one core; the model loads in 1.5 s and takes about 340 MB of memory.
87
+
88
+ ## Words the model does not know
89
+
90
+ The model knows a word when a dictionary attests it or the training corpus contains it. Any other word is judged by
91
+ its letters and neighbours. For a Russian word that mostly works. A loan from Arabic or a Turkic language looks
92
+ like a Chechen word and is mostly missed (see the table below).
93
+
94
+ The optional **origin check** sends exactly these words, each with up to three short examples from the text, to a
95
+ large model through a Gemini-protocol endpoint (Google's API, or a compatible gateway). Its verdict replaces the
96
+ local model's and the output records who decided.
97
+
98
+ ```bash
99
+ export GEMINI_API_KEY=...
100
+ ce-tagger corpus.json.gz --ai --ai-model MODEL_NAME -o cleaned.json.gz --marked marked.tsv
101
+ ```
102
+
103
+ The check is off by default. Answers are kept in a file, so a second run sends nothing and gives the same result,
104
+ and the file can be applied later without any network call. The check takes minutes instead of seconds, sends
105
+ parts of your text to the provider and spends the quota of your key: see [docs/origin-check.md](https://github.com/chechen-language/ce-tagger/blob/main/docs/origin-check.md).
106
+
107
+ ## How well it works
108
+
109
+ Five-fold cross-validation by document on the training corpus; each document is tagged by a model that never saw
110
+ it. "New word" means the word occurs nowhere in the training folds, which is the situation on a new corpus.
111
+
112
+ | | Result at the model's threshold (0.3) |
113
+ | --- | --- |
114
+ | Russian speech found | 96.2% of 2 917 words |
115
+ | Loan from Russian found: word seen in training / new word | 98.9% / 72.4% |
116
+ | Loan from another language found: word seen in training / new word | 96.0% / 28.7% |
117
+ | Chechen word the dictionaries attest, marked by mistake | 110 of 593 663 |
118
+ | Native word the dictionaries do not attest, new word, marked by mistake | 2.1% |
119
+ | Kind right: `ru` / `other` | 97.3% / 83.4% |
120
+
121
+ Full tables, the test on a held-out part of a book and the weak spots are in [MODEL_CARD.md](https://github.com/chechen-language/ce-tagger/blob/main/MODEL_CARD.md).
122
+
123
+ ## Limitations
124
+
125
+ - Agreement with a large model's labels is not accuracy. A native-speaker gold set does not exist yet.
126
+ - Trained on fiction, folklore and essays. News text has not been tested.
127
+ - Unknown loans from Arabic or Turkic languages are mostly missed without the origin check.
128
+ - Single Russian words far from other Russian (a title in quotes, an exclamation) are caught less often than
129
+ Russian passages.
130
+ - Some everyday old loans are missing from the dictionaries and get marked as `other` (`къурӏан`, `хьаьким`).
131
+
132
+ ## Development
133
+
134
+ ```bash
135
+ uv run --extra ai --with pytest pytest
136
+ uv build
137
+ ```
138
+
139
+ The offline tests cover the tagger, the answer file, the origin procedure, the command line and real SDK requests
140
+ to local HTTP servers. They need no key and no endpoint. `pytest tests/test_live_gemini.py --run-live` sends four
141
+ words to the endpoint set by `GEMINI_API_KEY`, `GEMINI_MODEL` and `GEMINI_BASE_URL`.
142
+
143
+ Report bugs or ask questions in [GitHub Issues](https://github.com/chechen-language/ce-tagger/issues).
144
+
145
+ ## Data inside the model
146
+
147
+ The model file holds word counts from the training corpus, Russian word counts derived from the
148
+ [Leipzig Corpora Collection](https://wortschatz.uni-leipzig.de/en/download/Russian), word forms from 12 dictionary
149
+ titles, and about 85 000 weights. It holds no text. Sources and their terms are listed in
150
+ [MODEL_CARD.md](https://github.com/chechen-language/ce-tagger/blob/main/MODEL_CARD.md).