ArturKotAllegro commited on
Commit
0d3a761
·
verified ·
1 Parent(s): 7a703ac

Upload 4 files

Browse files
Files changed (4) hide show
  1. README.md +256 -155
  2. allegro-title.svg +359 -0
  3. p5-eng.svg +4 -0
  4. pivot-data-eng2many.svg +4 -0
README.md CHANGED
@@ -1,199 +1,300 @@
1
  ---
 
 
 
 
 
 
 
2
  library_name: transformers
3
- tags: []
 
 
 
 
 
 
 
 
 
 
4
  ---
5
 
6
- # Model Card for Model ID
7
 
8
- <!-- Provide a quick summary of what the model is/does. -->
 
 
9
 
 
10
 
 
 
 
 
11
 
12
- ## Model Details
 
13
 
14
- ### Model Description
 
 
15
 
16
- <!-- Provide a longer summary of what this model is. -->
 
 
 
17
 
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
 
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
 
28
- ### Model Sources [optional]
29
 
30
- <!-- Provide the basic links for the model. -->
 
 
 
31
 
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
 
 
 
35
 
36
- ## Uses
37
 
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
 
40
- ### Direct Use
41
 
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
 
43
 
44
- [More Information Needed]
45
 
46
- ### Downstream Use [optional]
 
47
 
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
 
 
 
 
 
 
 
 
 
49
 
50
- [More Information Needed]
 
51
 
52
- ### Out-of-Scope Use
53
-
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
-
56
- [More Information Needed]
57
-
58
- ## Bias, Risks, and Limitations
59
-
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
-
62
- [More Information Needed]
63
-
64
- ### Recommendations
65
-
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
-
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
-
70
- ## How to Get Started with the Model
71
-
72
- Use the code below to get started with the model.
73
-
74
- [More Information Needed]
75
-
76
- ## Training Details
77
-
78
- ### Training Data
79
-
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
-
82
- [More Information Needed]
83
-
84
- ### Training Procedure
85
-
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
-
88
- #### Preprocessing [optional]
89
-
90
- [More Information Needed]
91
-
92
-
93
- #### Training Hyperparameters
94
-
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
-
97
- #### Speeds, Sizes, Times [optional]
98
-
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
-
101
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
 
103
  ## Evaluation
104
 
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
-
107
- ### Testing Data, Factors & Metrics
108
-
109
- #### Testing Data
110
-
111
- <!-- This should link to a Dataset Card if possible. -->
112
-
113
- [More Information Needed]
114
-
115
- #### Factors
116
-
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
-
119
- [More Information Needed]
120
-
121
- #### Metrics
122
-
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
-
125
- [More Information Needed]
126
-
127
- ### Results
128
-
129
- [More Information Needed]
130
-
131
- #### Summary
132
-
133
-
134
-
135
- ## Model Examination [optional]
136
-
137
- <!-- Relevant interpretability work for the model goes here -->
138
-
139
- [More Information Needed]
140
-
141
- ## Environmental Impact
142
-
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
-
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
-
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
-
153
- ## Technical Specifications [optional]
154
-
155
- ### Model Architecture and Objective
156
-
157
- [More Information Needed]
158
-
159
- ### Compute Infrastructure
160
-
161
- [More Information Needed]
162
-
163
- #### Hardware
164
-
165
- [More Information Needed]
166
 
167
- #### Software
168
 
169
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
170
 
171
- ## Citation [optional]
172
 
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
 
 
 
 
 
 
 
 
 
174
 
175
- **BibTeX:**
176
 
177
- [More Information Needed]
178
 
179
- **APA:**
180
 
181
- [More Information Needed]
182
 
183
- ## Glossary [optional]
184
 
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
 
187
- [More Information Needed]
188
 
189
- ## More Information [optional]
 
190
 
191
- [More Information Needed]
192
 
193
- ## Model Card Authors [optional]
194
 
