Text Classification
fastText
language-identification
MariaFjodorowa commited on
Commit
33b156e
·
verified ·
1 Parent(s): 3570ce2

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +118 -3
README.md CHANGED
@@ -1,3 +1,118 @@
1
- ---
2
- license: gpl-3.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: gpl-3.0
3
+ library_name: fasttext
4
+ tags:
5
+ - text-classification
6
+ - language-identification
7
+ ---
8
+
9
+ # OpenLID-v3
10
+
11
+ - **Model type:** Text classification (language identification)
12
+ - **License:** gpl-3.0
13
+
14
+ ## Model description
15
+
16
+ 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).
17
+
18
+ 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).
19
+
20
+ ### How to use
21
+
22
+ > [!WARNING]
23
+ > `fasttext` requires `numpy` <2.0
24
+
25
+ Here is how to use this model to detect the language of a given text. For best results, text should be preprocessed
26
+
27
+ ```shell
28
+ pip install fasttext==0.9.3 huggingface-hub==0.35.3 numpy==1.23.5 regex==2024.4.28
29
+ ``
30
+
31
+ ```python
32
+ import fasttext
33
+ from huggingface_hub import hf_hub_download
34
+ import regex
35
+
36
+ # defines what we want to remove from string for langID
37
+ NONWORD_REPLACE_STR = r"[^\p{Word}\p{Zs}]|\d" # either (not a word nor a space) or (is digit)
38
+ NONWORD_REPLACE_PATTERN = regex.compile(NONWORD_REPLACE_STR)
39
+ SPACE_PATTERN = regex.compile(r"\s\s+") # squeezes sequential whitespace
40
+
41
+
42
+ def preprocess(text):
43
+ text = text.strip().replace('\n', ' ').lower()
44
+ text = regex.sub(SPACE_PATTERN, " ", text)
45
+ text = regex.sub(NONWORD_REPLACE_PATTERN, "", text)
46
+ return text
47
+
48
+ model_path = hf_hub_download(repo_id="HPLT/OpenLID-v3", filename="openlid-v3.bin") # may take some time
49
+ model = fasttext.load_model(model_path)
50
+ text = "Maskinsjefen er oppteken av å løfta fram dei maritime utdanningane."
51
+ text = preprocess(text)
52
+ print(
53
+ model.predict(
54
+ text=text,
55
+ k=1,
56
+ threshold=0.5,
57
+ on_unicode_error="strict",
58
+ ),
59
+ )
60
+ # should output: (('__label__nno_Latn',), array([0.99999893]))
61
+ ```
62
+
63
+ ### Limitations and bias
64
+
65
+ 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 a input at the macrolanguage level.
66
+
67
+ 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.
68
+
69
+ ## Training data
70
+
71
+ 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 [the OpenLID-v3 repository](https://github.com/hplt-project/openlid).
72
+
73
+ ## Training procedure
74
+
75
+ The model was trained using fastText with the following hyperparameters set. All other hyperparameters were set to their default values.
76
+
77
+ * loss: softmax
78
+ * epochs: 2
79
+ * learning rate: 0.8
80
+ * minimum number of word occurances: 1000
81
+ * embedding dimension: 256
82
+ * character n-grams: 2-5
83
+ * word n-grams: 1
84
+ * bucket size: 1,000,000
85
+ * threads: 68
86
+
87
+
88
+ ### Evaluation datasets
89
+
90
+ Evaluation details are available in [the paper repository](https://github.com/hplt-project/openlid-v3-evaluation/tree/main).
91
+
92
+ ### BibTeX entry and citation info
93
+
94
+ #### ACL citation (preferred)
95
+
96
+ ```
97
+ @inproceedings{burchell-etal-2023-open,
98
+ title = "An Open Dataset and Model for Language Identification",
99
+ author = "Burchell, Laurie and
100
+ Birch, Alexandra and
101
+ Bogoychev, Nikolay and
102
+ Heafield, Kenneth",
103
+ editor = "Rogers, Anna and
104
+ Boyd-Graber, Jordan and
105
+ Okazaki, Naoaki",
106
+ booktitle = "Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 2: Short Papers)",
107
+ month = jul,
108
+ year = "2023",
109
+ address = "Toronto, Canada",
110
+ publisher = "Association for Computational Linguistics",
111
+ url = "https://aclanthology.org/2023.acl-short.75",
112
+ doi = "10.18653/v1/2023.acl-short.75",
113
+ pages = "865--879",
114
+ 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.",
115
+ }
116
+ ```
117
+
118
+ [![arXiv](https://img.shields.io/badge/arXiv-2305.13820-b31b1b.svg)](https://arxiv.org/abs/2305.13820)