ArturKotAllegro commited on
Commit
05e7b52
·
verified ·
1 Parent(s): 948d410

Update readme.md

Browse files
Files changed (2) hide show
  1. bi-di.svg +4 -0
  2. readme.md +269 -0
bi-di.svg ADDED
readme.md ADDED
@@ -0,0 +1,269 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-4.0
3
+ language:
4
+ - cs
5
+ - pl
6
+ - sk
7
+ - sl
8
+ - en
9
+ library_name:
10
+ - transformers
11
+ - marian
12
+ tags:
13
+ - translation
14
+ - mt
15
+ - marian
16
+ - pytorch
17
+ - sentence-piece
18
+ - one2many
19
+ - multilingual
20
+ - pivot
21
+ - allegro
22
+ - laniqo
23
+ ---
24
+
25
+ # MultiSlav BiDi Models
26
+
27
+
28
+ [//]: # (<p align="center">)
29
+
30
+ [//]: # ( <a href="https://ml.allegro.tech/"><img src="allegro-title.svg" alt="MLR @ Allegro.com"></a>)
31
+
32
+ [//]: # (</p>)
33
+
34
+ ## Multilingual BiDi MT Models
35
+
36
+ ___BiDi___ is a collection of Encoder-Decoder vanilla transformer models trained on sentence-level Machine Translation task.
37
+ Each model is supporting Bi-Directional translation.
38
+
39
+ ___BiDi___ models are part of the [___MultiSlav___ collection](https://huggingface.co/collections/allegro/multislav-6793d6b6419e5963e759a683). More information will be available soon in our upcoming MultiSlav paper.
40
+
41
+ Experiments were conducted under research project by [Machine Learning Research](https://ml.allegro.tech/) lab for [Allegro.com](https://ml.allegro.tech/).
42
+ Big thanks to [laniqo.com](laniqo.com) for cooperation in the research.
43
+
44
+ <p align="center">
45
+ <img src="bi-di.svg">
46
+ </p>
47
+
48
+ Graphic above provides an example of an BiDi model - [BiDi-ces-pol](https://huggingface.co/allegro/bidi-ces-pol) to translate from Polish to Czech language.
49
+ ___BiDi-ces-pol___ is a bi-directional model supporting translation both __form Czech to Polish__ and __from Polish to Czech__ directions.
50
+
51
+
52
+ ### Supported languages
53
+
54
+ To use a ___BiDi___ model, you must provide the target language for translation.
55
+ Target language tokens are represented as 3-letter ISO 639-3 language codes embedded in a format >>xxx<<.
56
+ All accepted directions and their respective tokens are listed below.
57
+ Note that, for each model only two directions are available.
58
+ Each of them was added as a special token to Sentence-Piece tokenizer.
59
+
60
+ | **Target Language** | **First token** |
61
+ |---------------------|-----------------|
62
+ | Czech | `>>ces<<` |
63
+ | English | `>>eng<<` |
64
+ | Polish | `>>pol<<` |
65
+ | Slovak | `>>slk<<` |
66
+ | Slovene | `>>slv<<` |
67
+
68
+
69
+ ### Bi-Di models available
70
+
71
+ We provided 10 ___BiDi___ models, allowing to translate between 20 languages.
72
+
73
+ | **Bi-Di model** | **Languages supported** | **HF repository** |
74
+ |-----------------|-------------------------|---------------------------------------------------------------------|
75
+ | BiDi-ces-eng | Czech ↔ English | [allegro/BiDi-ces-eng](https://huggingface.co/allegro/bidi-ces-eng) |
76
+ | BiDi-ces-pol | Czech ↔ Polish | [allegro/BiDi-ces-pol](https://huggingface.co/allegro/bidi-ces-pol) |
77
+ | BiDi-ces-slk | Czech ↔ Slovak | [allegro/BiDi-ces-slk](https://huggingface.co/allegro/bidi-ces-slk) |
78
+ | BiDi-ces-slv | Czech ↔ Slovene | [allegro/BiDi-ces-slv](https://huggingface.co/allegro/bidi-ces-slv) |
79
+ | BiDi-eng-pol | English ↔ Polish | [allegro/BiDi-eng-pol](https://huggingface.co/allegro/bidi-eng-pol) |
80
+ | BiDi-eng-slk | English ↔ Slovak | [allegro/BiDi-eng-slk](https://huggingface.co/allegro/bidi-eng-slk) |
81
+ | BiDi-eng-slv | English ↔ Slovene | [allegro/BiDi-eng-slv](https://huggingface.co/allegro/bidi-eng-slv) |
82
+ | BiDi-pol-slk | Polish ↔ Slovak | [allegro/BiDi-pol-slk](https://huggingface.co/allegro/bidi-pol-slk) |
83
+ | BiDi-pol-slv | Polish ↔ Slovene | [allegro/BiDi-pol-slv](https://huggingface.co/allegro/bidi-pol-slv) |
84
+ | BiDi-slk-slv | Slovak ↔ Slovene | [allegro/BiDi-slk-slv](https://huggingface.co/allegro/bidi-slk-slv) |
85
+
86
+ ## Use case quickstart
87
+
88
+ Example code-snippet to use model. Due to bug the `MarianMTModel` must be used explicitly.
89
+ Remember to adjust source and target languages to your use-case.
90
+
91
+ ```python
92
+ from transformers import AutoTokenizer, MarianMTModel
93
+
94
+ source_lang = "pol"
95
+ target_lang = "ces"
96
+ first_lang, second_lang = sorted([source_lang, target_lang])
97
+ model_name = f"Allegro/BiDi-{first_lang}-{second_lang}"
98
+
99
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
100
+ model = MarianMTModel.from_pretrained(model_name)
101
+
102
+ text = f">>{target_lang}<<" + " " + "Allegro to internetowa platforma e-commerce, na której swoje produkty sprzedają średnie i małe firmy, jak również duże marki."
103
+
104
+ batch_to_translate = [text]
105
+ translations = model.generate(**tokenizer.batch_encode_plus(batch_to_translate, return_tensors="pt"))
106
+ decoded_translation = tokenizer.batch_decode(translations, skip_special_tokens=True, clean_up_tokenization_spaces=True)[0]
107
+
108
+ print(decoded_translation)
109
+ ```
110
+
111
+ Generated Czech output:
112
+ > Allegro je online platforma pro e-commerce, na které své produkty prodávají střední a malé firmy, stejně jako velké značky.
113
+
114
+
115
+ ## Training
116
+
117
+ [SentencePiece](https://github.com/google/sentencepiece) tokenizer has a vocab size 32k in total (16k per language). Tokenizer was trained on randomly sampled part of the training corpus.
118
+ During the training we used the [MarianNMT](https://marian-nmt.github.io/) framework.
119
+ Base marian configuration used: [transfromer-big](https://github.com/marian-nmt/marian-dev/blob/master/src/common/aliases.cpp#L113).
120
+ All training parameters are listed in table below.
121
+
122
+ ### Training hyperparameters:
123
+
124
+ | **Hyperparameter** | **Value** |
125
+ |----------------------------|------------------------------------------------------------------------------------------------------------|
126
+ | Total Parameter Size | 209M |
127
+ | Vocab Size | 32k |
128
+ | Base Parameters | [Marian transfromer-big](https://github.com/marian-nmt/marian-dev/blob/master/src/common/aliases.cpp#L113) |
129
+ | Number of Encoding Layers | 6 |
130
+ | Number of Decoding Layers | 6 |
131
+ | Model Dimension | 1024 |
132
+ | FF Dimension | 4096 |
133
+ | Heads | 16 |
134
+ | Dropout | 0.1 |
135
+ | Batch Size | mini batch fit to VRAM |
136
+ | Training Accelerators | 4x A100 40GB |
137
+ | Max Length | 100 tokens |
138
+ | Optimizer | Adam |
139
+ | Warmup steps | 8000 |
140
+ | Context | Sentence-level MT |
141
+ | Languages Supported | See [Bi-Di models available](#Bi-Di-models-available) |
142
+ | Precision | float16 |
143
+ | Validation Freq | 3000 steps |
144
+ | Stop Metric | ChrF |
145
+ | Stop Criterion | 20 Validation steps |
146
+
147
+
148
+ ## Training corpora
149
+
150
+ The main research question was: "How does adding additional, related languages impact the quality of the model?" - we explored it in the Slavic language family.
151
+ ___BiDi___ models are baseline before expanding the data-regime by using data higher-level multilinguality.
152
+
153
+ Datasets were downloaded via [MT-Data](https://pypi.org/project/mtdata/0.2.10/) library.
154
+ Number of total examples post filtering and deduplication vary, see table below.
155
+
156
+ | **Language pair** | **Number of training examples** |
157
+ |-------------------|--------------------------------:|
158
+ | Czech ↔ Polish | 63M |
159
+ | Czech ↔ Slovak | 30M |
160
+ | Czech ↔ Slovene | 25M |
161
+ | Polish ↔ Slovak | 26M |
162
+ | Polish ↔ Slovene | 23M |
163
+ | Slovak ↔ Slovene | 18M |
164
+ | ---------------- | ------------------------------- |
165
+ | Czech ↔ English | 151M |
166
+ | English ↔ Polish | 150M |
167
+ | English ↔ Slovak | 52M |
168
+ | English ↔ Slovene | 40M |
169
+
170
+ The datasets used (only applicable to specific directions):
171
+
172
+ | **Corpus** |
173
+ |----------------------|
174
+ | paracrawl |
175
+ | opensubtitles |
176
+ | multiparacrawl |
177
+ | dgt |
178
+ | elrc |
179
+ | xlent |
180
+ | wikititles |
181
+ | wmt |
182
+ | wikimatrix |
183
+ | dcep |
184
+ | ELRC |
185
+ | tildemodel |
186
+ | europarl |
187
+ | eesc |
188
+ | eubookshop |
189
+ | emea |
190
+ | jrc_acquis |
191
+ | ema |
192
+ | qed |
193
+ | elitr_eca |
194
+ | EU-dcep |
195
+ | rapid |
196
+ | ecb |
197
+ | kde4 |
198
+ | news_commentary |
199
+ | kde |
200
+ | bible_uedin |
201
+ | europat |
202
+ | elra |
203
+ | wikipedia |
204
+ | wikimedia |
205
+ | tatoeba |
206
+ | globalvoices |
207
+ | euconst |
208
+ | ubuntu |
209
+ | php |
210
+ | ecdc |
211
+ | eac |
212
+ | eac_reference |
213
+ | gnome |
214
+ | EU-eac |
215
+ | books |
216
+ | EU-ecdc |
217
+ | newsdev |
218
+ | khresmoi_summary |
219
+ | czechtourism |
220
+ | khresmoi_summary_dev |
221
+ | worldbank |
222
+
223
+ ## Evaluation
224
+
225
+ Evaluation of the models was performed on [Flores200](https://huggingface.co/datasets/facebook/flores) dataset.
226
+ The table below compares performance of the open-source models and all applicable models from our collection.
227
+ Metric used: Unbabel/wmt22-comet-da.
228
+
229
+ | **Direction** | **CES → ENG** | **CES → POL** | **CES → SLK** | **CES → SLV** | **ENG → CES** | **ENG → POL** | **ENG → SLK** | **ENG → SLV** | **POL → CES** | **POL → ENG** | **POL → SLK** | **POL → SLV** | **SLK → CES** | **SLK → ENG** | **SLK → POL** | **SLK → SLV** | **SLV → CES** | **SLV → ENG** | **SLV → POL** | **SLV → SLK** |
230
+ |----------------------------------------------------|--------------:|--------------:|--------------:|--------------:|--------------:|--------------:|--------------:|--------------:|--------------:|--------------:|--------------:|--------------:|--------------:|--------------:|--------------:|--------------:|--------------:|--------------:|--------------:|--------------:|
231
+ | **M2M-100** | 87.0 | 89.0 | 92.1 | 89.7 | 88.6 | 86.4 | 88.4 | 87.3 | 89.6 | 84.6 | 89.4 | 88.4 | 92.7 | 86.8 | 89.1 | 89.6 | 90.3 | 86.4 | 88.7 | 90.1 |
232
+ | **NLLB-200** | 88.1 | 88.9 | 91.2 | 88.6 | 90.4 | __88.5__ | 90.1 | 88.8 | 89.4 | __85.8__ | 88.9 | 87.7 | 91.8 | 88.2 | 88.9 | 88.8 | 90.0 | __87.5__ | 88.6 | 89.4 |
233
+ | **Seamless-M4T** | 87.5 | 80.9 | 90.8 | 82.0 | __90.7__ | __88.5__ | __90.6__ | __89.6__ | 79.6 | 85.4 | 80.0 | 76.4 | 91.5 | 87.2 | 81.2 | 82.9 | 80.9 | 87.3 | 76.7 | 81.0 |
234
+ | **OPUS-MT Sla-Sla** | __88.2__ | 82.8 | - | 83.4 | 89.1 | 85.6 | 89.5 | 84.5 | 82.9 | 82.2 | - | 81.2 | - | __88.4__ | - | - | 83.5 | 84.1 | 80.8 | - |
235
+ | **OPUS-MT SK-EN** | - | - | - | - | - | - | 89.5 | - | - | - | - | - | - | __88.4__ | - | - | - | - | - | - |
236
+ | _Our contributions:_ | | | | | | | | | | | | | | | | | | | | |
237
+ | **BiDi Models**<span style="color:green;">*</span> | 87.5 | 89.4 | 92.4 | 89.8 | 87.8 | 86.2 | 87.2 | 86.6 | 90.0 | 85.0 | 89.1 | 88.4 | 92.9 | 87.3 | 88.8 | 89.4 | 90.0 | 86.9 | 88.1 | 89.1 |
238
+ | **P4-pol**<span style="color:red;">◊</span> | - | 89.6 | 90.8 | 88.7 | - | - | - | - | 90.2 | - | 89.8 | 88.7 | 91.0 | - | 89.3 | 88.4 | 89.3 | - | 88.7 | 88.5 |
239
+ | **P5-eng**<span style="color:red;">◊</span> | 88.0 | 89.0 | 90.7 | 89.0 | 88.8 | 87.3 | 88.4 | 87.5 | 89.0 | 85.7 | 88.5 | 87.8 | 91.0 | 88.2 | 88.6 | 88.5 | 89.6 | 87.2 | 88.4 | 88.9 |
240
+ | **P5-ces**<span style="color:red;">◊</span> | 87.9 | 89.6 | __92.5__ | 89.9 | 88.4 | 85.0 | 87.9 | 85.9 | 90.3 | 84.5 | 89.5 | 88.0 | __93.0__ | 87.8 | 89.4 | 89.8 | 90.3 | 85.7 | 87.9 | 89.8 |
241
+ | **MultiSlav-4slav** | - | 89.7 | __92.5__ | 90.0 | - | - | - | - | 90.2 | - | 89.6 | 88.7 | 92.9 | - | 89.4 | 90.1 | ___90.6___ | - | 88.9 | __90.2__ |
242
+ | **MultiSlav-5lang** | 87.8 | ___89.8___ | __92.5__ | ___90.1___ | 88.9 | 86.9 | 88.0 | 87.3 | __90.4__ | 85.4 | 89.8 | __88.9__ | 92.9 | 87.8 | ___89.6___ | __90.2__ | ___90.6___ | 87.0 | __89.2__ | __90.2__ |
243
+
244
+ <span style="color:red;">◊</span> system of 2 models *Many2XXX* and *XXX2Many*
245
+
246
+ <span style="color:green;">*</span> results combined for all bi-directional models; each values for applicable model
247
+
248
+ ## Limitations and Biases
249
+
250
+ We did not evaluate inherent bias contained in training datasets. It is advised to validate bias of our models in perspective domain. This might be especially problematic in translation from English to Slavic languages, which require explicitly indicated gender and might hallucinate based on bias present in training data.
251
+
252
+ ## License
253
+
254
+ The model is licensed under CC BY 4.0, which allows for commercial use.
255
+
256
+ ## Citation
257
+ TO BE UPDATED SOON 🤗
258
+
259
+
260
+
261
+ ## Contact Options
262
+
263
+ Authors:
264
+ - MLR @ Allegro: [Artur Kot](https://linkedin.com/in/arturkot), [Mikołaj Koszowski](https://linkedin.com/in/mkoszowski), [Wojciech Chojnowski](https://linkedin.com/in/wojciech-chojnowski-744702348), [Mieszko Rutkowski](https://linkedin.com/in/mieszko-rutkowski)
265
+ - Laniqo.com: [Artur Nowakowski](https://linkedin.com/in/artur-nowakowski-mt), [Kamil Guttmann](https://linkedin.com/in/kamil-guttmann), [Mikołaj Pokrywka](https://linkedin.com/in/mikolaj-pokrywka)
266
+
267
+ Please don't hesitate to contact authors if you have any questions or suggestions:
268
+ - e-mail: artur.kot@allegro.com or mikolaj.koszowski@allegro.com
269
+ - LinkedIn: [Artur Kot](https://linkedin.com/in/arturkot) or [Mikołaj Koszowski](https://linkedin.com/in/mkoszowski)