File size: 7,784 Bytes
9952add
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4d60c31
 
 
 
 
 
 
 
 
9952add
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4d60c31
9952add
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
---

language:
- ba
- tt
- ru
license: apache-2.0
pretty_name: Bashkir Multiclass LID
library_name: onnxruntime
pipeline_tag: text-classification
tags:
- bashkir
- tatar
- russian
- language-identification
- multilingual
- text-classification
- onnx
- onnxruntime
- low-resource
- open-source
---


# Bashkir Multiclass LID

> Compact ONNX language identification for `ba`, `tt`, `ru` and `other`, for
> Bashkir corpus filtering and local CPU inference.

## Overview

A compact ONNX language-identification model for Bashkir corpus filtering and
local CPU applications. It predicts four classes: `ba` (Bashkir), `tt` (Tatar),
`ru` (Russian) and `other` (other languages, code, URLs, technical noise and
corrupted text). It is designed to separate closely related Bashkir and Tatar
text while preventing foreign-language and technical material from being silently
classified as Bashkir.

| At a glance | |
| --- | --- |
| Task | Four-class language identification |
| Default artifact | `model.onnx` + `lid.py` |
| Classes | `ba`, `tt`, `ru`, `other` |
| Source | Bashkir, Tatar, Russian and technical text (not redistributed) |
| Version / license | v3 / Apache-2.0 |

## Contents

### Files and Configurations

| File | Purpose |
| --- | --- |
| `model.onnx` | Exported classifier graph and weights (opset 17) |
| `vectorizer.json` | Character and word feature vocabularies |
| `lid.py` | Portable ONNX Runtime adapter |
| `config.json` | Runtime contract and feature settings |
| `META.json` | Model passport, validation results and artifact hashes |
| `requirements.txt` | Minimal runtime dependencies |
| `LICENSE` | Full license text |
| `SHA256SUMS` | Release checksums |

Training texts and the original `joblib` pipeline are not distributed.

### Model Architecture

| Property | Description |
| --- | --- |
| Task | Four-class language identification |
| Classes | `ba`, `tt`, `ru`, `other` |
| Character features | TF-IDF `char_wb` n-grams, lengths 2–5 |
| Word features | TF-IDF word n-grams, lengths 1–2 |
| Classifier | `SGDClassifier(loss="log_loss")` |
| Export | ONNX, opset 17 |
| Runtime | ONNX Runtime on CPU |
| Input handling | Unicode-aware adapter in `lid.py` |

The ONNX graph consumes sparse feature tensors rather than raw strings; the
adapter performs tokenization, feature lookup, batching and checksum validation.
No custom ONNX operators or Transformers installation are needed.

### Examples

| Text | Prediction | Top probability |
| --- | --- | ---: |
| `Бары бала бара.` | `ba` | 0.829 |
| `Бүген Казанда яңа мәдәни үзәк ачылды.` | `tt` | 0.919 |
| `В Уфе открыли новый корпус университета.` | `ru` | 0.930 |
| `SELECT id FROM users WHERE active = TRUE;` | `other` | 0.982 |

## Method

The model is a dual-channel linear classifier: TF-IDF `char_wb` (2–5) and word
(1–2) features are fused and passed to an `SGDClassifier` exported to ONNX. It is
trained on Bashkir, Tatar, Russian and other-language material with technical
noise. Training texts are not distributed in this repository.

```text

multilingual training corpus (Bashkir, Tatar, Russian & noise)

  ├── 1. extract character n-grams: char_wb (2–5)

  ├── 2. extract word n-grams: words (1–2)

  ├── 3. feature union & TF-IDF weighting

  ├── 4. train multi-class SGDClassifier with calibrated log-loss

  └── 5. export optimized ONNX graph (4-way: ba / tt / ru / other)

```

### Evaluation

The clean multi-source benchmark contains 1,000 examples each from Bashkir,
Tatar, Russian and other-language/noise sources; the adversarial set includes
closely related Bashkir/Tatar pairs, code-switching, Kazakh, Chuvash, Russian
regional text and technical noise.

| Evaluation | Result |
| --- | ---: |
| Clean multi-source benchmark | 92.67% accuracy (3,707/4,000) |
| Bashkir subset | 81.70% recall (817/1,000) |
| Tatar subset | 100.00% recall (1,000/1,000) |
| Russian subset | 91.40% recall (914/1,000) |
| Other subset | 97.60% recall (976/1,000) |
| Linguistic adversarial stress test | 39/39 (100%) |
| ONNX / sklearn label parity | 0 disagreements |

The benchmark is not expert-reviewed Gold and some examples come from the same
source pools used during model development; source overlap was not fully
excluded. Exact validation fields are recorded in [`META.json`](META.json).

## Quality and Use

Mixed-language text does not have a separate class: predictions should be read as
the dominant language of the sentence. In a corpus pipeline, confident Bashkir can
be retained, while uncertain BA/TT or mixed cases should be sent to a review queue
instead of being deleted automatically. Short sentences with common Turkic
vocabulary remain intrinsically ambiguous.

### Limitations

- A lightweight text classifier, not a universal language detector.
- The reported benchmark is not an expert-reviewed Gold benchmark.
- Confidence values are model scores, not calibrated human probabilities.
- Empty strings, OCR fragments and technical noise should be handled with explicit pipeline rules.

## Related Resources

- [Bashkir LID (Binary BA vs NON_BA)](https://huggingface.co/failed09/bashkir-lid) —
  a strict `ba` vs `non_ba` gate with configurable thresholds; use it when only a
  pass/reject decision is needed.

## Usage

```bash

pip install huggingface_hub onnxruntime numpy

```

```python

import sys

from huggingface_hub import snapshot_download



model_dir = snapshot_download(

    "failed09/bashkir-lid-multiclass",

    allow_patterns=[

        "lid.py", "config.json", "META.json", "model.onnx", "vectorizer.json"

    ],

    revision="main",  # pin a reviewed commit for reproducible deployments

)

sys.path.insert(0, model_dir)

from lid import LanguageIdentifier



lid = LanguageIdentifier(model_dir=model_dir)

texts = [

    "Бары бала бара.",

    "Бүген Казанда яңа мәдәни үзәк ачылды.",

    "В Уфе открыли новый корпус университета.",

    "SELECT id FROM users WHERE active = TRUE;",

]



print(lid.predict(texts).tolist())

print(lid.predict_proba(texts))

print(lid.classes.tolist())  # probability-column order

```

After downloading, inference runs locally without network access. The
probability-column order is always the order in [`META.json`](META.json).

## License

Distributed under the [Apache-2.0 license](https://huggingface.co/failed09/bashkir-lid-multiclass/blob/main/LICENSE).
This release contains derived model and tokenizer assets, not the source corpus,
scans or original document layouts.

## Citation

```bibtex

@software{failed09_bashkir_multiclass_lid_2026,

  title = {Bashkir Multiclass LID},

  author = {failed09},

  year = {2026},

  publisher = {Hugging Face},

  url = {https://huggingface.co/failed09/bashkir-lid-multiclass},

  note = {Open-source four-class language identification for Bashkir corpus filtering}

}

```

## Open Bashkir Data and Sources 🐝

This release is part of an open-source effort to support the development,
preservation and practical use of the Bashkir language. Other related models,
datasets and tools are available on the author's Hugging Face profile.

The author does not claim ownership or authorship of the source texts or other
materials used to derive this release; rights and licensing remain with the
original authors, publishers and dataset providers. Source texts are not
redistributed in this repository, so users should follow the licenses and
attribution requirements of the relevant upstream resources.