195
- [More Information Needed]
196
 
197
- ## Model Card Contact
 
 
198
 
199
- [More Information Needed]
 
 
 
1
  ---
2
+ license: cc-by-4.0
3
+ language:
4
+ - cs
5
+ - en
6
+ - pl
7
+ - sk
8
+ - sl
9
  library_name: transformers
10
+ tags:
11
+ - translation
12
+ - mt
13
+ - marian
14
+ - pytorch
15
+ - sentence-piece
16
+ - many2one
17
+ - multilingual
18
+ - pivot
19
+ - allegro
20
+ - laniqo
21
  ---
22
 
23
+ # MultiSlav P5-eng2many
24
 
25
+ <p align="center">
26
+ <a href="https://ml.allegro.tech/"><img src="allegro-title.svg" alt="MLR @ Allegro.com"></a>
27
+ </p>
28
 
29
+ ## Multilingual English-to-Many MT Model
30
 
31
+ ___P5-eng2many___ is an Encoder-Decoder vanilla transformer model trained on sentence-level Machine Translation task.
32
+ Model is supporting translation from English language to 4 languages: Czech, Polish, Slovak and Slovene.
33
+ This model is part of the [___MultiSlav___ collection](https://huggingface.co/collections/allegro/multislav-6793d6b6419e5963e759a683).
34
+ More information will be available soon in our upcoming MultiSlav paper.
35
 
36
+ Experiments were conducted under research project by [Machine Learning Research](https://ml.allegro.tech/) lab for [Allegro.com](https://ml.allegro.tech/).
37
+ Big thanks to [laniqo.com](laniqo.com) for cooperation in the research.
38
 
39
+ <p align="center">
40
+ <img src="p5-eng.svg">
41
+ </p>
42
 
43
+ ___P5-eng2many___ - _5_-language _English-to-Many_ model translating from English to all applicable languages
44
+ This model and [_P5-many2eng_](https://huggingface.co/allegro/P5-many2eng) combine into ___P5-eng___ pivot system translating between _5_ languages.
45
+ _P5-eng_ translates all supported languages using Many2One model to English bridge sentence
46
+ and next using the One2Many model from English bridge sentence to target language.
47
 
48
+ ### Model description
49
 
50
+ * **Model name:** P5-many2eng
51
+ * **Source Language:** English
52
+ * **Target Languages:** Czech, Polish, Slovak, Slovene
53
+ * **Model Collection:** [MultiSlav](https://huggingface.co/collections/allegro/multislav-6793d6b6419e5963e759a683)
54
+ * **Model type:** MarianMTModel Encoder-Decoder
55
+ * **License:** CC BY 4.0 (commercial use allowed)
56
+ * **Developed by:** [MLR @ Allegro](https://ml.allegro.tech/) & [Laniqo.com](https://laniqo.com/)
57
 
58
+ ### Supported languages
59
 
60
+ Using model you must specify target language for translation.
61
+ Target language tokens are represented as 3-letter ISO 639-3 language codes embedded in a format >>xxx<<.
62
+ All accepted directions and their respective tokens are listed below.
63
+ Each of them was added as a special token to Sentence-Piece tokenizer.
64
 
65
+ | **Target Language** | **First token** |
66
+ |---------------------|-----------------|
67
+ | Czech | `>>ces<<` |
68
+ | Polish | `>>pol<<` |
69
+ | Slovak | `>>slk<<` |
70
+ | Slovene | `>>slv<<` |
71
 
 
72
 
73
+ ## Use case quickstart
74
 
75
+ Example code-snippet to use model. Due to bug the `MarianMTModel` must be used explicitly.
76
 
77
+ ```python
78
+ from transformers import AutoTokenizer, MarianMTModel
79
 
80
+ o2m_model_name = "Allegro/P5-eng2many"
81
 
82
+ o2m_tokenizer = AutoTokenizer.from_pretrained(o2m_model_name)
83
+ o2m_model = MarianMTModel.from_pretrained(o2m_model_name)
84
 
85
+ text = "Allegro is an online e-commerce platform on which medium and small companies as well as large brands sell their products."
86
+ target_languages = ["ces", "pol", "slk", "slv"]
87
+ batch_to_translate = [
88
+ f">>{lang}<<" + " " + text for lang in target_languages
89
+ ]
90
+ translations = o2m_model.generate(**o2m_tokenizer.batch_encode_plus(batch_to_translate, return_tensors="pt"))
91
+ bridge_translations = o2m_tokenizer.batch_decode(translations, skip_special_tokens=True, clean_up_tokenization_spaces=True)
92
+ for trans in bridge_translations:
93
+ print(trans)
94
+ ```
95
 
96
+ Generated Czech output:
97
+ > Allegro je on-line e-commerce platforma, na které střední a malé firmy, stejně jako velké značky prodávají své produkty.
98
 
99
+ Generated Polish output:
100
+ > Allegro to internetowa platforma e-commerce, na której średnie i małe firmy oraz duże marki sprzedają swoje produkty.
101
+
102
+ Generated Slovak output:
103
+ > Allegro je online e-commerce platforma, na ktorej stredné a malé spoločnosti, ako aj veľké značky predávajú svoje produkty.
104
+
105
+ Generated Slovene output:
106
+ > Allegro je spletna e-poslovanje platforma, na kateri srednje in mala podjetja, kot tudi velike blagovne znamke prodajajo svoje izdelke.
107
+
108
+ To pivot-translate to other languages via _bridge_ English sentence, we need One2Many model.
109
+ Many2One model requires explicit source language token as well.
110
+ Example for translating from Polish to Slovak:
111
+
112
+ ```python
113
+ from transformers import AutoTokenizer, MarianMTModel
114
+
115
+ m2o_model_name = "Allegro/P5-many2eng"
116
+ o2m_model_name = "Allegro/P5-eng2many"
117
+
118
+ m2o_tokenizer = AutoTokenizer.from_pretrained(m2o_model_name)
119
+ m2o_model = MarianMTModel.from_pretrained(m2o_model_name)
120
+
121
+ o2m_tokenizer = AutoTokenizer.from_pretrained(o2m_model_name)
122
+ o2m_model = MarianMTModel.from_pretrained(o2m_model_name)
123
+
124
+ text = ">>pol<<" + " " + "Allegro to internetowa platforma e-commerce, na której swoje produkty sprzedają średnie i małe firmy, jak również duże marki."
125
+
126
+ translation = m2o_model.generate(**m2o_tokenizer.batch_encode_plus([text], return_tensors="pt"))
127
+ bridge_translations = m2o_tokenizer.batch_decode(translation, skip_special_tokens=True, clean_up_tokenization_spaces=True)
128
+
129
+ post_edited_bridge = ">>slk<<" + " " + bridge_translations[0]
130
+ translation = o2m_model.generate(**o2m_tokenizer.batch_encode_plus([post_edited_bridge], return_tensors="pt"))
131
+ decoded_translations = o2m_tokenizer.batch_decode(translation, skip_special_tokens=True, clean_up_tokenization_spaces=True)
132
+
133
+ print(decoded_translations[0])
134
+ ```
135
+
136
+ Generated Polish to Slovak pivot translation via English:
137
+ > Allegro je online e-commerce platforma, kde stredné a malé firmy, ako aj veľké značky predávajú svoje produkty.
138
+
139
+ ## Training
140
+
141
+ [SentencePiece](https://github.com/google/sentencepiece) tokenizer has a vocab size 80k in total (16k per language). Tokenizer was trained on randomly sampled part of the training corpus.
142
+ During the training we used the [MarianNMT](https://marian-nmt.github.io/) framework.
143
+ Base marian configuration used: [transfromer-big](https://github.com/marian-nmt/marian-dev/blob/master/src/common/aliases.cpp#L113).
144
+ All training parameters are listed in table below.
145
+
146
+ ### Training hyperparameters:
147
+
148
+ | **Hyperparameter** | **Value** |
149
+ |----------------------------|------------------------------------------------------------------------------------------------------------|
150
+ | Total Parameter Size | 258M |
151
+ | Training Examples | 393M |
152
+ | Vocab Size | 80k |
153
+ | Base Parameters | [Marian transfromer-big](https://github.com/marian-nmt/marian-dev/blob/master/src/common/aliases.cpp#L113) |
154
+ | Number of Encoding Layers | 6 |
155
+ | Number of Decoding Layers | 6 |
156
+ | Model Dimension | 1024 |
157
+ | FF Dimension | 4096 |
158
+ | Heads | 16 |
159
+ | Dropout | 0.1 |
160
+ | Batch Size | mini batch fit to VRAM |
161
+ | Training Accelerators | 4x A100 40GB |
162
+ | Max Length | 100 tokens |
163
+ | Optimizer | Adam |
164
+ | Warmup steps | 8000 |
165
+ | Context | Sentence-level MT |
166
+ | Source Language Supported | English |
167
+ | Target Languages Supported | Czech, Polish, Slovak, Slovene |
168
+ | Precision | float16 |
169
+ | Validation Freq | 3000 steps |
170
+ | Stop Metric | ChrF |
171
+ | Stop Criterion | 20 Validation steps |
172
+
173
+
174
+ ## Training corpora
175
+
176
+ <p align="center">
177
+ <img src="pivot-data-eng2many.svg">
178
+ </p>
179
+
180
+ 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.
181
+ In this model we experimented with expanding data-regime by using data from multiple target language and expanding language-pool by adding English.
182
+ We found that additional data clearly improved performance compared to the bi-directional baseline models.
183
+ For example in translation from Polish to Czech, this allowed us to expand training data-size from 63M to 269M examples, and from 25M to 269M for Slovene to Czech translation.
184
+ We only used explicitly open-source data to ensure open-source license of our model.
185
+
186
+ Datasets were downloaded via [MT-Data](https://pypi.org/project/mtdata/0.2.10/) library. Number of total examples post filtering and deduplication: __269M__.
187
+
188
+ The datasets used:
189
+
190
+ | **Corpus** |
191
+ |----------------------|
192
+ | paracrawl |
193
+ | opensubtitles |
194
+ | multiparacrawl |
195
+ | dgt |
196
+ | elrc |
197
+ | xlent |
198
+ | wikititles |
199
+ | wmt |
200
+ | wikimatrix |
201
+ | dcep |
202
+ | ELRC |
203
+ | tildemodel |
204
+ | europarl |
205
+ | eesc |
206
+ | eubookshop |
207
+ | emea |
208
+ | jrc_acquis |
209
+ | ema |
210
+ | qed |
211
+ | elitr_eca |
212
+ | EU-dcep |
213
+ | rapid |
214
+ | ecb |
215
+ | kde4 |
216
+ | news_commentary |
217
+ | kde |
218
+ | bible_uedin |
219
+ | europat |
220
+ | elra |
221
+ | wikipedia |
222
+ | wikimedia |
223
+ | tatoeba |
224
+ | globalvoices |
225
+ | euconst |
226
+ | ubuntu |
227
+ | php |
228
+ | ecdc |
229
+ | eac |
230
+ | eac_reference |
231
+ | gnome |
232
+ | EU-eac |
233
+ | books |
234
+ | EU-ecdc |
235
+ | newsdev |
236
+ | khresmoi_summary |
237
+ | czechtourism |
238
+ | khresmoi_summary_dev |
239
+ | worldbank |
240
 
241
  ## Evaluation
242
 
243
+ Evaluation of the models was performed on [Flores200](https://huggingface.co/datasets/facebook/flores) dataset.
244
+ The table below compares performance of the open-source models and all applicable models from our collection.
245
+ Metrics BLEU, ChrF2, and Unbabel/wmt22-comet-da.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
 
247
+ Translation results on translation from Polish to Czech (Slavic direction with the __highest__ data-regime):
248
 
249
+ | **Model** | **Comet22** | **BLEU** | **ChrF** | **Model Size** |
250
+ |------------------------------------------------------------------------------|:-----------:|:--------:|:--------:|---------------:|
251
+ | M2M−100 | 89.6 | 19.8 | 47.7 | 1.2B |
252
+ | NLLB−200 | 89.4 | 19.2 | 46.7 | 1.3B |
253
+ | Opus Sla-Sla | 82.9 | 14.6 | 42.6 | 64M |
254
+ | BiDi-ces-pol (baseline) | 90.0 | 20.3 | 48.5 | 209M |
255
+ | P4-pol <span style="color:red;">◊</span> | 90.2 | 20.2 | 48.5 | 2x 242M |
256
+ | P5-eng <span style="color:red;">◊</span> <span style="color:green;">*</span> | 89.0 | 19.9 | 48.3 | 2x 258M |
257
+ | P5-many2ces | 90.3 | 20.2 | 48.6 | 258M |
258
+ | MultiSlav-4slav | 90.2 | 20.6 | 48.7 | 242M |
259
+ | MultiSlav-5lang | __90.4__ | __20.7__ | __48.9__ | 258M |
260
 
261
+ Translation results on translation from Slovak to Slovene (Slavic direction with the __lowest__ data-regime):
262
 
263
+ | **Model** | **Comet22** | **BLEU** | **ChrF** | **Model Size** |
264
+ |------------------------------------------------------------------------------|:-----------:|:--------:|:--------:|---------------:|
265
+ | M2M−100 | 89.6 | 26.6 | 55.0 | 1.2B |
266
+ | NLLB−200 | 88.8 | 23.3 | 42.0 | 1.3B |
267
+ | BiDi-slk-slv (baseline) | 89.4 | 26.6 | 55.4 | 209M |
268
+ | P4-pol <span style="color:red;">◊</span> | 88.4 | 24.8 | 53.2 | 2x 242M |
269
+ | P5-eng <span style="color:red;">◊</span> <span style="color:green;">*</span> | 88.5 | 25.6 | 54.6 | 2x 258M |
270
+ | P5-ces <span style="color:red;">◊</span> | 89.8 | 26.6 | 55.3 | 2x 258M |
271
+ | MultiSlav-4slav | 90.1 | __27.1__ | __55.7__ | 242M |
272
+ | MultiSlav-5lang | __90.2__ | __27.1__ | __55.7__ | 258M |
273
 
 
274
 
275
+ <span style="color:green;">*</span> this model is One2Many part of P5-eng pivot system.
276
 
277
+ <span style="color:red;">◊</span> system of 2 models *Many2XXX* and *XXX2Many*.
278
 
279
+ ## Limitations and Biases
280
 
281
+ 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.
282
 
283
+ ## License
284
 
285
+ The model is licensed under CC BY 4.0, which allows for commercial use.
286
 
287
+ ## Citation
288
+ TO BE UPDATED SOON 🤗
289
 
 
290
 
 
291
 
292
+ ## Contact Options
293
 
294
+ Authors:
295
+ - 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)
296
+ - 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)
297
 
298
+ Please don't hesitate to contact authors if you have any questions or suggestions:
299
+ - e-mail: artur.kot@allegro.com or mikolaj.koszowski@allegro.com
300
+ - LinkedIn: [Artur Kot](https://linkedin.com/in/arturkot) or [Mikołaj Koszowski](https://linkedin.com/in/mkoszowski)
allegro-title.svg ADDED
p5-eng.svg ADDED
pivot-data-eng2many.svg ADDED