模型概述
模型特點
模型能力
使用案例
🚀 多斯拉夫雙向模型
多斯拉夫雙向模型是一組支持雙向翻譯的編碼器 - 解碼器香草變換器模型,可助力多語言翻譯任務,為跨語言交流提供高效解決方案。
🚀 快速開始
由於存在一個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.
✨ 主要特性
- 雙向翻譯:每個模型都支持雙向翻譯,能夠在兩種語言之間自由轉換。
- 多語言支持:支持捷克語、英語、波蘭語、斯洛伐克語和斯洛文尼亞語等多種語言。
- 多模型選擇:提供了10種雙向模型,可滿足不同語言對之間的翻譯需求。
📦 安裝指南
文檔未提及安裝步驟,可參考transformers
庫的官方安裝說明進行安裝。
💻 使用示例
基礎用法
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)模型,你必須為翻譯指定目標語言。目標語言標記以嵌入格式>>xxx<<
的3字母ISO 639 - 3語言代碼表示。所有接受的方向及其各自的標記如下所列。請注意,每個模型僅提供兩個方向。每個方向都作為特殊標記添加到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 |
批量大小 | 小批量適應顯存 |
訓練加速器 | 4x A100 40GB |
最大長度 | 100個標記 |
優化器 | Adam |
預熱步數 | 8000 |
上下文 | 句子級機器翻譯 |
支持的語言 | 見[可用的雙向模型](#Bi - Di模型可用) |
精度 | 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 Models | 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



