CoolFace
Modelpublic

allegro/multislav-5lang

sourceHugging Facecc-by-4.0updated 2y agoView on Hugging Face
5likes58downloads
Model Card

MultiSlav MultiSlav-5lang

<p align="center">

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

</p>

Multilingual Many2Many MT Model

__MultiSlav-5lang_ is an Encoder-Decoder vanilla transformer model trained on sentence-level Machine Translation task. Model is supporting translation between 5 languages: Czech, English, Polish, Slovak, Slovene. 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="multislav-5lang.svg"> </p>

__MultiSlav-5lang__ - translates directly between all supported languages using single Many2Many model as seen on the diagram above.

Model description

  • Model name: multislav-5lang
  • Source Languages: Czech, English, Polish, Slovak, Slovene
  • Target Languages: Czech, English, Polish, Slovak, Slovene
  • 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 target language for translation. Target 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.

**Target Language****First token**
Czech>>ces<<
English>>eng<<
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

model_name = "Allegro/MultiSlav-5lang"

tokenizer = AutoTokenizer.from_pretrained(model_name)
model = MarianMTModel.from_pretrained(model_name)

text = "Allegro to internetowa platforma e-commerce, na której swoje produkty sprzedają średnie i małe firmy, jak również duże marki."
target_languages = ["ces", "eng", "slk", "slv"]
batch_to_translate = [
    f">>{lang}<<" + " " + text for lang in target_languages
]

translations = model.generate(**tokenizer.batch_encode_plus(batch_to_translate, return_tensors="pt"))
decoded_translations = tokenizer.batch_decode(translations, skip_special_tokens=True, clean_up_tokenization_spaces=True)
for trans in decoded_translations:
    print(trans)

Generated outputs:

Czech output:

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

English output:

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

Slovak output:

Allegro je internetová e-commerce platforma, na ktorej svoje produkty predávajú stredné a malé podniky, ako aj veľké značky.

Slovene output:

Allegro je spletna platforma za e-poslovanje, na kateri srednje velika in mala podjetja ter velike blagovne znamke prodajajo svoje izdelke.

The model is also capable of translating into Polish language, following the same pattern:

python
text = ">>pol<<" + " " + "Allegro is an online e-commerce platform on which medium and small companies as well as large brands sell their products."
translation = model.generate(**tokenizer.batch_encode_plus([text], return_tensors="pt"))
decoded_translation = tokenizer.batch_decode(translation, skip_special_tokens=True, clean_up_tokenization_spaces=True)

print(decoded_translation[0])

Generated Polish output:

Allegro to internetowa platforma e-commerce, na której sprzedają swoje produkty średnie i małe firmy, a także duże marki.

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 Examples578M
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, English, Polish, Slovak, Slovene
Target Languages SupportedCzech, English, Polish, Slovak, Slovene
Precisionfloat16
Validation Freq3000 steps
Stop MetricChrF
Stop Criterion20 Validation steps

Training corpora

<p align="center"> <img src="./multi5-data.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. In this model we experimented by additionally adding English <-> Slavic parallel corpora to further increase open-source data-regime. We found that additional data clearly improved performance compared to the bi-directional baseline models, and compared to pivot models and MultiSlav-4slav in the most of the directions. For example in translation from Polish to Czech, this allowed us to expand training data-size from 63M to 578M examples, and from 18M to 578M for Slovak to Slovene translation.

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: _578M_.

The datasets used and data amount prior to filtering and deduplication:

**Corpus****Data Size**
paracrawl246407901
opensubtitles167583218
multiparacrawl52388826
dgt36403859
elrc29687222
xlent18375223
wikititles12936394
wmt11074816
wikimatrix10435588
dcep10239150
ELRC7609067
tildemodel6309369
europarl6088362
eesc5604672
eubookshop3732718
emea3482661
jrc_acquis2920805
ema1881408
qed1835208
elitr_eca1398536
EU-dcep1132950
rapid1016905
ecb885442
kde4541944
news_commentary498432
kde473269
bible_uedin429692
europat358911
elra357696
wikipedia352118
wikimedia201088
tatoeba91251
globalvoices69736
euconst65507
ubuntu47301
php44031
ecdc21154
eac20224
eac_reference10099
gnome4466
EU-eac2925
books2816
EU-ecdc2210
newsdev1953
khresmoi_summary889
czechtourism832
khresmoisummarydev455
worldbank189

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>89.019.948.32x 258M
P5-ces <span style="color:red;">◊</span>90.320.248.62x 258M
MultiSlav-4slav90.220.648.7242M
__MultiSlav-5lang__ <span style="color:green;">*</span>_90.4__20.7__48.9_258M

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

**Model****Comet22****BLEU****ChrF****Model Size**
M2M−10089.626.655.01.2B
NLLB−20088.823.342.01.3B
BiDi-slk-slv (baseline)89.426.655.4209M
P4-pol <span style="color:red;">◊</span>88.424.853.22x 242M
P5-eng <span style="color:red;">◊</span>88.525.654.62x 258M
P5-ces <span style="color:red;">◊</span>89.826.655.32x 258M
MultiSlav-4slav90.1_27.1__55.7_242M
__MultiSlav-5lang__ <span style="color:green;">*</span>_90.2__27.1__55.7_258M

<span style="color:green;">*</span> this model

<span style="color:red;">◊</span> system of 2 models Many2XXX and XXX2Many, see P5-ces2many

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: