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 whitespacedefpreprocess(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.
@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.",
}
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].
Runs of HPLT OpenLID-v3 on huggingface.co
1.1K
Total runs
0
24-hour runs
192
3-day runs
124
7-day runs
253
30-day runs
More Information About OpenLID-v3 huggingface.co Model
OpenLID-v3 huggingface.co is an AI model on huggingface.co that provides OpenLID-v3's model effect (), which can be used instantly with this HPLT OpenLID-v3 model. huggingface.co supports a free trial of the OpenLID-v3 model, and also provides paid use of the OpenLID-v3. Support call OpenLID-v3 model through api, including Node.js, Python, http.
OpenLID-v3 huggingface.co is an online trial and call api platform, which integrates OpenLID-v3's modeling effects, including api services, and provides a free online trial of OpenLID-v3, you can try OpenLID-v3 online for free by clicking the link below.
HPLT OpenLID-v3 online free url in huggingface.co:
OpenLID-v3 is an open source model from GitHub that offers a free installation service, and any user can find OpenLID-v3 on GitHub to install. At the same time, huggingface.co provides the effect of OpenLID-v3 install, users can directly use OpenLID-v3 installed effect in huggingface.co for debugging and trial. It also supports api for free installation.