CoolFace
Modelpublic

allegro/p5-many2eng

sourceHugging Facecc-by-4.0updated 2y agoView on Hugging Face
0likes9downloads
Model Card

MultiSlav P5-many2eng

<p align="center"> <a href="https://ml.allegro.tech/"><img src="allegro-title.svg" alt="MLR @ Allegro.com"></a> </p>

Multilingual Many-to-English MT Model

__P5-many2eng_ is an Encoder-Decoder vanilla transformer model trained on sentence-level Machine Translation task. Model is supporting translation from 4 languages: Czech, Polish, Slovak, and Slovene to English. This model is part of the [_MultiSlav__ collection](https://huggingface.co/collections/allegro/multislav-6793d6b6419e5963e759a683). More information will be available soon in our upcoming MultiSlav paper.

Experiments were conducted under research project by Machine Learning Research lab for Allegro.com. Big thanks to laniqo.com for cooperation in the research.

<p align="center"> <img src="p5-eng.svg"> </p>

__P5-many2eng_ - 5-language Many-to-English model translating from all applicable languages to English. This model and [P5-eng2many](https://huggingface.co/allegro/P5-eng2many) combine into _P5-eng_ pivot system translating between 5 languages. P5-eng_ translates all supported languages using Many2One model to English bridge sentence and next using the One2Many model from English bridge sentence to target language.

Model description

  • —Model name: P5-many2ces
  • —Source Languages: Czech, Polish, Slovak, Slovene
  • —Target Language: English
  • —Model Collection: MultiSlav
  • —Model type: MarianMTModel Encoder-Decoder
  • —License: CC BY 4.0 (commercial use allowed)
  • —Developed by: MLR @ Allegro & Laniqo.com

Supported languages

Using model you must specify source language for translation. Source language tokens are represented as 3-letter ISO 639-3 language codes embedded in a format >>xxx<<. All accepted directions and their respective tokens are listed below. Each of them was added as a special token to Sentence-Piece tokenizer.

**Source Language****First token**
Czech>>ces<<
Polish>>pol<<
Slovak>>slk<<
Slovene>>slv<<

Use case quickstart

Example code-snippet to use model. Due to bug the MarianMTModel must be used explicitly.

python
from transformers import AutoTokenizer, MarianMTModel

m2o_model_name = "Allegro/P5-many2eng"

m2o_tokenizer = AutoTokenizer.from_pretrained(m2o_model_name)
m2o_model = MarianMTModel.from_pretrained(m2o_model_name)

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."

translations = m2o_model.generate(**m2o_tokenizer.batch_encode_plus([text], return_tensors="pt"))
bridge_translation = m2o_tokenizer.batch_decode(translations, skip_special_tokens=True, clean_up_tokenization_spaces=True)
print(bridge_translation[0])

Generated bridge English output:

Allegro is an online e-commerce platform where medium and small companies as well as large brands sell their products.

To pivot-translate to other languages via bridge English sentence, we need One2Many model. One2Many model requires explicit target language token as well:

python

o2m_model_name = "Allegro/P5-eng2many"

o2m_tokenizer = AutoTokenizer.from_pretrained(o2m_model_name)
o2m_model = MarianMTModel.from_pretrained(o2m_model_name)

texts_to_translate = [
    ">>ces<<" + " " + bridge_translation[0],
    ">>slk<<" + " " + bridge_translation[0],
    ">>slv<<" + " " + bridge_translation[0]
]
translation = o2m_model.generate(**o2m_tokenizer.batch_encode_plus(texts_to_translate, return_tensors="pt"))
decoded_translations = o2m_tokenizer.batch_decode(translation, skip_special_tokens=True, clean_up_tokenization_spaces=True)

for trans in decoded_translations:
    print(trans)

Generated Polish to Czech pivot translation via English:

Allegro je on-line e-commerce platforma, kde střední a malé firmy, stejně jako velké značky prodávají své produkty.

Generated Polish to Slovak pivot translation via English:

Allegro je online e-commerce platforma, kde stredné a malé firmy, ako aj veľké značky predávajú svoje produkty.

Generated Polish to Slovene pivot translation via English:

Allegro je spletna e-poslovanje platforma, kjer srednje in mala podjetja, kot tudi velike blagovne znamke prodajajo svoje izdelke.

Training

SentencePiece tokenizer has a vocab size 80k in total (16k per language). Tokenizer was trained on randomly sampled part of the training corpus. During the training we used the MarianNMT framework. Base marian configuration used: transfromer-big. All training parameters are listed in table below.

Training hyperparameters:

**Hyperparameter****Value**
Total Parameter Size258M
Training Examples393M
Vocab Size80k
Base ParametersMarian transfromer-big
Number of Encoding Layers6
Number of Decoding Layers6
Model Dimension1024
FF Dimension4096
Heads16
Dropout0.1
Batch Sizemini batch fit to VRAM
Training Accelerators4x A100 40GB
Max Length100 tokens
OptimizerAdam
Warmup steps8000
ContextSentence-level MT
Source Languages SupportedCzech, Polish, Slovak, Slovene
Target Language SupportedEnglish
Precisionfloat16
Validation Freq3000 steps
Stop MetricChrF
Stop Criterion20 Validation steps

Training corpora

<p align="center"> <img src="pivot-data-many2eng.svg"> </p>

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. Choosing English model as Bridge Language provides more training examples to model, as English is high-resource data-regime increasing to 393M compared to 269M for [P5-many2ces](). However, English has a limited morphology compared to Slavic languages, which may lead to loss of information (like gender for the subject in the sentence). Performance results are mixed compared to [P5-many2ces](). We only used explicitly open-source data to ensure open-source license of our model.

Datasets were downloaded via MT-Data library. Number of total examples post filtering and deduplication: _393M_.

The datasets used:

**Corpus**
paracrawl
opensubtitles
multiparacrawl
dgt
elrc
xlent
wikititles
wmt
wikimatrix
dcep
ELRC
tildemodel
europarl
eesc
eubookshop
emea
jrc_acquis
ema
qed
elitr_eca
EU-dcep
rapid
ecb
kde4
news_commentary
kde
bible_uedin
europat
elra
wikipedia
wikimedia
tatoeba
globalvoices
euconst
ubuntu
php
ecdc
eac
eac_reference
gnome
EU-eac
books
EU-ecdc
newsdev
khresmoi_summary
czechtourism
khresmoisummarydev
worldbank

Evaluation

Evaluation of the models was performed on Flores200 dataset. The table below compares performance of the open-source models and all applicable models from our collection. Metrics BLEU, ChrF2, and Unbabel/wmt22-comet-da.

Translation results on translation from Polish to Czech (Slavic direction with the _highest_ data-regime):

**Model****Comet22****BLEU****ChrF****Model Size**
M2M−10089.619.847.71.2B
NLLB−20089.419.246.71.3B
Opus Sla-Sla82.914.642.664M
BiDi-ces-pol (baseline)90.020.348.5209M
P4-pol <span style="color:red;">◊</span>90.220.248.52x 242M
__P5-eng__ <span style="color:red;">◊</span> <span style="color:green;">*</span>89.019.948.32x 258M
P5-many2ces90.320.248.6258M
MultiSlav-4slav90.220.648.7242M
MultiSlav-5lang_90.4__20.7__48.9_258M

Translation results on translation from Slovene to Czech (direction to Czech with the _lowest_ data-regime):

**Model****Comet22****BLEU****ChrF****Model Size**
M2M−10090.324.351.61.2B
NLLB−20090.022.549.91.3B
Opus Sla-Sla83.517.446.01.3B
BiDi-ces-slv (baseline)90.024.452.0209M
P4-pol <span style="color:red;">◊</span>89.322.750.42x 242M
__P5-eng__ <span style="color:red;">◊</span> <span style="color:green;">*</span>89.624.752.42x 258M
P5-many2ces90.324.952.4258M
MultiSlav-4slav_90.6__25.3__52.7_242M
MultiSlav-5lang_90.6_25.252.5258M

<span style="color:green;">*</span> used entire P5-eng pivot system, including One2Many [P5-eng2many]() model.

<span style="color:red;">◊</span> system of 2 models Many2XXX and XXX2Many.

Limitations and Biases

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.

License

The model is licensed under CC BY 4.0, which allows for commercial use.

Citation

TO BE UPDATED SOON 🤗

Contact Options

Authors:

Please don't hesitate to contact authors if you have any questions or suggestions: