File size: 8,075 Bytes
efea51d 33b156e 5e8af7b 33b156e 64c9f52 33b156e 8f7f20a 33b156e 8f7f20a 33b156e 64c9f52 33b156e 64c9f52 33b156e 5e8af7b 33b156e 5e8af7b 3984b61 |
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 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 |
---
license: gpl-3.0
library_name: fasttext
tags:
- text-classification
- language-identification
language:
- ace
- afr
- af
- als
- amh
- am
- ara
- ar
- asm
- as
- ast
- awa
- ayr
- azb
- azj
- bak
- ba
- bam
- bm
- ban
- bel
- be
- bem
- ben
- bn
- bho
- bjn
- bod
- bo
- bos
- bs
- bug
- bul
- bg
- cat
- ca
- ceb
- ces
- cs
- cjk
- ckb
- cmn
- crh
- cym
- cy
- dan
- da
- deu
- de
- dik
- dzo
- dz
- ekk
- ell
- el
- eng
- en
- epo
- eo
- eus
- eu
- ewe
- ee
- fao
- fo
- fas
- fa
- fij
- fj
- fil
- fin
- fi
- fon
- fra
- fr
- frp
- fur
- fuv
- gaz
- gla
- gd
- gle
- ga
- glg
- gl
- gug
- guj
- gu
- hat
- ht
- hau
- ha
- heb
- he
- hin
- hi
- hne
- hrv
- hr
- hun
- hu
- hye
- hy
- ibo
- ig
- ilo
- ind
- id
- isl
- is
- ita
- it
- jav
- jv
- jpn
- ja
- kab
- kac
- kam
- kan
- kn
- kas
- ks
- kat
- ka
- kaz
- kk
- kbp
- kea
- khk
- khm
- km
- kik
- ki
- kin
- rw
- kir
- ky
- kmb
- kmr
- knc
- kor
- ko
- ktu
- lao
- lo
- lat
- la
- lij
- lim
- li
- lin
- ln
- lit
- lt
- lmo
- ltg
- ltz
- lb
- lua
- lug
- lg
- luo
- lus
- lvs
- mag
- mai
- mal
- ml
- mar
- mr
- min
- mkd
- mk
- mlt
- mt
- mni
- mos
- mri
- mi
- mya
- my
- nld
- nl
- nno
- nn
- nob
- nb
- npi
- nso
- nus
- nya
- ny
- oci
- oc
- ory
- pag
- pan
- pa
- pap
- pbt
- plt
- pol
- pl
- por
- pt
- quy
- ron
- ro
- run
- rn
- rus
- ru
- sag
- sg
- san
- sa
- sat
- scn
- shn
- sin
- si
- slk
- sk
- slv
- sl
- smo
- sm
- sna
- sn
- snd
- sd
- som
- so
- sot
- st
- spa
- es
- srd
- sc
- srp
- sr
- ssw
- ss
- sun
- su
- swe
- sv
- swh
- szl
- tam
- ta
- taq
- tat
- tt
- tel
- te
- tgk
- tg
- tha
- th
- tir
- ti
- tpi
- tsn
- tn
- tso
- ts
- tuk
- tk
- tum
- tur
- tr
- twi
- tw
- uig
- ug
- ukr
- uk
- umb
- urd
- ur
- uzn
- vec
- vie
- vi
- war
- wol
- wo
- xho
- xh
- ydd
- yor
- yo
- yue
- zgh
- zsm
- zul
- zu
---
# OpenLID-v3
- **Model type:** Text classification (language identification)
- **License:** gpl-3.0
## Model description
OpenLID-v3 is a high-coverage, high-performance language identification model. It is an improved version of [OpenLID-v2](https://huggingface.co/laurievb/OpenLID-v2).
The original model and training data are described in [Burchell et al. (2023)](https://aclanthology.org/2023.acl-short.75/), [the OpenLID-v2 dataset repo](https://huggingface.co/datasets/laurievb/OpenLID-v2).
This model is described in the [OpenLID-v3 paper](https://arxiv.org/abs/2602.13139).
### How to use
> [!WARNING]
> `fasttext` requires `numpy` <2.0
Here is how to use this model to detect the language of a given text. For best results, text should be preprocessed
```shell
pip install fasttext==0.9.3 huggingface-hub==0.35.3 numpy==1.23.5 regex==2024.4.28
```
```python
import fasttext
from huggingface_hub import hf_hub_download
import regex
# defines what we want to remove from string for langID
NONWORD_REPLACE_STR = r"[^\p{Word}\p{Zs}]|\d" # either (not a word nor a space) or (is digit)
NONWORD_REPLACE_PATTERN = regex.compile(NONWORD_REPLACE_STR)
SPACE_PATTERN = regex.compile(r"\s\s+") # squeezes sequential whitespace
def preprocess(text):
text = text.strip().replace('\n', ' ').lower()
text = regex.sub(SPACE_PATTERN, " ", text)
text = regex.sub(NONWORD_REPLACE_PATTERN, "", text)
return text
model_path = hf_hub_download(
repo_id="HPLT/OpenLID-v3", filename="openlid-v3.bin",
) # may take some time
model = fasttext.load_model(model_path)
text = "Maskinsjefen er oppteken av å løfta fram dei maritime utdanningane."
text = preprocess(text)
print(
model.predict(
text=text,
k=1,
threshold=0.5,
on_unicode_error="strict",
),
)
# should output: (('__label__nno_Latn',), array([0.99999893]))
```
### Limitations and bias
The dataset and model cover 194 language varieties. However, some language varieties (e.g. Arabic dialects) are very hard to distinguish and in practice, it may only be possible to classify an input at the macrolanguage level.
Our work aims to broaden NLP coverage by allowing practitioners to identify relevant data in more languages. However, we note that LID is inherently a normative activity that risks excluding minority dialects, scripts, or entire microlanguages from a macrolanguage. Choosing which languages to cover may reinforce power imbalances, as only some groups gain access to NLP technologies. In addition, errors in LID can have a significant impact on downstream performance, particularly (as is often the case) when a system is used as a ‘black box’. The performance of our classifier is not equal across languages which could lead to worse downstream performance for particular groups. We mitigate this by providing metrics by class.
## Training data
The model was trained on the samples from [OpenLID-v2 dataset](https://huggingface.co/datasets/laurievb/OpenLID-v2), [glotlid-corpus](https://huggingface.co/datasets/cis-lmu/glotlid-corpus) and [Wikipedia](https://dumps.wikimedia.org/backup-index.html). The data was normalised and classes were up/downsampled with temperature sampling prior to training; code to do this can be found in [the OpenLID-v3 repository](https://github.com/hplt-project/openlid).
## Training procedure
The model was trained using fastText with the following hyperparameters set. All other hyperparameters were set to their default values.
* loss: softmax
* epochs: 2
* learning rate: 0.8
* minimum number of word occurances: 1000
* embedding dimension: 256
* character n-grams: 2-5
* word n-grams: 1
* bucket size: 1,000,000
* threads: 68
### Evaluation datasets
Evaluation details are available in [the paper repository](https://github.com/hplt-project/openlid-v3-evaluation/tree/main).
### BibTeX entry and citation info
```
@misc{fedorova2026openlidv3improvingprecisionclosely,
title={OpenLID-v3: Improving the Precision of Closely Related Language Identification -- An Experience Report},
author={Mariia Fedorova and Nikolay Arefyev and Maja Buljan and Jindřich Helcl and Stephan Oepen and Egil Rønningstad and Yves Scherrer},
year={2026},
eprint={2602.13139},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2602.13139},
}
```
```
@inproceedings{burchell-etal-2023-open,
title = "An Open Dataset and Model for Language Identification",
author = "Burchell, Laurie and
Birch, Alexandra and
Bogoychev, Nikolay and
Heafield, Kenneth",
editor = "Rogers, Anna and
Boyd-Graber, Jordan and
Okazaki, Naoaki",
booktitle = "Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 2: Short Papers)",
month = jul,
year = "2023",
address = "Toronto, Canada",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2023.acl-short.75",
doi = "10.18653/v1/2023.acl-short.75",
pages = "865--879",
abstract = "Language identification (LID) is a fundamental step in many natural language processing pipelines. However, current LID systems are far from perfect, particularly on lower-resource languages. We present a LID model which achieves a macro-average F1 score of 0.93 and a false positive rate of 0.033{\%} across 201 languages, outperforming previous work. We achieve this by training on a curated dataset of monolingual data, which we audit manually to ensure reliability. We make both the model and the dataset available to the research community. Finally, we carry out detailed analysis into our model{'}s performance, both in comparison to existing open models and by language class.",
}
```
[](https://arxiv.org/abs/2602.13139)
[](https://arxiv.org/abs/2305.13820)
This project has received funding from the European Union’s Horizon Europe research and innovation programme under grant agreement No 101070350 and from UK Research and Innovation (UKRI) under the UK government’s Horizon Europe funding guarantee [grant number 10052546]. |