模型概述
模型特點
模型能力
使用案例
🚀 多斯拉夫雙向模型
多斯拉夫雙向模型是一組支持雙向翻譯的編碼器 - 解碼器香草變壓器模型,可用於多種斯拉夫語言及英語的互譯,為跨語言交流提供有力支持。
🚀 快速開始
要使用 BiDi 模型,你需要指定翻譯的目標語言。目標語言標記以 3 字母的 ISO 639 - 3 語言代碼形式嵌入在 >>xxx<< 格式中。以下是使用模型的示例代碼片段。由於存在一個 bug,必須顯式使用 MarianMTModel
。請記得根據你的使用場景調整源語言和目標語言。
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)
生成的捷克語輸出如下:
Allegro je online e-commerce platforma, na které své výrobky prodávají střední a malé firmy, stejně jako velké značky.
✨ 主要特性
- 雙向翻譯:BiDi 是一組在句子級機器翻譯任務上訓練的編碼器 - 解碼器香草變壓器模型集合,每個模型都支持雙向翻譯。
- 多語言支持:支持捷克語、英語、波蘭語、斯洛伐克語和斯洛文尼亞語等多種語言的翻譯。
📦 安裝指南
文檔未提及安裝步驟,故跳過該章節。
💻 使用示例
基礎用法
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)
高級用法
文檔未提及高級用法示例,故跳過該部分。
📚 詳細文檔
支持的語言
要使用 BiDi 模型,你必須提供翻譯的目標語言。目標語言標記以 3 字母的 ISO 639 - 3 語言代碼形式嵌入在 >>xxx<< 格式中。所有接受的翻譯方向及其相應的標記如下所示。請注意,每個模型僅支持兩個方向。每個方向都作為特殊標記添加到了 Sentence - Piece 分詞器中。
目標語言 | 第一個標記 |
---|---|
捷克語 | >>ces<< |
英語 | >>eng<< |
波蘭語 | >>pol<< |
斯洛伐克語 | >>slk<< |
斯洛文尼亞語 | >>slv<< |
可用的雙向模型
我們提供了 10 個 BiDi 模型,可實現 20 種語言之間的翻譯。
雙向模型 | 支持的語言 | HF 倉庫 |
---|---|---|
BiDi - ces - eng | 捷克語 ↔ 英語 | [allegro/BiDi - ces - eng](https://huggingface.co/allegro/bidi - ces - eng) |
BiDi - ces - pol | 捷克語 ↔ 波蘭語 | [allegro/BiDi - ces - pol](https://huggingface.co/allegro/bidi - ces - pol) |
BiDi - ces - slk | 捷克語 ↔ 斯洛伐克語 | [allegro/BiDi - ces - slk](https://huggingface.co/allegro/bidi - ces - slk) |
BiDi - ces - slv | 捷克語 ↔ 斯洛文尼亞語 | [allegro/BiDi - ces - slv](https://huggingface.co/allegro/bidi - ces - slv) |
BiDi - eng - pol | 英語 ↔ 波蘭語 | [allegro/BiDi - eng - pol](https://huggingface.co/allegro/bidi - eng - pol) |
BiDi - eng - slk | 英語 ↔ 斯洛伐克語 | [allegro/BiDi - eng - slk](https://huggingface.co/allegro/bidi - eng - slk) |
BiDi - eng - slv | 英語 ↔ 斯洛文尼亞語 | [allegro/BiDi - eng - slv](https://huggingface.co/allegro/bidi - eng - slv) |
BiDi - pol - slk | 波蘭語 ↔ 斯洛伐克語 | [allegro/BiDi - pol - slk](https://huggingface.co/allegro/bidi - pol - slk) |
BiDi - pol - slv | 波蘭語 ↔ 斯洛文尼亞語 | [allegro/BiDi - pol - slv](https://huggingface.co/allegro/bidi - pol - slv) |
BiDi - slk - slv | 斯洛伐克語 ↔ 斯洛文尼亞語 | [allegro/BiDi - slk - slv](https://huggingface.co/allegro/bidi - slk - slv) |
訓練
SentencePiece 分詞器的詞彙表總大小為 32k(每種語言 16k)。分詞器是在訓練語料庫的隨機採樣部分上訓練的。在訓練過程中,我們使用了 [MarianNMT](https://marian - nmt.github.io/) 框架。使用的基礎 Marian 配置為:[transfromer - big](https://github.com/marian - nmt/marian - dev/blob/master/src/common/aliases.cpp#L113)。所有訓練參數如下表所示。
訓練超參數:
超參數 | 值 |
---|---|
總參數大小 | 209M |
詞彙表大小 | 32k |
基礎參數 | [Marian transfromer - big](https://github.com/marian - nmt/marian - dev/blob/master/src/common/aliases.cpp#L113) |
編碼層數 | 6 |
解碼層數 | 6 |
模型維度 | 1024 |
前饋維度 | 4096 |
頭數 | 16 |
丟棄率 | 0.1 |
批量大小 | 小批量適應 VRAM |
訓練加速器 | 4x A100 40GB |
最大長度 | 100 個標記 |
優化器 | Adam |
預熱步數 | 8000 |
上下文 | 句子級機器翻譯 |
支持的語言 | 見可用的雙向模型 |
精度 | float16 |
驗證頻率 | 3000 步 |
停止指標 | ChrF |
停止標準 | 20 次驗證步驟 |
訓練語料庫
主要研究問題是:“添加額外的相關語言如何影響模型的質量?” 我們在斯拉夫語系中進行了探索。BiDi 模型是我們在通過使用更高級別的多語言性擴展數據機制之前的基線。
數據集是通過 MT - Data 庫下載的。過濾和去重後,總示例數量會根據支持的語言而有所不同,如下表所示。
語言對 | 訓練示例數量 |
---|---|
捷克語 ↔ 波蘭語 | 63M |
捷克語 ↔ 斯洛伐克語 | 30M |
捷克語 ↔ 斯洛文尼亞語 | 25M |
波蘭語 ↔ 斯洛伐克語 | 26M |
波蘭語 ↔ 斯洛文尼亞語 | 23M |
斯洛伐克語 ↔ 斯洛文尼亞語 | 18M |
捷克語 ↔ 英語 | 151M |
英語 ↔ 波蘭語 | 150M |
英語 ↔ 斯洛伐克語 | 52M |
英語 ↔ 斯洛文尼亞語 | 40M |
使用的數據集(僅適用於特定方向):
語料庫 |
---|
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 |
khresmoi_summary_dev |
worldbank |
評估
模型的評估是在 Flores200 數據集上進行的。下表比較了開源模型和我們集合中所有適用模型的性能。使用的指標為:Unbabel/wmt22 - comet - da。
方向 | 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 - 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 |
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 |
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 |
OPUS - MT Sla - Sla | 88.2 | 82.8 | - | 83.4 | 89.1 | 85.6 | - | 84.5 | 82.9 | 82.2 | - | 81.2 | - | - | - | - | 83.5 | 84.1 | 80.8 | - |
OPUS - MT SK - EN | - | - | - | - | - | - | 89.5 | - | - | - | - | - | - | 88.4 | - | - | - | - | - | - |
BiDi 模型 | 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 |
P4 - pol | - | 89.6 | 90.8 | 88.7 | - | - | - | - | 90.2 | - | 89.8 | 88.7 | 91.0 | - | 89.3 | 88.4 | 89.3 | - | 88.7 | 88.5 |
P5 - eng | 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 |
P5 - ces | 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 |
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 |
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 |
◊ 由 2 個模型 Many2XXX 和 XXX2Many 組成的系統,見 [P5 - ces2many](https://huggingface.co/allegro/p5 - ces2many)
- 所有雙向模型的綜合結果;每個值對應適用的模型
侷限性和偏差
我們沒有評估訓練數據集中包含的固有偏差。建議在特定領域驗證我們模型的偏差。這在從英語到斯拉夫語的翻譯中可能尤其成問題,因為斯拉夫語需要明確指示性別,並且可能會基於訓練數據中存在的偏差產生幻覺。
🔧 技術細節
文檔中關於技術細節部分已在詳細文檔的訓練部分詳細說明,此處不再重複。
📄 許可證
該模型採用 CC BY 4.0 許可證,允許商業使用。
聯繫信息
作者:
- MLR @ Allegro:Artur Kot,Mikołaj Koszowski,[Wojciech Chojnowski](https://linkedin.com/in/wojciech - chojnowski - 744702348),[Mieszko Rutkowski](https://linkedin.com/in/mieszko - rutkowski)
- 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)
如果您有任何問題或建議,請隨時聯繫作者:
- 電子郵件:artur.kot@allegro.com 或 mikolaj.koszowski@allegro.com
- LinkedIn:Artur Kot 或 Mikołaj Koszowski
引用
即將更新 🤗



