distals 0.0.1__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.
- distals-0.0.1/PKG-INFO +306 -0
- distals-0.0.1/README.md +301 -0
- distals-0.0.1/distals/__init__.py +1 -0
- distals-0.0.1/distals/asjp.py +90 -0
- distals-0.0.1/distals/conceptualizer.py +25 -0
- distals-0.0.1/distals/distals.py +369 -0
- distals-0.0.1/distals/glot_tree.py +53 -0
- distals-0.0.1/distals/glottolog.py +54 -0
- distals-0.0.1/distals/grambank.py +91 -0
- distals-0.0.1/distals/l2v.py +34 -0
- distals-0.0.1/distals/langname_utils.py +117 -0
- distals-0.0.1/distals/linguameta.py +51 -0
- distals-0.0.1/distals/phoible.py +41 -0
- distals-0.0.1/distals/state_and_fate.py +22 -0
- distals-0.0.1/distals/textbased.py +132 -0
- distals-0.0.1/distals/wals.py +50 -0
- distals-0.0.1/distals/wiki.py +37 -0
- distals-0.0.1/distals.egg-info/PKG-INFO +306 -0
- distals-0.0.1/distals.egg-info/SOURCES.txt +23 -0
- distals-0.0.1/distals.egg-info/dependency_links.txt +1 -0
- distals-0.0.1/distals.egg-info/entry_points.txt +2 -0
- distals-0.0.1/distals.egg-info/requires.txt +5 -0
- distals-0.0.1/distals.egg-info/top_level.txt +1 -0
- distals-0.0.1/setup.cfg +4 -0
- distals-0.0.1/setup.py +25 -0
distals-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: distals
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Description-Content-Type: text/markdown
|
|
5
|
+
|
|
6
|
+
### Language distances and information
|
|
7
|
+
|
|
8
|
+
This repository combines a number of sources to obtain information and
|
|
9
|
+
distances for languages. It focuses on ISO639-3 languages, and combines
|
|
10
|
+
information from a variety of sources.
|
|
11
|
+
|
|
12
|
+
### Usage
|
|
13
|
+
The package is located in `src/distals/`, and can be used from the
|
|
14
|
+
commandline: `python3 src/distals/distals.py`.
|
|
15
|
+
|
|
16
|
+
Its main function is to provide a user with distance metrics between
|
|
17
|
+
two languages. This can be obtained by adding `--lang1` and `--lang2`
|
|
18
|
+
to the command. For example:
|
|
19
|
+
```
|
|
20
|
+
python3 src/distals/distals.py --lang1 fry --lang2 dan
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The distances are calculated based on information from existing databases.
|
|
24
|
+
This information is loaded from a pickle file (default `distals-db.pickle.gz`),
|
|
25
|
+
and a full database is included in this repo. It can also easily be updated,
|
|
26
|
+
by using the `--update_database` option and the `--update_textbased` option.
|
|
27
|
+
|
|
28
|
+
The package also depends on language code and language names conversion.
|
|
29
|
+
The database for this is included in `langname-db.pickle.gz`, this can
|
|
30
|
+
re-created with the `--cache_langnames` option.
|
|
31
|
+
|
|
32
|
+
For now, we assume all source data to be available in the `data/` folder. The
|
|
33
|
+
data can be updated using the `scripts/0.update.sh` script. So to update the
|
|
34
|
+
database completely, one has to run:
|
|
35
|
+
```
|
|
36
|
+
./scripts/0.update.sh
|
|
37
|
+
python3 src/distals/distals.py --update_database
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
To update the textbased features, the LTI-LangId corpus needs to be downloaded,
|
|
41
|
+
which takes a substantial amount of time (weeks), the steps for doing so can be
|
|
42
|
+
seen in `0.get_miltale.sh`.
|
|
43
|
+
|
|
44
|
+
It should be noted that all metrics are designed to have values between 0 and
|
|
45
|
+
1, and they are not directional. In cases where a metric could not be
|
|
46
|
+
estimated, the code returns a -1.
|
|
47
|
+
|
|
48
|
+
### Metrics
|
|
49
|
+
|
|
50
|
+
* **aes_dist**: first collects the Agglomerated Endangerment Scale (AES)
|
|
51
|
+
category for each language, and then calculates how many groups apart they
|
|
52
|
+
are. See also https://glottolog.org/langdoc/status , the extraction of these
|
|
53
|
+
values was done with the `scripts/getAES.py` script, and based on GlottoLog 5.0
|
|
54
|
+
|
|
55
|
+
* **asjp_lev_dist**: Calculates the LDND distance on the ASJP word lists as
|
|
56
|
+
defined in ``Adding typology to lexicostatistics: A combined approach to
|
|
57
|
+
language classification''. Unfortunately, there is no 1-1 mapping between the
|
|
58
|
+
language codes in ASJP and ISO639-3 codes, so we made an automatic mapping
|
|
59
|
+
based on the language name provided in ASJP and other sources. The script for
|
|
60
|
+
this is in `scripts/complete_lists.py` and the results in `data/aspj_conv`. We
|
|
61
|
+
use the normalized levenshtein as provided by ASJP
|
|
62
|
+
(https://asjp.clld.org/software). When multiple versions of a word are
|
|
63
|
+
available, we use the average (this was underspecified in the original paper,
|
|
64
|
+
and we could not find reference implementations).
|
|
65
|
+
|
|
66
|
+
* **lang2vec**: Cosine distance between lang2vec vectors, only taking into
|
|
67
|
+
account values that overlap. Note that this metric is thus hard to compare
|
|
68
|
+
across language pairs, as different linguistic features will be
|
|
69
|
+
included/excluded for different language pairs.
|
|
70
|
+
|
|
71
|
+
* **lang2vec_knn**: Cosine distance between lang2vec vectors which have been
|
|
72
|
+
completed through KNN by the original paper.
|
|
73
|
+
|
|
74
|
+
* **lang_fam**: The percentage of trees of distance. This means that if you are
|
|
75
|
+
in two different trees, it will always be 2.0. If both languages are in the
|
|
76
|
+
same tree it is #overlapping edges/the total edges of the deepest language of
|
|
77
|
+
the two.
|
|
78
|
+
|
|
79
|
+
* **lang_group**: distance between language groups as defined in ``The State
|
|
80
|
+
and Fate of Linguistic Diversity and Inclusion in the NLP World''.
|
|
81
|
+
Unfortunately, I could not obtain the language codes, but have made an
|
|
82
|
+
automatic mapping (`scripts/complete_lang2tax.py`), which is available in
|
|
83
|
+
`data/lang2tax.txt.codes`.
|
|
84
|
+
|
|
85
|
+
* **script**: We use the set of scripts used for a language as collected by
|
|
86
|
+
``GlotScript: A Resource and Tool for Low Resource Writing System
|
|
87
|
+
Identification''. We then calculate the percentage of overlap and inverse
|
|
88
|
+
(1-overlap) to obtain a distance metric. We ignore Braille (brai) in the
|
|
89
|
+
calculations, as the information for this script is incomplete.
|
|
90
|
+
|
|
91
|
+
* **speakers**: Number of speakers as reported by ASPJ, these are based on
|
|
92
|
+
numbers from an old version of Ethnologue. Transformed to a distance metric
|
|
93
|
+
by dividing the smallest by the largest number.
|
|
94
|
+
|
|
95
|
+
* **wiki_size**: Wikipedia size, which is extracted from a download of the
|
|
96
|
+
Wikipedia page ``List_of_Wikipedias'', downloaded on 17-04-2024. Transformed
|
|
97
|
+
to a distance metric by dividing the smallest by the largest number.
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
### Citations
|
|
101
|
+
Please provide the correct citations when using any of these metrics. People
|
|
102
|
+
have spend a lot of their valuable time providing us with this data. Also, I
|
|
103
|
+
would be interested to hear about your project if you find this repository
|
|
104
|
+
useful, so would appreciate a link/short description e-mailed to me
|
|
105
|
+
(robv@itu.dk).
|
|
106
|
+
|
|
107
|
+
* **aes_dist**:
|
|
108
|
+
```
|
|
109
|
+
@misc{glottolog,
|
|
110
|
+
title = "Glottolog 5.0.",
|
|
111
|
+
author = "Hammarström, Harald and Forkel, Robert and Haspelmath, Martin and Bank, Sebastian",
|
|
112
|
+
year = 2024,
|
|
113
|
+
url = "https://doi.org/10.5281/zenodo.10804357",
|
|
114
|
+
publisher = "Leipzig: Max Planck Institute for Evolutionary Anthropology",
|
|
115
|
+
misc = "Available online at http://glottolog.org, Accessed on 2024-04-24."
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
* **asjp_lev_dist**:
|
|
120
|
+
```
|
|
121
|
+
@misc{ASJP,
|
|
122
|
+
author = {Wichmann and Søren and Holman, Eric W. and Brown, Cecil H.},
|
|
123
|
+
year = {2022},
|
|
124
|
+
title = {The {ASJP} Database (version 20)}
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
* **lang2vec**:
|
|
129
|
+
```
|
|
130
|
+
@inproceedings{littell-etal-2017-uriel,
|
|
131
|
+
title = "{URIEL} and lang2vec: Representing languages as typological, geographical, and phylogenetic vectors",
|
|
132
|
+
author = "Littell, Patrick and
|
|
133
|
+
Mortensen, David R. and
|
|
134
|
+
Lin, Ke and
|
|
135
|
+
Kairis, Katherine and
|
|
136
|
+
Turner, Carlisle and
|
|
137
|
+
Levin, Lori",
|
|
138
|
+
editor = "Lapata, Mirella and
|
|
139
|
+
Blunsom, Phil and
|
|
140
|
+
Koller, Alexander",
|
|
141
|
+
booktitle = "Proceedings of the 15th Conference of the {E}uropean Chapter of the Association for Computational Linguistics: Volume 2, Short Papers",
|
|
142
|
+
month = apr,
|
|
143
|
+
year = "2017",
|
|
144
|
+
address = "Valencia, Spain",
|
|
145
|
+
publisher = "Association for Computational Linguistics",
|
|
146
|
+
url = "https://aclanthology.org/E17-2002",
|
|
147
|
+
pages = "8--14"
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
* **lang_fam**:
|
|
152
|
+
```
|
|
153
|
+
@misc{glottolog,
|
|
154
|
+
title = "Glottolog 5.0.",
|
|
155
|
+
author = "Hammarström, Harald and Forkel, Robert and Haspelmath, Martin and Bank, Sebastian",
|
|
156
|
+
year = 2024,
|
|
157
|
+
url = "https://doi.org/10.5281/zenodo.10804357",
|
|
158
|
+
publisher = "Leipzig: Max Planck Institute for Evolutionary Anthropology",
|
|
159
|
+
misc = "Available online at http://glottolog.org, Accessed on 2024-04-24."
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
* **lang_group**:
|
|
164
|
+
```
|
|
165
|
+
@inproceedings{joshi-etal-2020-state,
|
|
166
|
+
title = "The State and Fate of Linguistic Diversity and Inclusion in the {NLP} World",
|
|
167
|
+
author = "Joshi, Pratik and
|
|
168
|
+
Santy, Sebastin and
|
|
169
|
+
Budhiraja, Amar and
|
|
170
|
+
Bali, Kalika and
|
|
171
|
+
Choudhury, Monojit",
|
|
172
|
+
editor = "Jurafsky, Dan and
|
|
173
|
+
Chai, Joyce and
|
|
174
|
+
Schluter, Natalie and
|
|
175
|
+
Tetreault, Joel",
|
|
176
|
+
booktitle = "Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics",
|
|
177
|
+
month = jul,
|
|
178
|
+
year = "2020",
|
|
179
|
+
address = "Online",
|
|
180
|
+
publisher = "Association for Computational Linguistics",
|
|
181
|
+
url = "https://aclanthology.org/2020.acl-main.560",
|
|
182
|
+
doi = "10.18653/v1/2020.acl-main.560",
|
|
183
|
+
pages = "6282--6293"
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
* **script**:
|
|
188
|
+
```
|
|
189
|
+
@article{kargaran2023glotscript,
|
|
190
|
+
title={GlotScript: A Resource and Tool for Low Resource Writing System Identification},
|
|
191
|
+
author={Kargaran, Amir Hossein and Yvon, Fran{\c{c}}ois and Sch{\"u}tze, Hinrich},
|
|
192
|
+
journal={arXiv preprint arXiv:2309.13320},
|
|
193
|
+
year={2023}
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
* **speakers**:
|
|
198
|
+
```
|
|
199
|
+
@misc{ASJP,
|
|
200
|
+
author = {Wichmann and Søren and Holman, Eric W. and Brown, Cecil H.},
|
|
201
|
+
year = {2022},
|
|
202
|
+
title = {The {ASJP} Database (version 20)}
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
* **wiki_size**:
|
|
207
|
+
```
|
|
208
|
+
https://en.wikipedia.org/wiki/List_of_Wikipedias
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Example output
|
|
212
|
+
```
|
|
213
|
+
rob@cir:/data/rob/lang_dist$ python3 src/distals/distals.py --lang1 fry --lang2 dan
|
|
214
|
+
loading from: ./distals-db.pickle.gz
|
|
215
|
+
7855 languages loaded
|
|
216
|
+
========================================
|
|
217
|
+
Information for fry
|
|
218
|
+
wiki_size: 56,299
|
|
219
|
+
nlp_state: 1. The Scraping-Bys
|
|
220
|
+
speakers: 740,000
|
|
221
|
+
AES: 5. not endangered
|
|
222
|
+
loc: (5.86091, 53.143)
|
|
223
|
+
lang2vec: [1.0, 1.0, 0.0, ..., '--', '--', '--']
|
|
224
|
+
lang2vec_knn: [1.0, 1.0, 0.0, ..., 1.0, 0.0, 0.0]
|
|
225
|
+
grambank: {'GB020': 1, 'GB021': 1, 'GB022': 1, ..., 'GB520': 0, 'GB521': 0, 'GB522': 0}
|
|
226
|
+
glot_tree: ["'Western Frisian [west2354][fry]-l-'", "'Westlauwers-Terschelling Frisian [west2902]'", "'Modern West Frisian [mode1264]'", ..., "'Germanic [germ1287]'", "'Classical Indo-European [clas1257]'", "'Indo-European [indo1319]'"]
|
|
227
|
+
scripts: {'latn'}
|
|
228
|
+
asjp: [['1', 'ik'], ['2', 'do, yo'], ['3', 'vEi'], ..., ['95', 'fol'], ['96', 'nEy, nEi'], ['100', 'nam3']]
|
|
229
|
+
whitespace: 0.160835
|
|
230
|
+
punctuation: 0.031726
|
|
231
|
+
|
|
232
|
+
========================================
|
|
233
|
+
Information for dan
|
|
234
|
+
wiki_size: 307,173
|
|
235
|
+
nlp_state: 3. The Rising Stars
|
|
236
|
+
speakers: 5,510,600
|
|
237
|
+
AES: 5. not endangered
|
|
238
|
+
loc: (9.36284, 54.8655)
|
|
239
|
+
lang2vec: [1.0, 0.0, 0.0, ..., '--', '--', '--']
|
|
240
|
+
lang2vec_knn: [1.0, 0.0, 0.0, ..., 1.0, 0.0, 0.0]
|
|
241
|
+
grambank: {'GB020': 1, 'GB021': 1, 'GB022': 1, ..., 'GB520': 0, 'GB521': 0, 'GB522': 0}
|
|
242
|
+
glot_tree: ["'Danish [dani1285][dan]-l-'", "'South Scandinavian [sout3248]'", "'North Germanic [nort3160]'", "'Northwest Germanic [nort3152]'", "'Germanic [germ1287]'", "'Classical Indo-European [clas1257]'", "'Indo-European [indo1319]'"]
|
|
243
|
+
scripts: {'latn'}
|
|
244
|
+
asjp: [['1', 'yoy'], ['2', 'du'], ['3', 'vi'], ..., ['98', 'ron7'], ['99', 'tE7a'], ['100', 'now7n']]
|
|
245
|
+
whitespace: 0.156298
|
|
246
|
+
punctuation: 0.028514
|
|
247
|
+
|
|
248
|
+
========================================
|
|
249
|
+
Distances between fry and dan (-1 if the feature is not available for both)
|
|
250
|
+
METADATA
|
|
251
|
+
wiki_size: 0.8167
|
|
252
|
+
nlp_state: 0.4000
|
|
253
|
+
speakers: 0.8657
|
|
254
|
+
AES: 0.0000
|
|
255
|
+
loc: 0.0149
|
|
256
|
+
average: 0.5206
|
|
257
|
+
|
|
258
|
+
TYPOLOGY
|
|
259
|
+
lang2vec: 0.1598
|
|
260
|
+
lang2vec_knn: 0.1204
|
|
261
|
+
grambank: 0.0280
|
|
262
|
+
gb_clause: 0.0269
|
|
263
|
+
gb_nominal_domain: 0.0267
|
|
264
|
+
gb_numeral: 0.0353
|
|
265
|
+
gb_pronoun: 0.0000
|
|
266
|
+
gb_verbal_domain: 0.0328
|
|
267
|
+
glot_tree: 0.5325
|
|
268
|
+
scripts: 0.0000
|
|
269
|
+
average: 0.0280
|
|
270
|
+
|
|
271
|
+
WORDLISTS
|
|
272
|
+
asjp: 0.3397
|
|
273
|
+
concepts: 0.0400
|
|
274
|
+
average: 0.1898
|
|
275
|
+
|
|
276
|
+
TEXTBASED
|
|
277
|
+
whitespace: 0.0282
|
|
278
|
+
punctuation: 0.1012
|
|
279
|
+
JSD: 0.1979
|
|
280
|
+
average: 0.1979
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
Coverage:
|
|
285
|
+
```
|
|
286
|
+
7855 language codes found.
|
|
287
|
+
l2v_avg 3910
|
|
288
|
+
l2v_knn 3910
|
|
289
|
+
num_wikiarticles 286
|
|
290
|
+
speakers 5119
|
|
291
|
+
asjp 5581
|
|
292
|
+
glot_tree 7855
|
|
293
|
+
scripts 7393
|
|
294
|
+
state_and_fate 2264
|
|
295
|
+
AES 7718
|
|
296
|
+
loc 7624
|
|
297
|
+
speakers_l 5536
|
|
298
|
+
scripts_l 6425
|
|
299
|
+
conceptualizer 1271
|
|
300
|
+
grambank 2324
|
|
301
|
+
textdata found for 2110 iso-codes
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
## update pip
|
|
305
|
+
python3 setup.py sdist bdist_wheel
|
|
306
|
+
pip3 install dist/distals-0.1-py3-none-any.whl --break-system-packages --force-reinstall
|
distals-0.0.1/README.md
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
### Language distances and information
|
|
2
|
+
|
|
3
|
+
This repository combines a number of sources to obtain information and
|
|
4
|
+
distances for languages. It focuses on ISO639-3 languages, and combines
|
|
5
|
+
information from a variety of sources.
|
|
6
|
+
|
|
7
|
+
### Usage
|
|
8
|
+
The package is located in `src/distals/`, and can be used from the
|
|
9
|
+
commandline: `python3 src/distals/distals.py`.
|
|
10
|
+
|
|
11
|
+
Its main function is to provide a user with distance metrics between
|
|
12
|
+
two languages. This can be obtained by adding `--lang1` and `--lang2`
|
|
13
|
+
to the command. For example:
|
|
14
|
+
```
|
|
15
|
+
python3 src/distals/distals.py --lang1 fry --lang2 dan
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The distances are calculated based on information from existing databases.
|
|
19
|
+
This information is loaded from a pickle file (default `distals-db.pickle.gz`),
|
|
20
|
+
and a full database is included in this repo. It can also easily be updated,
|
|
21
|
+
by using the `--update_database` option and the `--update_textbased` option.
|
|
22
|
+
|
|
23
|
+
The package also depends on language code and language names conversion.
|
|
24
|
+
The database for this is included in `langname-db.pickle.gz`, this can
|
|
25
|
+
re-created with the `--cache_langnames` option.
|
|
26
|
+
|
|
27
|
+
For now, we assume all source data to be available in the `data/` folder. The
|
|
28
|
+
data can be updated using the `scripts/0.update.sh` script. So to update the
|
|
29
|
+
database completely, one has to run:
|
|
30
|
+
```
|
|
31
|
+
./scripts/0.update.sh
|
|
32
|
+
python3 src/distals/distals.py --update_database
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
To update the textbased features, the LTI-LangId corpus needs to be downloaded,
|
|
36
|
+
which takes a substantial amount of time (weeks), the steps for doing so can be
|
|
37
|
+
seen in `0.get_miltale.sh`.
|
|
38
|
+
|
|
39
|
+
It should be noted that all metrics are designed to have values between 0 and
|
|
40
|
+
1, and they are not directional. In cases where a metric could not be
|
|
41
|
+
estimated, the code returns a -1.
|
|
42
|
+
|
|
43
|
+
### Metrics
|
|
44
|
+
|
|
45
|
+
* **aes_dist**: first collects the Agglomerated Endangerment Scale (AES)
|
|
46
|
+
category for each language, and then calculates how many groups apart they
|
|
47
|
+
are. See also https://glottolog.org/langdoc/status , the extraction of these
|
|
48
|
+
values was done with the `scripts/getAES.py` script, and based on GlottoLog 5.0
|
|
49
|
+
|
|
50
|
+
* **asjp_lev_dist**: Calculates the LDND distance on the ASJP word lists as
|
|
51
|
+
defined in ``Adding typology to lexicostatistics: A combined approach to
|
|
52
|
+
language classification''. Unfortunately, there is no 1-1 mapping between the
|
|
53
|
+
language codes in ASJP and ISO639-3 codes, so we made an automatic mapping
|
|
54
|
+
based on the language name provided in ASJP and other sources. The script for
|
|
55
|
+
this is in `scripts/complete_lists.py` and the results in `data/aspj_conv`. We
|
|
56
|
+
use the normalized levenshtein as provided by ASJP
|
|
57
|
+
(https://asjp.clld.org/software). When multiple versions of a word are
|
|
58
|
+
available, we use the average (this was underspecified in the original paper,
|
|
59
|
+
and we could not find reference implementations).
|
|
60
|
+
|
|
61
|
+
* **lang2vec**: Cosine distance between lang2vec vectors, only taking into
|
|
62
|
+
account values that overlap. Note that this metric is thus hard to compare
|
|
63
|
+
across language pairs, as different linguistic features will be
|
|
64
|
+
included/excluded for different language pairs.
|
|
65
|
+
|
|
66
|
+
* **lang2vec_knn**: Cosine distance between lang2vec vectors which have been
|
|
67
|
+
completed through KNN by the original paper.
|
|
68
|
+
|
|
69
|
+
* **lang_fam**: The percentage of trees of distance. This means that if you are
|
|
70
|
+
in two different trees, it will always be 2.0. If both languages are in the
|
|
71
|
+
same tree it is #overlapping edges/the total edges of the deepest language of
|
|
72
|
+
the two.
|
|
73
|
+
|
|
74
|
+
* **lang_group**: distance between language groups as defined in ``The State
|
|
75
|
+
and Fate of Linguistic Diversity and Inclusion in the NLP World''.
|
|
76
|
+
Unfortunately, I could not obtain the language codes, but have made an
|
|
77
|
+
automatic mapping (`scripts/complete_lang2tax.py`), which is available in
|
|
78
|
+
`data/lang2tax.txt.codes`.
|
|
79
|
+
|
|
80
|
+
* **script**: We use the set of scripts used for a language as collected by
|
|
81
|
+
``GlotScript: A Resource and Tool for Low Resource Writing System
|
|
82
|
+
Identification''. We then calculate the percentage of overlap and inverse
|
|
83
|
+
(1-overlap) to obtain a distance metric. We ignore Braille (brai) in the
|
|
84
|
+
calculations, as the information for this script is incomplete.
|
|
85
|
+
|
|
86
|
+
* **speakers**: Number of speakers as reported by ASPJ, these are based on
|
|
87
|
+
numbers from an old version of Ethnologue. Transformed to a distance metric
|
|
88
|
+
by dividing the smallest by the largest number.
|
|
89
|
+
|
|
90
|
+
* **wiki_size**: Wikipedia size, which is extracted from a download of the
|
|
91
|
+
Wikipedia page ``List_of_Wikipedias'', downloaded on 17-04-2024. Transformed
|
|
92
|
+
to a distance metric by dividing the smallest by the largest number.
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
### Citations
|
|
96
|
+
Please provide the correct citations when using any of these metrics. People
|
|
97
|
+
have spend a lot of their valuable time providing us with this data. Also, I
|
|
98
|
+
would be interested to hear about your project if you find this repository
|
|
99
|
+
useful, so would appreciate a link/short description e-mailed to me
|
|
100
|
+
(robv@itu.dk).
|
|
101
|
+
|
|
102
|
+
* **aes_dist**:
|
|
103
|
+
```
|
|
104
|
+
@misc{glottolog,
|
|
105
|
+
title = "Glottolog 5.0.",
|
|
106
|
+
author = "Hammarström, Harald and Forkel, Robert and Haspelmath, Martin and Bank, Sebastian",
|
|
107
|
+
year = 2024,
|
|
108
|
+
url = "https://doi.org/10.5281/zenodo.10804357",
|
|
109
|
+
publisher = "Leipzig: Max Planck Institute for Evolutionary Anthropology",
|
|
110
|
+
misc = "Available online at http://glottolog.org, Accessed on 2024-04-24."
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
* **asjp_lev_dist**:
|
|
115
|
+
```
|
|
116
|
+
@misc{ASJP,
|
|
117
|
+
author = {Wichmann and Søren and Holman, Eric W. and Brown, Cecil H.},
|
|
118
|
+
year = {2022},
|
|
119
|
+
title = {The {ASJP} Database (version 20)}
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
* **lang2vec**:
|
|
124
|
+
```
|
|
125
|
+
@inproceedings{littell-etal-2017-uriel,
|
|
126
|
+
title = "{URIEL} and lang2vec: Representing languages as typological, geographical, and phylogenetic vectors",
|
|
127
|
+
author = "Littell, Patrick and
|
|
128
|
+
Mortensen, David R. and
|
|
129
|
+
Lin, Ke and
|
|
130
|
+
Kairis, Katherine and
|
|
131
|
+
Turner, Carlisle and
|
|
132
|
+
Levin, Lori",
|
|
133
|
+
editor = "Lapata, Mirella and
|
|
134
|
+
Blunsom, Phil and
|
|
135
|
+
Koller, Alexander",
|
|
136
|
+
booktitle = "Proceedings of the 15th Conference of the {E}uropean Chapter of the Association for Computational Linguistics: Volume 2, Short Papers",
|
|
137
|
+
month = apr,
|
|
138
|
+
year = "2017",
|
|
139
|
+
address = "Valencia, Spain",
|
|
140
|
+
publisher = "Association for Computational Linguistics",
|
|
141
|
+
url = "https://aclanthology.org/E17-2002",
|
|
142
|
+
pages = "8--14"
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
* **lang_fam**:
|
|
147
|
+
```
|
|
148
|
+
@misc{glottolog,
|
|
149
|
+
title = "Glottolog 5.0.",
|
|
150
|
+
author = "Hammarström, Harald and Forkel, Robert and Haspelmath, Martin and Bank, Sebastian",
|
|
151
|
+
year = 2024,
|
|
152
|
+
url = "https://doi.org/10.5281/zenodo.10804357",
|
|
153
|
+
publisher = "Leipzig: Max Planck Institute for Evolutionary Anthropology",
|
|
154
|
+
misc = "Available online at http://glottolog.org, Accessed on 2024-04-24."
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
* **lang_group**:
|
|
159
|
+
```
|
|
160
|
+
@inproceedings{joshi-etal-2020-state,
|
|
161
|
+
title = "The State and Fate of Linguistic Diversity and Inclusion in the {NLP} World",
|
|
162
|
+
author = "Joshi, Pratik and
|
|
163
|
+
Santy, Sebastin and
|
|
164
|
+
Budhiraja, Amar and
|
|
165
|
+
Bali, Kalika and
|
|
166
|
+
Choudhury, Monojit",
|
|
167
|
+
editor = "Jurafsky, Dan and
|
|
168
|
+
Chai, Joyce and
|
|
169
|
+
Schluter, Natalie and
|
|
170
|
+
Tetreault, Joel",
|
|
171
|
+
booktitle = "Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics",
|
|
172
|
+
month = jul,
|
|
173
|
+
year = "2020",
|
|
174
|
+
address = "Online",
|
|
175
|
+
publisher = "Association for Computational Linguistics",
|
|
176
|
+
url = "https://aclanthology.org/2020.acl-main.560",
|
|
177
|
+
doi = "10.18653/v1/2020.acl-main.560",
|
|
178
|
+
pages = "6282--6293"
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
* **script**:
|
|
183
|
+
```
|
|
184
|
+
@article{kargaran2023glotscript,
|
|
185
|
+
title={GlotScript: A Resource and Tool for Low Resource Writing System Identification},
|
|
186
|
+
author={Kargaran, Amir Hossein and Yvon, Fran{\c{c}}ois and Sch{\"u}tze, Hinrich},
|
|
187
|
+
journal={arXiv preprint arXiv:2309.13320},
|
|
188
|
+
year={2023}
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
* **speakers**:
|
|
193
|
+
```
|
|
194
|
+
@misc{ASJP,
|
|
195
|
+
author = {Wichmann and Søren and Holman, Eric W. and Brown, Cecil H.},
|
|
196
|
+
year = {2022},
|
|
197
|
+
title = {The {ASJP} Database (version 20)}
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
* **wiki_size**:
|
|
202
|
+
```
|
|
203
|
+
https://en.wikipedia.org/wiki/List_of_Wikipedias
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Example output
|
|
207
|
+
```
|
|
208
|
+
rob@cir:/data/rob/lang_dist$ python3 src/distals/distals.py --lang1 fry --lang2 dan
|
|
209
|
+
loading from: ./distals-db.pickle.gz
|
|
210
|
+
7855 languages loaded
|
|
211
|
+
========================================
|
|
212
|
+
Information for fry
|
|
213
|
+
wiki_size: 56,299
|
|
214
|
+
nlp_state: 1. The Scraping-Bys
|
|
215
|
+
speakers: 740,000
|
|
216
|
+
AES: 5. not endangered
|
|
217
|
+
loc: (5.86091, 53.143)
|
|
218
|
+
lang2vec: [1.0, 1.0, 0.0, ..., '--', '--', '--']
|
|
219
|
+
lang2vec_knn: [1.0, 1.0, 0.0, ..., 1.0, 0.0, 0.0]
|
|
220
|
+
grambank: {'GB020': 1, 'GB021': 1, 'GB022': 1, ..., 'GB520': 0, 'GB521': 0, 'GB522': 0}
|
|
221
|
+
glot_tree: ["'Western Frisian [west2354][fry]-l-'", "'Westlauwers-Terschelling Frisian [west2902]'", "'Modern West Frisian [mode1264]'", ..., "'Germanic [germ1287]'", "'Classical Indo-European [clas1257]'", "'Indo-European [indo1319]'"]
|
|
222
|
+
scripts: {'latn'}
|
|
223
|
+
asjp: [['1', 'ik'], ['2', 'do, yo'], ['3', 'vEi'], ..., ['95', 'fol'], ['96', 'nEy, nEi'], ['100', 'nam3']]
|
|
224
|
+
whitespace: 0.160835
|
|
225
|
+
punctuation: 0.031726
|
|
226
|
+
|
|
227
|
+
========================================
|
|
228
|
+
Information for dan
|
|
229
|
+
wiki_size: 307,173
|
|
230
|
+
nlp_state: 3. The Rising Stars
|
|
231
|
+
speakers: 5,510,600
|
|
232
|
+
AES: 5. not endangered
|
|
233
|
+
loc: (9.36284, 54.8655)
|
|
234
|
+
lang2vec: [1.0, 0.0, 0.0, ..., '--', '--', '--']
|
|
235
|
+
lang2vec_knn: [1.0, 0.0, 0.0, ..., 1.0, 0.0, 0.0]
|
|
236
|
+
grambank: {'GB020': 1, 'GB021': 1, 'GB022': 1, ..., 'GB520': 0, 'GB521': 0, 'GB522': 0}
|
|
237
|
+
glot_tree: ["'Danish [dani1285][dan]-l-'", "'South Scandinavian [sout3248]'", "'North Germanic [nort3160]'", "'Northwest Germanic [nort3152]'", "'Germanic [germ1287]'", "'Classical Indo-European [clas1257]'", "'Indo-European [indo1319]'"]
|
|
238
|
+
scripts: {'latn'}
|
|
239
|
+
asjp: [['1', 'yoy'], ['2', 'du'], ['3', 'vi'], ..., ['98', 'ron7'], ['99', 'tE7a'], ['100', 'now7n']]
|
|
240
|
+
whitespace: 0.156298
|
|
241
|
+
punctuation: 0.028514
|
|
242
|
+
|
|
243
|
+
========================================
|
|
244
|
+
Distances between fry and dan (-1 if the feature is not available for both)
|
|
245
|
+
METADATA
|
|
246
|
+
wiki_size: 0.8167
|
|
247
|
+
nlp_state: 0.4000
|
|
248
|
+
speakers: 0.8657
|
|
249
|
+
AES: 0.0000
|
|
250
|
+
loc: 0.0149
|
|
251
|
+
average: 0.5206
|
|
252
|
+
|
|
253
|
+
TYPOLOGY
|
|
254
|
+
lang2vec: 0.1598
|
|
255
|
+
lang2vec_knn: 0.1204
|
|
256
|
+
grambank: 0.0280
|
|
257
|
+
gb_clause: 0.0269
|
|
258
|
+
gb_nominal_domain: 0.0267
|
|
259
|
+
gb_numeral: 0.0353
|
|
260
|
+
gb_pronoun: 0.0000
|
|
261
|
+
gb_verbal_domain: 0.0328
|
|
262
|
+
glot_tree: 0.5325
|
|
263
|
+
scripts: 0.0000
|
|
264
|
+
average: 0.0280
|
|
265
|
+
|
|
266
|
+
WORDLISTS
|
|
267
|
+
asjp: 0.3397
|
|
268
|
+
concepts: 0.0400
|
|
269
|
+
average: 0.1898
|
|
270
|
+
|
|
271
|
+
TEXTBASED
|
|
272
|
+
whitespace: 0.0282
|
|
273
|
+
punctuation: 0.1012
|
|
274
|
+
JSD: 0.1979
|
|
275
|
+
average: 0.1979
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
Coverage:
|
|
280
|
+
```
|
|
281
|
+
7855 language codes found.
|
|
282
|
+
l2v_avg 3910
|
|
283
|
+
l2v_knn 3910
|
|
284
|
+
num_wikiarticles 286
|
|
285
|
+
speakers 5119
|
|
286
|
+
asjp 5581
|
|
287
|
+
glot_tree 7855
|
|
288
|
+
scripts 7393
|
|
289
|
+
state_and_fate 2264
|
|
290
|
+
AES 7718
|
|
291
|
+
loc 7624
|
|
292
|
+
speakers_l 5536
|
|
293
|
+
scripts_l 6425
|
|
294
|
+
conceptualizer 1271
|
|
295
|
+
grambank 2324
|
|
296
|
+
textdata found for 2110 iso-codes
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
## update pip
|
|
300
|
+
python3 setup.py sdist bdist_wheel
|
|
301
|
+
pip3 install dist/distals-0.1-py3-none-any.whl --break-system-packages --force-reinstall
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .distals import Distals
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
|
|
2
|
+
# String distances from the AsjpDist-full program
|
|
3
|
+
# @author: rarakar
|
|
4
|
+
def levenshtein(a,b):
|
|
5
|
+
UNNORM = False
|
|
6
|
+
m=[];la=len(a)+1;lb=len(b)+1
|
|
7
|
+
for i in range(0,la):
|
|
8
|
+
m.append([])
|
|
9
|
+
for j in range(0,lb):m[i].append(0)
|
|
10
|
+
m[i][0]=i
|
|
11
|
+
for i in range(0,lb):m[0][i]=i
|
|
12
|
+
for i in range(1,la):
|
|
13
|
+
for j in range(1,lb):
|
|
14
|
+
s=m[i-1][j-1]
|
|
15
|
+
if (a[i-1]!=b[j-1]):s=s+1
|
|
16
|
+
m[i][j]=min(m[i][j-1]+1,m[i-1][j]+1,s)
|
|
17
|
+
la=la-1;lb=lb-1
|
|
18
|
+
if UNNORM:
|
|
19
|
+
return float(m[la][lb])
|
|
20
|
+
return float(m[la][lb])/float(max(la,lb))
|
|
21
|
+
|
|
22
|
+
def expand_list(data):
|
|
23
|
+
new_data = [None] * 100
|
|
24
|
+
for item in data:
|
|
25
|
+
new_data[int(item[0])-1] = item[-1]
|
|
26
|
+
return new_data
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def collect(all_data, data_folder, langname_utils):
|
|
30
|
+
aspj_lines = open(data_folder + 'lists.txt', encoding='ISO-8859-1').readlines()
|
|
31
|
+
for lineIdx, line in enumerate(aspj_lines):
|
|
32
|
+
if line[0].isupper() and '{' in line:
|
|
33
|
+
|
|
34
|
+
lang_name = line.split('{')[0]
|
|
35
|
+
lang_code = aspj_lines[lineIdx+1].strip().split(' ')[-1]
|
|
36
|
+
lang_code = langname_utils.toISO(lang_code)
|
|
37
|
+
lang_code2 = langname_utils.name_to_iso(lang_name.lower().replace('_', ' '))
|
|
38
|
+
if lang_code == None and lang_code2 == None:
|
|
39
|
+
continue
|
|
40
|
+
if lang_code == None and lang_code2 != None:
|
|
41
|
+
lang_code = lang_code2
|
|
42
|
+
lang_code = langname_utils.toISO(lang_code)
|
|
43
|
+
if lang_code == None:
|
|
44
|
+
continue
|
|
45
|
+
|
|
46
|
+
data = []
|
|
47
|
+
for i in range(100):
|
|
48
|
+
if aspj_lines[lineIdx+2+i][0].isdigit():
|
|
49
|
+
line = aspj_lines[lineIdx+2+i].strip().replace(' //', '')
|
|
50
|
+
tok = line.split()
|
|
51
|
+
num = tok[0]
|
|
52
|
+
en = tok[1]
|
|
53
|
+
aspj_info = ' '.join(tok[2:])
|
|
54
|
+
data.append([num, aspj_info])
|
|
55
|
+
else:
|
|
56
|
+
break
|
|
57
|
+
|
|
58
|
+
all_data[lang_code]['asjp'] = data
|
|
59
|
+
return all_data
|
|
60
|
+
|
|
61
|
+
def distance_metric(data1, data2, key):
|
|
62
|
+
data1 = expand_list(data1)
|
|
63
|
+
data2 = expand_list(data2)
|
|
64
|
+
dists = [[None]*100 for _ in range(100)]
|
|
65
|
+
for idx1, item1 in enumerate(data1):
|
|
66
|
+
for idx2, item2 in enumerate(data2):
|
|
67
|
+
if None not in [item1, item2]:
|
|
68
|
+
# TODO handle multiple items (,)
|
|
69
|
+
all_dists = []
|
|
70
|
+
for item1_alternative in item1.split(', '):
|
|
71
|
+
for item2_alternative in item2.split(', '):
|
|
72
|
+
all_dists.append(levenshtein(item1_alternative, item2_alternative))
|
|
73
|
+
dists[idx1][idx2] = sum(all_dists)/len(all_dists)
|
|
74
|
+
items_ldnd = []
|
|
75
|
+
# get average over all non-matching pairs to normalize for chance
|
|
76
|
+
all_dists = []
|
|
77
|
+
for x in range(100):
|
|
78
|
+
for y in range(100):
|
|
79
|
+
if x != y and dists[x][y] != None:
|
|
80
|
+
all_dists.append(dists[x][y])
|
|
81
|
+
avg_dist = sum(all_dists)/len(all_dists)
|
|
82
|
+
|
|
83
|
+
all_ldnd = []
|
|
84
|
+
for item in range(100):
|
|
85
|
+
if dists[item][item] != None:
|
|
86
|
+
ldn = dists[item][item]
|
|
87
|
+
ldnd = ldn/avg_dist
|
|
88
|
+
all_ldnd.append(ldnd)
|
|
89
|
+
return (sum(all_ldnd)/len(all_ldnd)) / 2
|
|
90
|
+
|