CoolFace
Modelpublic

allegro/BiDi-eng-pol

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

MultiSlav BiDi Models

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

Multilingual BiDi MT Models

__BiDi__ is a collection of Encoder-Decoder vanilla transformer models trained on sentence-level Machine Translation task. Each model is supporting Bi-Directional translation.

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

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="bi-di.svg"> </p>

Graphic above provides an example of an BiDi model - BiDi-ces-pol to translate from Polish to Czech language. __BiDi-ces-pol_ is a bi-directional model supporting translation both form Czech to Polish and from Polish to Czech_ directions.

Supported languages

To use a __BiDi__ model, you must provide the 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. Note that, for each model only two directions are available. 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<<

Bi-Di models available

We provided 10 __BiDi__ models, allowing to translate between 20 languages.

**Bi-Di model****Languages supported****HF repository**
BiDi-ces-engCzech ↔ Englishallegro/BiDi-ces-eng
BiDi-ces-polCzech ↔ Polishallegro/BiDi-ces-pol
BiDi-ces-slkCzech ↔ Slovakallegro/BiDi-ces-slk
BiDi-ces-slvCzech ↔ Sloveneallegro/BiDi-ces-slv
BiDi-eng-polEnglish ↔ Polishallegro/BiDi-eng-pol
BiDi-eng-slkEnglish ↔ Slovakallegro/BiDi-eng-slk
BiDi-eng-slvEnglish ↔ Sloveneallegro/BiDi-eng-slv
BiDi-pol-slkPolish ↔ Slovakallegro/BiDi-pol-slk
BiDi-pol-slvPolish ↔ Sloveneallegro/BiDi-pol-slv
BiDi-slk-slvSlovak ↔ Sloveneallegro/BiDi-slk-slv

Use case quickstart

Example code-snippet to use model. Due to bug the MarianMTModel must be used explicitly. Remember to adjust source and target languages to your use-case.

python
from transformers import AutoTokenizer, MarianMTModel

source_lang = "pol"
target_lang = "ces"
first_lang, second_lang = sorted([source_lang, target_lang])
model_name = f"Allegro/BiDi-{first_lang}-{second_lang}"

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

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

batch_to_translate = [text]
translations = model.generate(**tokenizer.batch_encode_plus(batch_to_translate, return_tensors="pt"))
decoded_translation = tokenizer.batch_decode(translations, skip_special_tokens=True, clean_up_tokenization_spaces=True)[0]

print(decoded_translation)

Generated Czech output:

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

Training

SentencePiece tokenizer has a vocab size 32k 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 Size209M
Vocab Size32k
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
Languages SupportedSee Bi-Di models available
Precisionfloat16
Validation Freq3000 steps
Stop MetricChrF
Stop Criterion20 Validation steps

Training corpora

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. __BiDi__ models are our baseline before expanding the data-regime by using higher-level multilinguality.

Datasets were downloaded via MT-Data library. The number of total examples post filtering and deduplication varies, depending on languages supported, see the table below.

**Language pair****Number of training examples**
Czech ↔ Polish63M
Czech ↔ Slovak30M
Czech ↔ Slovene25M
Polish ↔ Slovak26M
Polish ↔ Slovene23M
Slovak ↔ Slovene18M
-----------------------------------------------
Czech ↔ English151M
English ↔ Polish150M
English ↔ Slovak52M
English ↔ Slovene40M

The datasets used (only applicable to specific directions):

**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. Metric used: Unbabel/wmt22-comet-da.

**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**
M2M-10087.089.092.189.788.686.488.487.389.684.689.488.492.786.889.189.690.386.488.790.1
NLLB-20088.188.991.288.690.4_88.5_90.188.889.4_85.8_88.987.791.888.288.988.890.0_87.5_88.689.4
Seamless-M4T87.580.990.882.0_90.7__88.5__90.6__89.6_79.685.480.076.491.587.281.282.980.987.376.781.0
OPUS-MT Sla-Sla_88.2_82.8-83.489.185.6-84.582.982.2-81.2----83.584.180.8-
OPUS-MT SK-EN------89.5------_88.4_------
Our contributions:
BiDi Models<span style="color:green;">*</span>87.589.492.489.887.886.287.286.690.085.089.188.492.987.388.889.490.086.988.189.1
P4-pol<span style="color:red;">◊</span>-89.690.888.7----90.2-89.888.791.0-89.388.489.3-88.788.5
P5-eng<span style="color:red;">◊</span>88.089.090.789.088.887.388.487.589.085.788.587.891.088.288.688.589.687.288.488.9
P5-ces<span style="color:red;">◊</span>87.989.6_92.5_89.988.485.087.985.990.384.589.588.0_93.0_87.889.489.890.385.787.989.8
MultiSlav-4slav-89.7_92.5_90.0----90.2-89.688.792.9-89.490.1_90.6_-88.9_90.2_
MultiSlav-5lang87.8_89.8__92.5__90.1_88.986.988.087.3_90.4_85.489.8_88.9_92.987.8_89.6__90.2__90.6_87.0_89.2__90.2_

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

<span style="color:green;">*</span> results combined for all bi-directional models; each values for applicable model

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: