-
Notifications
You must be signed in to change notification settings - Fork 6
/
constants.py
851 lines (729 loc) · 24.6 KB
/
constants.py
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
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
from collections import defaultdict
import economic_indicators
import os
# As of 2020
TOTAL_POPULATION = 7900000000.0
TOTAL_ENG_POPULATION = 510000000.0
population_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/populations/mt_populations_with_noneng.tsv"
#all_population_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/populations/populations.tsv"
all_population_file ="/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/populations/ethnologue_all_populations.tsv"
mt_population_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/populations/ethnologue_mt_populations.tsv"
mtL1_population_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/populations/ethnologue_mt_L1_populations.tsv"
dep_population_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/populations/ethnologue_dep_populations.tsv"
depL1_population_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/populations/ethnologue_dep_L1_populations.tsv"
xnli_population_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/populations/ethnologue_xnli_populations.tsv"
xnliL1_population_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/populations/ethnologue_xnli_L1_populations.tsv"
qa_population_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/populations/ethnologue_qa_populations.tsv"
sdqa_arabic_population_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/populations/ethnologue_sdqa_arabic_populations.tsv"
sdqa_swahili_population_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/populations/ethnologue_sdqa_swahili_populations.tsv"
synthesis_population_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/populations/ethnologue_synthesis_populations.tsv"
sig_population_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/populations/ethnologue_sig_populations.tsv"
sig_isolating_population_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/populations/ethnologue_isolating_populations.tsv"
sigL1_population_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/populations/ethnologue_sig_L1_populations.tsv"
index_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/task_results/MT_index.tsv"
flores_index_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/task_results/flores_index.tsv"
triangulation_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/task_results/triangulated_BLEUS.tsv"
xnli_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/task_results/XNLI.tsv"
qa_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/task_results/QA.tsv"
sdqa_arabic_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/task_results/SDQA_ARABIC.tsv"
sdqa_swahili_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/task_results/SDQA_SWAHILI.tsv"
dep_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/task_results/DEP.tsv"
sig_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/task_results/SIGMORPHON.tsv"
sig_isolating_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/task_results/SIGMORPHON_isolating.tsv"
sig21_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/task_results/SIGMORPHON2021.tsv"
sig20_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/task_results/SIGMORPHON2020.tsv"
sig19_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/task_results/SIGMORPHON2019.tsv"
sig18_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/task_results/SIGMORPHON2018.tsv"
sig17_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/task_results/SIGMORPHON2017.tsv"
sig16_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/task_results/SIGMORPHON2016.tsv"
wilderness_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/task_results/wilderness.tsv"
wilderness_countries_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/populations/wilderness_iso_country.tsv"
literacy_file = "/Users/antonios/desktop/research/PNAS_Fairness/globalutility/experiments/populations/literacy_data.csv"
def read_populations(L1only=False):
# Reads the population file and returns a dictionary
with open(population_file, 'r') as inp:
lines = inp.readlines()
d = {}
for l in lines[1:]:
if l.strip():
l = l.strip().split('\t')
d[l[0]] = float(l[2])/1000000
return d
def read_mt_populations(L1only=False):
# Reads the population file and returns a dictionary
if L1only:
with open(mtL1_population_file, 'r') as inp:
lines = inp.readlines()
else:
with open(mt_population_file, 'r') as inp:
lines = inp.readlines()
d = {}
for l in lines:
if l.strip():
l = l.strip().split('\t')
d[l[0]] = float(l[1])/1000000
return d
def read_dep_populations(L1only=False):
# Reads the population file and returns a dictionary
if L1only:
with open(depL1_population_file, 'r') as inp:
lines = inp.readlines()
else:
with open(dep_population_file, 'r') as inp:
lines = inp.readlines()
d = {}
for l in lines:
if l.strip():
l = l.strip().split('\t')
d[l[0]] = float(l[1])/1000000
return d
def read_xnli_populations(L1only=False):
# Reads the population file and returns a dictionary
if L1only:
with open(xnliL1_population_file, 'r') as inp:
lines = inp.readlines()
else:
with open(xnli_population_file, 'r') as inp:
lines = inp.readlines()
d = {}
for l in lines:
if l.strip():
l = l.strip().split('\t')
d[l[0]] = float(l[1])/1000000
return d
def read_qa_populations(L1only=False):
# Reads the population file and returns a dictionary
with open(qa_population_file, 'r') as inp:
lines = inp.readlines()
d = {}
for l in lines:
if l.strip():
l = l.strip().split('\t')
d[l[0]] = float(l[1])/1000000
return d
def read_sdqa_arabic_populations(L1only=False):
# Reads the population file and returns a dictionary
with open(sdqa_arabic_population_file, 'r') as inp:
lines = inp.readlines()
d = {}
for l in lines:
if l.strip():
l = l.strip().split('\t')
d[l[0]] = float(l[1])/1000000
return d
def read_sdqa_swahili_populations(L1only=False):
# Reads the population file and returns a dictionary
with open(sdqa_swahili_population_file, 'r') as inp:
lines = inp.readlines()
d = {}
for l in lines:
if l.strip():
l = l.strip().split('\t')
d[l[0]] = float(l[1])/1000000
return d
def read_synthesis_populations():
# Reads the population file and returns a dictionary
with open(synthesis_population_file, 'r') as inp:
lines = inp.readlines()
d = {}
for l in lines:
if l.strip():
l = l.strip().split('\t')
d[l[0]] = float(l[1])/1000000
return d
def read_sig_populations(L1only=False, include_isolating=True):
# Reads the population file and returns a dictionary
if L1only:
with open(sigL1_population_file, 'r') as inp:
lines = inp.readlines()
else:
with open(sig_population_file, 'r') as inp:
lines = inp.readlines()
if include_isolating:
with open(sig_isolating_population_file) as inp:
lines += inp.readlines()
d = {}
for l in lines:
if l.strip():
l = l.strip().split('\t')
d[l[0]] = float(l[1])/1000000
return d
def read_noneng_populations():
# Reads the population file and returns a dictionary
with open(population_file, 'r') as inp:
lines = inp.readlines()
disc = {}
for l in lines[1:]:
if l.strip():
l = l.strip().split('\t')
disc[l[0]] = float(l[5])
# Reads the population file and returns a dictionary
with open(mt_population_file, 'r') as inp:
lines = inp.readlines()
d = read_mt_populations()
for l in d:
if l in disc:
d[l] = (1-disc[l])*d[l]
return d
def read_all_populations():
# Synthesis
with open(synthesis_population_file, 'r') as inp:
lines = inp.readlines()
d = {}
for l in lines:
if l.strip():
l = l.strip().split('\t')
d[l[0]] = float(l[1])/1000000
# SIG
with open(sigL1_population_file, 'r') as inp:
lines = inp.readlines()
for l in lines:
if l.strip():
l = l.strip().split('\t')
if l[0] not in d:
d[l[0]] = float(l[1])/1000000
# Dep
with open(depL1_population_file, 'r') as inp:
lines = inp.readlines()
for l in lines:
if l.strip():
l = l.strip().split('\t')
if l[0] not in d:
d[l[0]] = float(l[1])/1000000
# XNLI
with open(xnliL1_population_file, 'r') as inp:
lines = inp.readlines()
for l in lines:
if l.strip():
l = l.strip().split('\t')
if l[0] not in d:
d[l[0]] = float(l[1])/1000000
# MT
with open(mtL1_population_file, 'r') as inp:
lines = inp.readlines()
for l in lines:
if l.strip():
l = l.strip().split('\t')
if l[0] not in d:
d[l[0]] = float(l[1])/1000000
# MT with non-eng file
with open(population_file, 'r') as inp:
lines = inp.readlines()
for l in lines[1:]:
if l.strip():
l = l.strip().split('\t')
if l[0] not in d:
d[l[0]] = float(l[2])/1000000
return d
def read_gdp(languages):
return economic_indicators.read_nominal_gdp(languages)
def read_economic_indicators(languages, ind_type="Import", ind="Top 5 absolute"):
print(f"Came in here! with languages {languages}")
if languages:
if not isinstance(languages, set):
if isinstance(languages[0], tuple):
languages2 = list(sorted(list(set ( [l[0] for l in languages] + [l[1] for l in languages]))))
if 'absolute' in ind:
return economic_indicators.read_absolute_economic_indicators(languages2, ind_type, ind)
else:
return economic_indicators.read_economic_indicators(languages2, ind_type, ind)
else:
languages2 = set(languages)
languages2.add('eng')
languages2 = list(sorted(list(languages2)))
if 'absolute' in ind:
return economic_indicators.read_absolute_economic_indicators(languages2, ind_type, ind)
else:
return economic_indicators.read_economic_indicators(languages2, ind_type, ind)
else:
languages2 = set(languages)
languages2.add('eng')
languages2 = list(sorted(list(languages2)))
if 'absolute' in ind:
return economic_indicators.read_absolute_economic_indicators(languages2, ind_type, ind)
else:
return economic_indicators.read_economic_indicators(languages2, ind_type, ind)
else:
if languages:
l2 = set(languages).add('eng')
else:
l2 = set()
l2.add('eng')
languages2 = list(sorted(list(l2)))
if 'absolute' in ind:
return economic_indicators.read_absolute_economic_indicators(languages2, ind_type, ind)
else:
return economic_indicators.read_economic_indicators(languages2, ind_type, ind)
#raise NotImplementedError("Economic Indicators demand not implemented")
def read_social_media_stats():
raise NotImplementedError("Social Media demand not implemented")
def read_usage_stats():
raise NotImplementedError("Usage demand not implemented")
def get_languages_to_Eng(domains=None):
with open(index_file, 'r') as inp:
lines = inp.readlines()
with open(flores_index_file, 'r') as inp:
lines += inp.readlines()[1:]
languages = set()
for l in lines[1:]:
if l.strip()[0] != '#':
l = l.strip().split('\t')
if l[1] == 'eng' and (l[0] != 'nno'):
if (domains is None) or any([w in domains for w in l[7].strip().split(',')]):
languages.add(l[0])
return sorted(list(languages))
def get_xnli_languages():
with open(xnli_file, 'r') as inp:
lines = inp.readlines()
languages = set()
for l in lines[1:]:
l = l.strip().split('\t')
languages.add(l[0])
return sorted(list(languages))
def get_qa_languages():
with open(qa_file, 'r') as inp:
lines = inp.readlines()
languages = set()
for l in lines[1:]:
l = l.strip().split('\t')
languages.add(l[0])
return sorted(list(languages))
def get_sdqa_arabic_languages():
with open(sdqa_arabic_file, 'r') as inp:
lines = inp.readlines()
languages = set()
for l in lines[1:]:
l = l.strip().split('\t')
languages.add(l[0])
return sorted(list(languages))
def get_sdqa_swahili_languages():
with open(sdqa_swahili_file, 'r') as inp:
lines = inp.readlines()
languages = set()
for l in lines[1:]:
l = l.strip().split('\t')
languages.add(l[0])
return sorted(list(languages))
def get_dep_languages():
with open(dep_file, 'r') as inp:
lines = inp.readlines()
languages = set()
for l in lines[1:]:
l = l.strip().split('\t')
languages.add(l[0])
return sorted(list(languages))
def get_sig_languages(include_isolating=True):
with open(sig_file, 'r') as inp:
lines = inp.readlines()
with open(sig16_file , 'r') as inp:
lines2 = inp.readlines()
with open(sig17_file , 'r') as inp:
lines2 += inp.readlines()
with open(sig18_file , 'r') as inp:
lines2 += inp.readlines()
with open(sig19_file , 'r') as inp:
lines2 += inp.readlines()
with open(sig21_file , 'r') as inp:
lines2 += inp.readlines()
if include_isolating:
with open(sig_isolating_file , 'r') as inp:
lines2 += inp.readlines()
languages = set()
for l in lines[1:]+lines2:
l = l.strip().split('\t')
languages.add(l[0])
return sorted(list(languages))
def get_all_languages():
# SIG
with open(sig_file, 'r') as inp:
lines = inp.readlines()
with open(sig16_file , 'r') as inp:
lines2 = inp.readlines()
with open(sig17_file , 'r') as inp:
lines2 += inp.readlines()
with open(sig18_file , 'r') as inp:
lines2 += inp.readlines()
with open(sig19_file , 'r') as inp:
lines2 += inp.readlines()
with open(sig21_file , 'r') as inp:
lines2 += inp.readlines()
with open(sig_isolating_file , 'r') as inp:
lines2 += inp.readlines()
languages = set()
for l in lines[1:]+lines2:
l = l.strip().split('\t')
languages.add(l[0])
# DepParse
with open(dep_file, 'r') as inp:
lines = inp.readlines()
for l in lines[1:]:
l = l.strip().split('\t')
languages.add(l[0])
# XNLI
with open(xnli_file, 'r') as inp:
lines = inp.readlines()
for l in lines[1:]:
l = l.strip().split('\t')
languages.add(l[0])
# QA
with open(qa_file, 'r') as inp:
lines = inp.readlines()
for l in lines[1:]:
l = l.strip().split('\t')
languages.add(l[0])
# MT2Eng
with open(index_file, 'r') as inp:
lines = inp.readlines()
with open(flores_index_file, 'r') as inp:
lines += inp.readlines()[1:]
for l in lines[1:]:
if l.strip()[0] != '#':
l = l.strip().split('\t')
if l[1] == 'eng' and (l[0] != 'nno'):
languages.add(l[0])
# MTfrom Eng
with open(index_file, 'r') as inp:
lines = inp.readlines()
with open(flores_index_file, 'r') as inp:
lines += inp.readlines()[1:]
for l in lines[1:]:
if l.strip()[0] != '#':
l = l.strip().split('\t')
if l[0] == 'eng':
languages.add(l[1])
# Wilderness
with open(wilderness_file, 'r') as inp:
lines = inp.readlines()
for l in lines[1:]:
l = l.strip().split('\t')
languages.add(l[1])
return sorted(list(languages))
def get_languages_from_Eng(domains=None):
with open(index_file, 'r') as inp:
lines = inp.readlines()
with open(flores_index_file, 'r') as inp:
lines += inp.readlines()[1:]
languages = set()
for l in lines[1:]:
if l.strip()[0] != '#':
l = l.strip().split('\t')
if l[0] == 'eng':
if (domains is None) or any([w in domains for w in l[7].strip().split(',')]):
languages.add(l[1])
return sorted(list(languages))
def get_mt_languages(domains=None):
with open(index_file, 'r') as inp:
lines = inp.readlines()
with open(flores_index_file, 'r') as inp:
lines += inp.readlines()[1:]
languages = set()
for l in lines[1:]:
if l.strip()[0] != '#' :
l = l.strip().split('\t')
if (l[0] != 'nno'):
languages.add(l[0])
languages.add(l[1])
return sorted(list(languages))
def get_all_language_pairs(domains=None):
with open(index_file, 'r') as inp:
lines = inp.readlines()
with open(flores_index_file, 'r') as inp:
lines += inp.readlines()[1:]
languages = set()
for l in lines[1:]:
if l.strip()[0] != '#':
l = l.strip().split('\t')
if (domains is None) or any([w in domains for w in l[7].strip().split(',')]):
languages.add((l[0],l[1]))
return sorted(list(languages))
def get_wilderness_languages():
with open(wilderness_file, 'r') as inp:
lines = inp.readlines()
languages = set()
for l in lines[1:]:
l = l.strip().split('\t')
languages.add(l[1])
return sorted(list(languages))
def read_wilderness():
with open(wilderness_file, 'r') as inp:
lines = inp.readlines()
d = defaultdict(lambda:0)
for l in lines[1:]:
l = l.strip().split('\t')
iso = l[1]
val = float(l[9])
if iso == "eng":
val = 3.5
if iso == "cmn":
val -= 1
d[iso] = val
return d
def read_wilderness_countries():
with open(wilderness_countries_file, 'r') as inp:
lines = inp.readlines()
d = defaultdict(lambda:0)
for l in lines:
l = l.strip().split('\t')
iso = l[0]
val = l[1]
d[iso] = val
return d
def read_iliteracy_pop():
with open(literacy_file, 'r') as inp:
lines = inp.readlines()
d = defaultdict(lambda:0)
for l in lines[1:]:
try:
l = l.strip().split('\t')
country = l[0]
illiteracy = 100 - float(l[1])
pop = float(l[2])*100/1000000.0
d[country] = (illiteracy * pop, illiteracy)
except:
pass
return d
def read_BLEUs(domains=None):
with open(index_file, 'r') as inp:
lines = inp.readlines()
with open(flores_index_file, 'r') as inp:
lines += inp.readlines()[1:]
d = defaultdict(lambda:0)
for l in lines[1:]:
if l.strip() and l.strip()[0] != '#':
l = l.strip().split('\t')
if domains:
if any( [w in domains for w in l[7].strip().split(',')] ):
d[l[0],l[1]] = max(float(l[2]), d[l[0],l[1]])
else:
d[l[0],l[1]] = max(float(l[2]), d[l[0],l[1]])
return d
def read_BLEUs_by_year(year=2019):
year = f"{int(year)}"
shortyear = year[-2:]
with open(index_file, 'r') as inp:
lines = inp.readlines()
if year == '2021':
with open(flores_index_file, 'r') as inp:
lines = inp.readlines()
d = defaultdict(lambda:0)
for l in lines[1:]:
if l.strip() and l.strip()[0] != '#':
l = l.strip().split('\t')
if (year in l[4]) or (year in l[5]) or (year in l[6]):
d[l[0],l[1]] = max(float(l[2]), d[l[0],l[1]])
elif year == '2019' and l[6].strip() == 'internal':
d[l[0],l[1]] = max(float(l[2]), d[l[0],l[1]])
elif 'arxiv' in l[4]:
temp = l[4].split('/')[-1][:2]
if temp == shortyear:
d[l[0],l[1]] = max(float(l[2]), d[l[0],l[1]])
elif 'anthology' in l[4]:
temp = l[4].split('/')[-1][1:3]
if temp == shortyear:
d[l[0],l[1]] = max(float(l[2]), d[l[0],l[1]])
if '2020.acl-main' in l[4] and year == '2020':
d[l[0],l[1]] = max(float(l[2]), d[l[0],l[1]])
elif year=='2021' and ('FLORES' in l[3]):
d[l[0],l[1]] = max(float(l[2]), d[l[0],l[1]])
return d
def read_triangulated_BLEUs():
with open(triangulation_file, 'r') as inp:
lines = inp.readlines()
d = defaultdict(lambda:0)
for l in lines:
if l.strip() and l.strip()[0] != '#':
l = l.strip().split('\t')
d[l[0],l[1]] = max(float(l[2]), d[l[0],l[1]])
return d
def read_dep(metric='uas', system='udp'):
with open(dep_file, 'r') as inp:
lines = inp.readlines()
d = defaultdict(lambda:0)
for l in lines[1:]:
if l.strip():
l = l.strip().split('\t')
if metric == 'uas':
if system == 'udp':
d[l[0]] = float(l[1])
elif system == 'udf':
d[l[0]] = float(l[3])
elif metric == 'las':
if system == 'udp':
d[l[0]] = float(l[2])
elif system == 'udf':
d[l[0]] = float(l[4])
return d
def read_sig(year='all',system='CULing-01-0',include_isolating=True):
d = defaultdict(lambda:0)
if year == '21' or year=='all':
with open(sig21_file, 'r') as inp:
lines = inp.readlines()
for l in lines:
if l.strip():
l = l.strip().split('\t')
#print(l)
if float(l[1])/100 > d[l[0]]:
d[l[0]] = float(l[1])/100
if year == '20' or year=='all':
with open(sig_file, 'r') as inp:
lines = inp.readlines()
for l in lines[1:]:
if l.strip():
l = l.strip().split('\t')
if system == 'CULing-01-0':
d[l[0]] = float(l[1])
elif system == 'deepspin-02-1':
d[l[0]] = float(l[2])
elif system == 'uiuc-01-0':
d[l[0]] = float(l[3])
elif system == 'any':
d[l[0]] = max(float(l[3]), float(l[2]), float(l[1]))
if year == '19' or year=='all':
with open(sig19_file, 'r') as inp:
lines = inp.readlines()
for l in lines:
if l.strip():
l = l.strip().split('\t')
#print(l)
if float(l[1])/100 > d[l[0]]:
d[l[0]] = float(l[1])/100
if year == '18' or year=='all':
with open(sig18_file, 'r') as inp:
lines = inp.readlines()
for l in lines:
if l.strip():
l = l.strip().split('\t')
if float(l[1])/100 > d[l[0]]:
d[l[0]] = float(l[1])/100
if year == '17' or year=='all':
with open(sig17_file, 'r') as inp:
lines = inp.readlines()
for l in lines:
if l.strip():
l = l.strip().split('\t')
if float(l[1])/100 > d[l[0]]:
d[l[0]] = float(l[1])/100
if year == '16' or year=='all':
with open(sig16_file, 'r') as inp:
lines = inp.readlines()
for l in lines:
if l.strip():
l = l.strip().split('\t')
if float(l[1])/100 > d[l[0]]:
d[l[0]] = float(l[1])/100
if include_isolating:
with open(sig_isolating_file, 'r') as inp:
lines = inp.readlines()
for l in lines:
if l.strip():
l = l.strip().split('\t')
if float(l[1]) > d[l[0]]:
d[l[0]] = float(l[1])
return d
def read_human_evals(domains=None):
raise NotImplementedError("No data on human evals so not implemented")
def read_post_editing_evals(domains=None):
raise NotImplementedError("No data on post-editing evals so not implemented")
def read_xnli_acc():
with open(xnli_file, 'r') as inp:
lines = inp.readlines()
d = defaultdict(lambda:0)
for l in lines[1:]:
l = l.strip().split('\t')
d[l[0]] = float(l[1])
return d
read_XNLI_acc = read_xnli_acc
def read_qa_acc():
with open(qa_file, 'r') as inp:
lines = inp.readlines()
d = defaultdict(lambda:0)
for l in lines[1:]:
l = l.strip().split('\t')
d[l[0]] = float(l[1])
#print(d)
return d
read_QA_acc = read_qa_acc
def read_sdqa_arabic_acc():
with open(sdqa_arabic_file, 'r') as inp:
lines = inp.readlines()
d = defaultdict(lambda:0)
for l in lines[1:]:
l = l.strip().split('\t')
d[l[0]] = float(l[1])
return d
read_SDQA_arabic_acc = read_sdqa_arabic_acc
def read_sdqa_swahili_acc():
with open(sdqa_swahili_file, 'r') as inp:
lines = inp.readlines()
d = defaultdict(lambda:0)
for l in lines[1:]:
l = l.strip().split('\t')
d[l[0]] = float(l[1])
return d
read_SDQA_swahili_acc = read_sdqa_swahili_acc
def read_number_of_papers(domains=None):
with open(index_file, 'r') as inp:
lines = inp.readlines()
d = defaultdict(lambda:0)
for l in lines[1:]:
if l.strip() and l[0].strip()!='#':
l = l.strip().split('\t')
if domains:
if any( [w in domains for w in l[7].strip().split(',')] ):
d[l[0],l[1]] += 1
else:
d[l[0],l[1]] += 1
return d
def read_number_of_internal_papers(domains=None):
with open(index_file, 'r') as inp:
lines = inp.readlines()
d = defaultdict(lambda:0)
for l in lines[1:]:
if l.strip():
l = l.strip().split('\t')
if len(l) > 3:
if domains:
if any( [w in domains for w in l[7].strip().split(',')] ) and l[6].strip()=='internal':
d[l[0],l[1]] += 1
elif l[6].strip()=='internal':
d[l[0],l[1]] += 1
return d
def triangulate(acc):
# First recover all the languages
alllangs = set( [ l[0] for l in acc ] + [ l[1] for l in acc ] + ['eng'] )
# Store original dict
original_dict = defaultdict(lambda:0)
for key in acc:
original_dict[key] = acc[key]
# For storing the pivot
pivot = {}
for l1 in alllangs:
for l2 in alllangs:
pivot[l1,l2] = []
#Pivot once
for l1 in alllangs:
for l2 in alllangs:
for l3 in alllangs:
if l1 != l2 and l2 != l3:
if original_dict[l1,l2] < original_dict[l1,l3] * original_dict[l3,l2]:
acc[l1,l2] = original_dict[l1,l3] * original_dict[l3,l2]
pivot[l1,l2] = [l3]
#Pivot twice
for l1 in alllangs:
for l2 in alllangs:
for l3 in alllangs:
for l4 in alllangs:
if l1 != l2 and l2 != l3 and l3 != l4:
if acc[l1,l2] < original_dict[l1,l3] * original_dict[l3,l4] * original_dict[l4,l2]:
# Weird because normalizing does the last operation when recovering it. TO DO
acc[l1,l2] = original_dict[l1,l3] * original_dict[l3,l4] * original_dict[l4,l2]
pivot[l1,l2] = [l3,l4]
#Pivot once through estimates
#pivot = {}
for l1 in alllangs:
for l2 in alllangs:
for l3 in alllangs:
if l1 != l2 and l2 != l3:
if acc[l1,l2] < acc[l1,l3] * acc[l3,l2]:
acc[l1,l2] = acc[l1,l3] * acc[l3,l2]
pivot[l1,l2] = pivot[l1,l3] + [l3] + pivot[l3,l2]