-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
879 lines (753 loc) · 35 KB
/
index.html
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
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Tokenizer unfairness</title>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-KJSCYM1NRV"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-KJSCYM1NRV');
</script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.25/datatables.min.css" />
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.2.0/css/bootstrap.min.css"
rel="stylesheet" />
<link href="https://cdn.datatables.net/1.13.4/css/dataTables.bootstrap5.min.css" rel="stylesheet" />
<meta name="theme-color" content="#712cf9">
<link rel="shortcut icon" type="image/png" href="favicon.png"/>
<style>
.bd-placeholder-img {
font-size: 1.125rem;
text-anchor: middle;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}
@media (min-width: 768px) {
.bd-placeholder-img-lg {
font-size: 3.5rem;
}
}
.b-example-divider {
width: 100%;
height: 3rem;
background-color: rgba(0, 0, 0, .1);
border: solid rgba(0, 0, 0, .15);
border-width: 1px 0;
box-shadow: inset 0 .5em 1.5em rgba(0, 0, 0, .1), inset 0 .125em .5em rgba(0, 0, 0, .15);
}
.b-example-vr {
flex-shrink: 0;
width: 1.5rem;
height: 100vh;
}
.bi {
vertical-align: -.125em;
fill: currentColor;
}
.nav-scroller {
position: relative;
z-index: 2;
height: 2.75rem;
overflow-y: hidden;
}
.nav-scroller .nav {
display: flex;
flex-wrap: nowrap;
padding-bottom: 1rem;
margin-top: -1px;
overflow-x: auto;
text-align: center;
white-space: nowrap;
-webkit-overflow-scrolling: touch;
}
.btn-bd-primary {
--bd-violet-bg: #712cf9;
--bd-violet-rgb: 112.520718, 44.062154, 249.437846;
--bs-btn-font-weight: 600;
--bs-btn-color: var(--bs-white);
--bs-btn-bg: var(--bd-violet-bg);
--bs-btn-border-color: var(--bd-violet-bg);
--bs-btn-hover-color: var(--bs-white);
--bs-btn-hover-bg: #6528e0;
--bs-btn-hover-border-color: #6528e0;
--bs-btn-focus-shadow-rgb: var(--bd-violet-rgb);
--bs-btn-active-color: var(--bs-btn-hover-color);
--bs-btn-active-bg: #5a23c8;
--bs-btn-active-border-color: #5a23c8;
}
.bd-mode-toggle {
z-index: 1500;
}
.text {
font-size: 2em;
overflow-wrap: break-word;
}
table {
font-size: smaller;
}
.token {
padding: 0 0.02em;
margin: 0;
font-size: 1em;
position: relative;
}
.token-text {
/* display: none; */
/* content: ""; */
white-space: pre-wrap;
/* position: absolute; */
font-size: 2em;
/* font-weight: bold; */
/* text-transform: uppercase; */
position: relative;
padding-left: 0.0em;
padding-right: 0.0em;
margin: 0em;
height: 5em;
}
.separator {
font-size: 0
}
.example {
width: 50%;
font-family: "Noto Sans Mono", monospace;
}
.text-container .tokens-container .tokens-token-text {
width: fit-content;
font-family: "Noto Sans Mono", monospace;
}
.dataTables_filter {
display: none;
}
.white_glow {
text-shadow: 0px 0px 0.1em #fff, 0px 0px 0.1em #fff, 0px 0px 0.1em #fff, 0px 0px 0.1em #fff;
}
/* .heading_bg {
background-image: url('assets/bg_small.jpeg');
background-size: cover;
} */
@media (min-width: 576px) {
.make-it-flex {
display: flex;
flex-wrap: wrap;
}
.flex-item-1 {
order: 1;
}
.flex-item-2 {
order: 2;
}
.flex-item-3 {
order: 3;
}
.flex-item-4 {
order: 4;
}
.flex-item-5 {
order: 5;
}
.flex-item-6 {
order: 6;
}
.flex-item-7 {
order: 7;
}
.flex-item-8 {
order: 8;
}
}
.author-block {
display: inline-block;
}
.dt-left {
text-align: left;
}
.dt-right {
text-align: right;
}
.arxiv-link {
/* display: flex; */
align-items: center;
}
.arxiv-logo {
height: 2em;
/* Adjust the logo size as needed */
margin-left: 10px;
/* Add some space between the logo and the text */
align-items: center;
}
.no-right-margin {
margin-right: 0px;
}
.no-left-margin {
margin-left: 0px;
}
</style>
</head>
<body>
<div class="px-4 py-5 overflow-hidden heading_bg text-center">
<h1 class="col-lg-8 mx-auto mb-4 display-5 fw-bold text-body-emphasis white_glow">
Language Model Tokenizers Introduce Unfairness Between Languages</h1>
<div class="col-lg-12 mx-auto">
<p class="lead mb-12">Conference on Neural Information Processing Systems (NeurIPS) 2023</p>
</div>
<div class="col-lg-6 mx-auto">
<p class="lead mb-4"><b>
<span class="author-block">
<a href="https://p-petrov.com/">Aleksandar Petrov</a><sup>1,2</sup>,
</span>
<span class="author-block">
<a href="https://www.cs.ox.ac.uk/people/emanuele.lamalfa/">Emanuele La Malfa</a><sup>1</sup>,
</span>
<span class="author-block"><a href="https://torrvision.com/">Philip H.S. Torr</a><sup>2</sup></span>
<span class="author-block"><a href="https://www.adelbibi.com/">Adel Bibi</a><sup>2</sup>,</span>
</p>
</div>
<div class="col-lg-6 mx-auto">
<p class="lead mb-4 text-muted">
<span class="author-block"><sup>1</sup>Department of Computer Science,</span> <span class="author-block">University of Oxford</span>
<span class="author-block"><sup>2</sup>Department of Engineering Science,</span> <span class="author-block">University of Oxford</span>
</b>
</div>
</div>
<div class="b-example-divider"></div>
<div class="container no-right-margin">
<!-- <div class="row p-4 pb-0 pe-lg-0 pt-lg-5 align-items-center rounded-3 border shadow-lg"> -->
<div class="row align-items-center">
<div class="col-lg-7 p-3 p-lg-5 pt-lg-3">
<h1 class="display-4 fw-bold lh-1 text-body-emphasis">Modern language models can speak many languages...
</h1>
<p class="lead">
It is impressive that language models can understand many different languages, even some
lower-resource ones, especially considering that most of them were built targeting solely English
text.
However, unsurprisingly, their performance varies greatly across languages: models show much better
command in their target language.
</p>
</div>
<div class="col-lg-4 offset-lg-1 p-0 overflow-hidden">
<img class="rounded-lg-3" src="assets/chat_example.jpeg" alt="Example text in different languages"
width="720">
</div>
</div>
</div>
<div class="b-example-divider"></div>
<div class="container no-left-margin">
<!-- <div class="row pl-4 pb-0 pe-lg-0 pt-lg-5 align-items-center rounded-3 border shadow-lg"> -->
<div class="row align-items-center ">
<div class="col-lg-4 p-0 overflow-hidden">
<img class="rounded-lg-3" src="assets/tokenization_diff.jpg" alt="Example text in different languages"
width="720">
</div>
<div class="col-lg-7 offset-lg-1 p-3 p-lg-5 pt-lg-3">
<h1 class="display-4 fw-bold lh-1 text-body-emphasis">But they are treated drastically differently
already at the tokenization stage</h1>
<p class="lead">
The tokenization lengths for some lanugages can be more than 15 times longer than English.
This results in some language communities having much larger cost of accessing API-based services
(which often charge per token), processing times and latency, and smaller amount of content that can
be provided as context.
</p>
</div>
</div>
</div>
<div class="b-example-divider"></div>
<div class="px-4 pt-5 my-5">
<h1 class="col-lg-6 mx-auto fw-bold text-body-emphasis">See for yourself</h1>
<div class="col-lg-6 mx-auto">
<p class="lead mb-4">
Select the languages and models you want to compare and see how they differ in tokenization length.
The tokenization length is computed over 2000 sentences from the <a
href="https://github.com/facebookresearch/flores">FLORES-200</a> parallel corpus.
You can also change which language is used to normalize the tokenization lengths.
</p>
</div>
<div class="col-lg-6 mx-auto mb-5">
<div class="row mb-3">
<label for="row-selector" class="form-label col-sm-4 col-form-label">Select your languages:</label>
<div class="col-sm-8">
<select id="row-selector" class="js-example-basic-multiple" style="width: 100%" multiple>
</select>
</div>
</div>
<div class="row mb-3 ">
<label for="col-selector" class="form-label col-sm-4 col-form-label">Select your models:</label>
<div class="col-sm-8">
<select id="col-selector" class="js-example-basic-multiple" style="width: 100%;" multiple>
</select>
</div>
</div>
<div class="row mb-5 align-items-center">
<label for="base-language-selector" class="form-label col-sm-8 col-form-label">Language to measure
tokenization lengths against:</label>
<div class="col-sm-4">
<select id="base-language-selector" class="js-example-basic" style="width: 100%;">
</select>
</div>
</div>
</div>
<div class="col-lg-6 mx-auto">
<div class="row text-end">
<p class="text-muted ">
*For the tokenization premiums for ChatGPT and GPT-4 refer to the <b>cl100k_base</b> tokenizer.
</p>
</div>
</div>
<div class="row">
<table id="myTable" class="display">
<thead>
<tr>
<th></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<div class="col-lg-6 mx-auto mb-5">
<div class="row text-end">
<p class="text-muted ">
Missing a tokenizer? Add it with a pull request <a
href="https://github.com/AleksandarPetrov/tokenization-fairness">here</a>.
</p>
</div>
</div>
</div>
<div class="b-example-divider"></div>
<div class="px-4 pt-5 my-5">
<h1 class="col-lg-6 mx-auto fw-bold text-body-emphasis">Compare tokenization of sentences</h1>
<div class="col-lg-6 mx-auto">
<p class="lead mb-4">
You can compare the tokenization of the same sentences across languages and tokenizers.
The sentences are selected from the <a href="https://github.com/facebookresearch/flores">FLORES-200</a>
parallel corpus.
</p>
</div>
<div class="col-lg-6 mx-auto mb-5">
<div class="row justify-content-center mb-2">
<div class="col-xs-12 col-sm-6">
<label for="example-tokenizer-selector" class="form-label">Pick tokenizer:</label>
</div>
<div class="col-xs-12 col-sm-6">
<select id="example-tokenizer-selector" class="js-example-basic dropdown-menu">
</select>
</div>
</div>
<div class="row justify-content-center">
<div class="col-12">
<label for="sentence-selector" class="form-label">Scroll for other example sentences:</label>
</div>
<div class="col-10">
<input type="range" class="form-range" min="0" max="9" id="sentence-selector" value=5>
</div>
</div>
</div>
<div class="row make-it-flex">
<div class="col-xs-12 col-sm-6 flex-item-1 mb-3">
<div class="form-floating example">
<select class="form-select selectpicker" id="languageL" aria-label="Select language" data-live-search="true"></select>
<label for="languageL">Select language:</label>
</div>
</div>
<div class="col-xs-12 col-sm-6 flex-item-3 mb-2">
<small class="text-muted">Sentence:</small>
<div id="exampleL-text" class="text-container"></div>
</div>
<div class="col-xs-12 col-sm-6 flex-item-5 mb-2">
<small class="text-muted" id="exampleL-ntokens">X Tokens, Y% Unknown:</small>
<div id="exampleL-token-text" class="tokens-token-text"></div>
</div>
<div class="col-xs-12 col-sm-6 flex-item-7 mb-5">
<small class="text-muted">Token IDs:</small>
<div id="exampleL-tokens" class="tokens-container"></div>
<div class="ml-auto col-auto"></div>
</div>
<div class="col-xs-12 col-sm-6 flex-item-2 mb-3">
<div class="form-floating example">
<select class="form-select" id="languageR" aria-label="Select language"></select>
<label for="languageR">Select language:</label>
</div>
</div>
<div class="col-xs-12 col-sm-6 flex-item-4 mb-2">
<small class="text-muted">Sentence:</small>
<div id="exampleR-text" class="text-container"></div>
</div>
<div class="col-xs-12 col-sm-6 flex-item-6 mb-2">
<small class="text-muted" id="exampleR-ntokens">X Tokens, Y% Unknown:</small>
<div id="exampleR-token-text" class="tokens-token-text"></div>
</div>
<div class="col-xs-12 col-sm-6 flex-item-8 mb-2">
<small class="text-muted">Token IDs:</small>
<div id="exampleR-tokens" class="tokens-container"></div>
</div>
</div>
</div>
<div class="b-example-divider"></div>
<div class="container col-xxl-8 px-4 py-5">
<div class="row">
<h1 class="display-5 fw-bold text-body-emphasis lh-1 mb-3">
For more details, read our paper:
</h1>
</div>
<div class="row g-5 py-5">
<div class="col-lg-6">
<h3 class="display-8 fw-bold text-body-emphasis lh-1 mb-3">
Language Model Tokenizers Introduce Unfairness Between Languages
</h3>
<h5 class="display-8 lh-1 mb-3 text-muted">
<span class="author-block">
<a href="https://p-petrov.com/">Aleksandar Petrov</a>,
</span>
<span class="author-block">
<a href="https://www.cs.ox.ac.uk/people/emanuele.lamalfa/">Emanuele La Malfa</a>,
</span>
<span class="author-block"><a href="https://torrvision.com/">Philip H.S. Torr</a></span>
<span class="author-block"><a href="https://www.adelbibi.com/">Adel Bibi</a>,</span>
</h5>
<p><em>
Recent language models have shown impressive multilingual performance, even when not explicitly trained for it.
Despite this, concerns have been raised about the quality of their outputs across different languages.
In this paper, we show how disparity in the treatment of different languages arises at the tokenization stage, well before a model is even invoked.
The same text translated into different languages can have drastically different tokenization lengths, with differences up to 15 times in some cases.
These disparities persist across the 17 tokenizers we evaluate, even if they are intentionally trained for multilingual support.
Character-level and byte-level models also exhibit over 4 times the difference in the encoding length for some language pairs.
This induces unfair treatment for some language communities in regard to the cost of accessing commercial language services, the processing time and latency, as well as the amount of content that can be provided as context to the models.
Therefore, we make the case that we should train future language models using multilingually fair tokenizers.
</em></p>
</div>
<div class="col-lg-6 center-block ">
<div class="container">
<div class="row align-items-center">
<button onclick="window.open('https://arxiv.org/abs/2305.15425', '_blank')"
class="btn btn-danger">
<h3>Read the paper
on
<img src="assets/arxiv-logo-one-color-white.svg" alt="arXiv Logo" class="arxiv-logo">
</h3>
</button>
</div>
<div class="card mt-4">
<div class="card-body">
<h5 class="card-title">Cite as:</h5>
<pre>@inproceedings{petrov2023token_unfairness,
title = {Language Model Tokenizers Introduce Unfairness Between Languages},
author = {Petrov, Aleksandar and La Malfa, Emanuele and H. S. Torr, Philip and Bibi, Adel},
booktitle = {Advances in Neural Information Processing Systems},
url = {https://arxiv.org/abs/2305.15425},
year = {2023}
}</pre>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.25/datatables.min.js"></script>
<script type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.3.0/papaparse.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js"></script>
<script src="https://cdn.datatables.net/1.13.4/js/dataTables.bootstrap5.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
// Load the data from the CSV file
$.get("assets/tokenization_lengths_validated.csv", async = false, function (data) {
// Parse the CSV data into an array of objects
var dataArray = Papa.parse(data, {
header: true,
skipEmptyLines: true
}).data;
// Get the column names from the first row of data
var columnNames = Object.keys(dataArray[0]);
var tokenizerNames = columnNames.slice(1).sort();
// Generate the DataTable columns based on the column names
var tableColumns = columnNames.map(function (columnName, index) {
if (index > 0) {
var align = "dt-right";
} else {
var align = "dt-left";
}
return { data: columnName, title: columnName, className: align };
});
// Update the number of columns in the table
var table_body = document.getElementById("myTable");
if (columnNames.length !== table_body.rows[0].cells.length) {
// Update the number of columns in the table
while (table_body.rows[0].cells.length < columnNames.length) {
const cell = table_body.rows[0].insertCell(-1);
cell.outerHTML = "<th style='max-width:100%; white-space:nowrap;'>New Column</th>";
}
while (table_body.rows[0].cells.length > columnNames.length) {
table_body.rows[0].deleteCell(-1);
}
}
// Initialize the DataTable
function init_table(dataArray) {
return $('#myTable').DataTable({
data: dataArray,
columns: tableColumns,
paging: false,
searching: true,
language: {
info: '',
infoEmpty: '',
infoFiltered: '',
zeroRecords: 'No records found'
},
"bDestroy": true
});
}
var table = init_table(dataArray);
// Get the data for the first column (assumes that the first column contains unique IDs for each row)
var rowsData = table.column(0).data().toArray();
// Get the dropdown element
var dropdown_row = $('#row-selector');
var dropdown_col = $('#col-selector');
var dropdown_base = $('#base-language-selector');
dropdown_row.select2();
dropdown_col.select2();
dropdown_base.select2();
// Add an option for each row
rowsData.forEach(function (rowId) {
var option = $('<option value="' + rowId + '">' + rowId + '</option>');
dropdown_row.append(option);
});
rowsData.forEach(function (rowId) {
var option = $('<option value="' + rowId + '">' + rowId + '</option>');
dropdown_base.append(option);
});
tokenizerNames.forEach(function (colId) {
var option = $('<option value="' + colId + '">' + colId + '</option>');
dropdown_col.append(option);
});
$.fn.dataTable.ext.search.push(function (settings, data, dataIndex) {
var selectedRowIds = dropdown_row.val();
var rowId = data[0]; // Assuming the row ID is in the first column
if (selectedRowIds.includes(rowId)) {
return true;
}
return false;
});
// Handle changes to the dropdown and checkboxes
dropdown_row.on('change', function () {
table.draw();
});
dropdown_col.on('change', function () {
var originalWidth = document.getElementById("myTable").style.width;
table.columns().header().each(function (columnHeader, index) {
var caption = $(columnHeader).text();
var columnVisible = dropdown_col.val().indexOf(caption) !== -1;
if (index > 0) {
table.column(index).visible(columnVisible);
}
});
table.draw();
table.columns.adjust();
document.getElementById("myTable").width = "1%";
document.getElementById("myTable").style.width = "1%";
});
// Select a default subset of the options
dropdown_row.val([
'Bulgarian',
// 'Burmese',
'Chinese (Simplified)',
'Dzongkha',
'English',
'French',
'German',
'Italian',
'Japanese',
// 'Maori',
// 'Pangasinan',
'Portuguese',
// 'Romanian',
// 'Santali',
'Shan',
'Spanish',
'Standard Arabic',
// 'Tumbuka',
'Vietnamese'
]).trigger('change');
// Function to divide rows of the table
function divideDicts(dict1, dict2) {
const result = {};
for (let key in dict1) {
if (key == "Language") {
result[key] = dict1[key];
continue;
}
if (!dict1.hasOwnProperty(key) || !dict2.hasOwnProperty(key)) {
continue;
}
const val1 = dict1[key];
const val2 = dict2[key];
if (!isNaN(Number(val1)) && !isNaN(Number(val2)) && Number(val2) !== 0) {
result[key] = (parseFloat(val1) / parseFloat(val2)).toFixed(2);
} else {
result[key] = "—";
}
}
return result;
}
// Update the table when the base language changes
dropdown_base.on('change', function () {
// Reset the table data
table = init_table(dataArray);
// Find the row matching the selected base language
var matchingRowId = null;
var rowData = null;
table.rows().every(function (rowIdx, tableLoop, rowLoop) {
rowData = table.row(rowIdx).data();
if (rowData['Language'] === dropdown_base.val()) {
matchingRowId = rowIdx;
return false; // exit the loop early if we find a match
}
});
var divisionRow = table.row(matchingRowId).data();
// Loop through each row of the table
table.rows().every(function (rowIdx, tableLoop, rowLoop) {
if (rowIdx > 0) {
// Get the row data
var rowData = this.data();
this.data(divideDicts(rowData, divisionRow));
};
});
table.draw();
dropdown_col.trigger('change');
});
dropdown_base.val("English").trigger('change');
dropdown_col.val([
"GPT-2",
"cl100k_base",
"RoBERTa",
"XLM-RoBERTa",
// "M2M100",
// "MBart50",
// "mT5",
// "FlanT5",
"ByT5",
// "CANINE",
"BLOOM"
]).trigger("change");
});
});
</script>
<script type="text/javascript">
$(document).ready(function () {
get_examples = function (lang) {
var examples = null;
$.ajax({
dataType: "json",
url: `assets/examples/${lang}.json`,
async: false,
success: function (json) {
examples = json;
}
});
return examples;
};
var colors = ["#bf91ba", "#6ccff6", "#b4dc7f", "#feffa5", "#fcaf58"];
var language_map = null;
$.ajax({
dataType: "text",
url: "assets/flores_language_map.csv",
async: false,
success: function (data) {
language_map = data;
}
});
var dropdown_langL = $('#languageL');
var dropdown_langR = $('#languageR');
language_map.split(/^/m).slice(1).forEach(function (row) {
var items = row.split(',');
dropdown_langL.append($('<option value="' + items[1].trim() + '">' + items[0].trim() + '</option>'));
dropdown_langR.append($('<option value="' + items[1].trim() + '">' + items[0].trim() + '</option>'));
});
var tokenizerNames = Object.keys(get_examples("eng_Latn")).sort();
var dropdown_tokenizer = $('#example-tokenizer-selector');
dropdown_tokenizer.select2();
tokenizerNames.forEach(function (colId) {
var option = $('<option value="' + colId + '">' + colId + '</option>');
dropdown_tokenizer.append(option);
});
var dropdown_sentence = $('#sentence-selector');
function update_example(which) {
var language = $(`#language${which}`).val();
var sentence_id = dropdown_sentence.val();
var tokenizer = dropdown_tokenizer.val();
console.log(language, sentence_id, tokenizer);
var example = get_examples(language)[tokenizer][sentence_id];
var divElement = null;
divElement = document.getElementById(`example${which}-text`);
divElement.replaceChildren();
var spanElement = document.createElement("span");
var spanText = document.createTextNode(example["text"]);
spanElement.appendChild(spanText);
spanElement.classList.add("text");
divElement.appendChild(spanElement);
divElement = document.getElementById(`example${which}-ntokens`);
divElement.innerHTML = `${example["num_tokens"]} tokens, ${(100 * example["unknown_fraction"]).toFixed(0)}% characters mapped to the UNK token:`;
divElement = document.getElementById(`example${which}-tokens`);
divElement.replaceChildren();
var nextColorIndex = 0;
example["tokens"].flat().forEach(element => {
var spanElement = document.createElement("span");
var spanText = document.createTextNode(element);
spanElement.appendChild(spanText);
spanElement.classList.add("token");
spanElement.style.backgroundColor = colors[nextColorIndex % colors.length];
divElement.appendChild(spanElement);
// add a separator that is an empty span in order to prevent diacritics from combining across tokens
spanElement = document.createElement("span");
spanText = document.createTextNode(" ");
spanElement.appendChild(spanText);
spanElement.classList.add("separator");
divElement.appendChild(spanElement);
nextColorIndex += 1;
});
divElement = document.getElementById(`example${which}-token-text`);
divElement.replaceChildren();
nextColorIndex = 0;
example["tokens-text"].forEach((element, i) => {
var spanElement = document.createElement("span");
var spanText = document.createTextNode(element);
var nTokens = example["tokens"][i].length;
// var nextColorIndex = colorCounter % colors.length;
spanElement.appendChild(spanText);
spanElement.classList.add("token-text");
var bgColor = "linear-gradient(to right, ";
for (var i = 0; i < nTokens; i++) {
var colorIndex = nextColorIndex % colors.length;
bgColor += `${colors[colorIndex]} ${100 / nTokens * i}%, ${colors[colorIndex]} ${100 / nTokens * i}%, `;
bgColor += `${colors[colorIndex]} ${100 / nTokens * (i + 1)}%, ${colors[colorIndex]} ${100 / nTokens * (i + 1)}%`;
if (i < nTokens - 1) {
bgColor += ",";
}
nextColorIndex += 1;
};
spanElement.style.backgroundImage = bgColor + ")";
divElement.appendChild(spanElement);
// add a separator that is an empty span in order to prevent diacritics from combining across tokens
spanElement = document.createElement("span");
spanText = document.createTextNode(" ");
spanElement.appendChild(spanText);
spanElement.classList.add("separator");
divElement.appendChild(spanElement);
});
};
dropdown_langL.val("shn_Mymr");
dropdown_langR.val("eng_Latn");
dropdown_tokenizer.val("cl100k_base");
dropdown_sentence.on('change', function () { update_example("L"); update_example("R"); });
dropdown_tokenizer.on('change', function () { update_example("L"); update_example("R"); });
dropdown_langL.on('change', function () { update_example("L"); });
dropdown_langR.on('change', function () { update_example("R"); });
dropdown_sentence.trigger('change');
});
</script>
</body>
</html>